Tui

Model/View/Update for the command line.

Use this module to define a command-line program that uses the elm architecture. See defineProgram for details, or one of the examples.

If you want total control of your program and only need ANSI escape sequences, see Ansi.

Defining your program

defineProgram :
{ init : Environment -> Task { model : model, command : Cmd msg }
, update : msg -> model -> { model : model, command : Cmd msg }
, subscriptions : model -> Sub msg
, view : model -> String
, onInput : Input -> msg
}
-> Program model msg

Define your Tui program.

Very similar to a normal Node.defineProgram, except for two special functions:

view: Return a string for the current model. gren-tui will print this, and keep track of how many lines are output so it can clear only those lines and print again when the output changes. This lets you do things like render progress bars, move characters around the screen, offer menu selections, etc.

onInput: Whenever your program receives input (a key is pressed, etc), a message is sent to your app with a Input value representing the input. This lets you capture text, trigger events on certain key presses, etc.

type alias Program model msg = Program (Model model) (Msg msg)

Type alias for Tui programs.

User Input

type Input
= KeyChar String
| Tab
| Space
| Return
| ArrowUp
| ArrowDown
| ArrowLeft
| ArrowRight
| CtrlC
| UnknownInput

Value sent to your onInput message when the program receives input (a key is pressed, a signal is received, etc.)

Note: Your program will receive keyboard input as the keys are pressed, as opposed to getting a bunch of characters after Enter is pressed (under the hood your terminal program is running in "raw mode"). For example, if someone types "hi" after starting your program, it will receive a message with KeyChar "h" and then another message with KeyChar "i".

Also note: gren-tui will exit the program when it gets CtrlC as input. For now you can't depend on receiving this in your app.