brick/programs/SuspendAndResumeDemo.hs

56 lines
1.3 KiB
Haskell
Raw Normal View History

2015-06-29 09:45:04 +03:00
{-# 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 =
2015-06-29 09:45:04 +03:00
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
2015-06-29 09:45:04 +03:00
, appAttrMap = const def
, appMakeVtyEvent = id
}
main :: IO ()
main = do
void $ defaultMain theApp initialState