https://github.com/nicolaiw/fsmenu
A very small DSL to create an interactive cli.
https://github.com/nicolaiw/fsmenu
cli console dsl fsharp
Last synced: about 1 year ago
JSON representation
A very small DSL to create an interactive cli.
- Host: GitHub
- URL: https://github.com/nicolaiw/fsmenu
- Owner: nicolaiw
- Created: 2017-07-20T17:15:17.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-03-05T08:34:14.000Z (over 8 years ago)
- Last Synced: 2025-06-03T14:26:29.333Z (about 1 year ago)
- Topics: cli, console, dsl, fsharp
- Language: F#
- Homepage:
- Size: 4.81 MB
- Stars: 11
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FsMenu
> A very small DSL to create an interactive cli.
### Build status
**Master Branch**
[](https://ci.appveyor.com/project/Jallah/fsmenu/branch/master)
### Nuget
Inc.
### Usage
#### The DSL:
```fsharp
// Creates a new menu
let Menu = Sub
// Render sub menu
let (+>) name entry : (string * MenuEntry) = (name,entry)
// Execute action and exit
let (=>) s f = (s, Action (fun () -> f(); Exit))
// Execute action and render the previous menu
let (<+) s f = (s, Action (fun () -> f(); NavigateBack))
// Execute action and render the menu where you come frome
let (<+=) s f = (s, Action (fun () -> f(); Stay))
```
#### Example:
```fsharp
let testFunc() =
printfn "selected Sub Sub 3"
printf "handle some input: "
let input = Console.ReadLine()
// Do some stuff with input
()
printfn "Use Keys: UP-Arrow DOWN-Arrow ENTER BACK-SPACE\n"
let mutable yesOrNo = ""
let test =
Menu [
"Item 1" => (fun () -> printf "selected Item 1")
"Item 2" +>
Menu [
"Sub 1" +>
Menu [
"Sub Sub 1" => (fun () -> printf "selected Sub Sub 1")
"Sub Sub 2" +>
Menu [
"yes" <+ (fun () -> yesOrNo <- "--yes")
"no " <+ (fun () -> yesOrNo <- "--no") ]
"Sub Sub 3" <+ testFunc]
"Sub 2" => (fun () -> printf "selected Sub 2")
"Sub 3" => (fun () -> printf "exec some command with param %s" yesOrNo)]]
render test "<--"
```
> Instead of `(fun () -> printf ...` you could pass any `unit -> unit` function.
#### Will turn into

#### Want some color ? :)
```fsharp
renderWithColoredEmphaziser test "<--" Color.Green
```
#### Here it is

### It is also possible to emphazise the entry
```fsharp
renderWithColoredEntry test Color.Cyan
```

### Or Both, the emphaziser and the entry
```fsharp
renderWithColoredLine test "<--" Color.Green
```

#### Another example
[Here](https://github.com/nicolaiw/FsMenu/tree/master/misc)
### Build
+ On Windows run build.cmd
+ On Linux run build.sh
### TODO ( contributes are very welcome :D )
+ Add support for multiselect list and single select list
+ Create NuGet Package using Paket
+ Clean build.fsx
+ Refactoring: The goal is too use the render funcion like `render test <| withColoredEmphaziser "<--" Color.Green` or something like that