mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-12-12 12:23:21 +03:00
56 lines
1.3 KiB
Haskell
56 lines
1.3 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
{-# LANGUAGE TemplateHaskell #-}
|
|
module Main where
|
|
|
|
import Control.Lens
|
|
import Control.Monad (void)
|
|
import Data.Monoid
|
|
import Data.Default
|
|
import Graphics.Vty hiding (translate)
|
|
|
|
import Brick.Main
|
|
import Brick.Widgets.Core
|
|
|
|
data St =
|
|
St { _stExternalInput :: String
|
|
}
|
|
|
|
makeLenses ''St
|
|
|
|
drawUI :: St -> [Widget]
|
|
drawUI st = [ui]
|
|
where
|
|
ui = vBox [ str $ "External input: \"" <> st^.stExternalInput <> "\""
|
|
, "(Press Esc to quit or Space to ask for input)"
|
|
]
|
|
|
|
appEvent :: St -> Event -> EventM (Next St)
|
|
appEvent st e =
|
|
case e of
|
|
EvKey KEsc [] -> halt st
|
|
EvKey (KChar ' ') [] -> suspendAndResume $ do
|
|
-- NB: https://github.com/coreyoconnor/vty/issues/77
|
|
putStrLn "Suspended. Please enter something and press enter to resume:"
|
|
s <- getLine
|
|
return $ st & stExternalInput .~ s
|
|
_ -> continue st
|
|
|
|
initialState :: St
|
|
initialState =
|
|
St { _stExternalInput = ""
|
|
}
|
|
|
|
theApp :: App St Event
|
|
theApp =
|
|
App { appDraw = drawUI
|
|
, appChooseCursor = neverShowCursor
|
|
, appHandleEvent = appEvent
|
|
, appStartEvent = return
|
|
, appAttrMap = const def
|
|
, appMakeVtyEvent = id
|
|
}
|
|
|
|
main :: IO ()
|
|
main = do
|
|
void $ defaultMain theApp initialState
|