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.

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 msg)

Type alias for Tui programs.

User Input

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

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

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".

CursorReport is a special input type you will receive if you include Ansi.getCursorReport in your output. Use this to get the current row and column position of the cursor in the terminal (where the upper-left corner of the window is row 1 column 1).

CtrlC is the "abort" signal and gets intercepted by gren-tui to exit your program. For now you can't depend on receiving this in your app.