marionette-commander
is a marionette
renderer for interactive CLI programs.
- Module documentation is published on Pursuit.
spago install marionette
spago install marionette-commander
In the simplest form a marionette-commander
program can look like this:
type State = Int
data Msg = CountUp | CountDown
update :: Msg -> State -> State
update msg state = case msg of
CountUp -> state + 1
CountDown -> state - 1
view :: State -> CliSurface Msg
view count = CliSurface
( TextOutput $
"Current count: " <> show count
)
( KeyInput (KeyPrompt "Use up/down keys") case _ of
{ name: "up" } -> Just CountUp
{ name: "down" } -> Just CountDown
_ -> Nothing
)
initialState :: State
initialState = 0
It's a counter that runs in the terminal, the user can count up and down by using the arrow keys. Check out the full code in the examples
folder.
spago run --main Test.Examples.PureCounter
spago run --main Test.Examples.CountDown
spago run --main Test.Examples.WordTicker
The snake implementation can be found in this repo.