packages feed

layoutz-1.0.0.0: examples/CounterDemo.hs

{-# LANGUAGE OverloadedStrings #-}

{-|
Counter demo: '+' and '-' to count, Esc to quit.
-}

module Main where

import Layoutz

data CounterMsg = Inc | Dec

counterApp :: LayoutzApp Int CounterMsg
counterApp = LayoutzApp
  { appInit = (0, cmdNone)
  
  , appUpdate = \msg count -> case msg of
      Inc -> (count + 1, cmdNone)
      Dec -> (count - 1, cmdNone)
  
  , appSubscriptions = \_state ->
      subKeyPress $ \key -> case key of
        KeyChar '+' -> Just Inc
        KeyChar '-' -> Just Dec
        _           -> Nothing
  
  , appView = \count ->
      vstack
        [ section "Counter" [text $ "Count: " <> show count]
        , br
        , ul ["Press '+' or '-'", "Press ESC to quit"]
        ]
  }

main :: IO ()
main = runApp counterApp