Last active
March 7, 2020 04:16
-
-
Save IvanRainbolt/6bddae9e59a52312e675afc7d5d76529 to your computer and use it in GitHub Desktop.
Very basic F# command line UI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Very basic F# command line UI | |
//trying to get a global state | |
open System | |
let mutable x = "NoUser" | |
let printPrompt () = | |
printfn "Current State: %s" x | |
printf "command:>" | |
let getCommandLineInput _ = | |
printPrompt () | |
System.Console.ReadLine () | |
let writeError value = | |
printfn "ERROR - No Match\nYou typed: %s" value | |
let writeMatch value = | |
printfn "Matched: %s" value | |
let processCommandLineInput commandLineInput = | |
match commandLineInput with | |
| "a" -> writeMatch "a"; x <- "Ivan" | |
| "b" -> writeMatch "b"; x <- "Bob" | |
| "c" -> writeMatch "b" | |
| "exit" | "quit" -> Environment.Exit 55 | |
| _ -> writeError commandLineInput | |
//change to output a 'command'? | |
//let progLoop () = | |
// let commandLineInput = Seq.initInfinite getCommandLineInput | |
// Seq.iter processCommandLineInput commandLineInput | |
let progLoop () = | |
getCommandLineInput | |
|> Seq.initInfinite | |
|> Seq.iter processCommandLineInput | |
[<EntryPoint>] | |
let main argv = | |
progLoop () | |
0 | |
// big time help from | |
// https://www.log4code.com/f-infinite-sequence-to-read-console-input/ | |
// https://dev.to/integerman/creating-a-net-core-3-0-f-console-app-348h | |
// FoggyFinder -> https://forums.fsharp.org/t/basic-f-console-ui-program-loop/1216?u=ivanrainbolt |
Aaaand I just now saw the post on the fsharp community forums. Ahh, well...happy F#-ing! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could try something like this: