2015-06-29 09:45:04 +03:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
2018-03-17 19:03:30 +03:00
|
|
|
{-# LANGUAGE CPP #-}
|
2015-06-29 09:45:04 +03:00
|
|
|
module Main where
|
|
|
|
|
2022-07-17 09:10:03 +03:00
|
|
|
import Lens.Micro ((^.))
|
2016-05-09 04:05:30 +03:00
|
|
|
import Lens.Micro.TH (makeLenses)
|
2015-06-29 09:45:04 +03:00
|
|
|
import Control.Monad (void)
|
2018-03-17 19:03:30 +03:00
|
|
|
#if !(MIN_VERSION_base(4,11,0))
|
2015-06-29 09:45:04 +03:00
|
|
|
import Data.Monoid
|
2018-03-17 19:03:30 +03:00
|
|
|
#endif
|
2015-07-10 23:34:21 +03:00
|
|
|
import qualified Graphics.Vty as V
|
2015-06-29 09:45:04 +03:00
|
|
|
|
|
|
|
import Brick.Main
|
2015-07-10 23:34:21 +03:00
|
|
|
( App(..), neverShowCursor, defaultMain
|
2022-07-17 09:10:03 +03:00
|
|
|
, suspendAndResume, halt
|
2015-07-10 23:34:21 +03:00
|
|
|
)
|
2017-01-25 00:48:45 +03:00
|
|
|
import Brick.AttrMap
|
|
|
|
( attrMap
|
|
|
|
)
|
2015-08-20 05:40:06 +03:00
|
|
|
import Brick.Types
|
2015-07-10 23:34:21 +03:00
|
|
|
( Widget
|
2015-08-20 05:48:55 +03:00
|
|
|
, EventM
|
2016-10-26 06:19:31 +03:00
|
|
|
, BrickEvent(..)
|
2015-08-20 05:40:06 +03:00
|
|
|
)
|
|
|
|
import Brick.Widgets.Core
|
|
|
|
( vBox
|
2015-07-10 23:34:21 +03:00
|
|
|
, str
|
|
|
|
)
|
2015-06-29 09:45:04 +03:00
|
|
|
|
|
|
|
data St =
|
|
|
|
St { _stExternalInput :: String
|
|
|
|
}
|
|
|
|
|
|
|
|
makeLenses ''St
|
|
|
|
|
2016-03-05 01:42:49 +03:00
|
|
|
drawUI :: St -> [Widget ()]
|
2015-06-29 09:45:04 +03:00
|
|
|
drawUI st = [ui]
|
|
|
|
where
|
|
|
|
ui = vBox [ str $ "External input: \"" <> st^.stExternalInput <> "\""
|
2015-08-20 05:40:06 +03:00
|
|
|
, str "(Press Esc to quit or Space to ask for input)"
|
2015-06-29 09:45:04 +03:00
|
|
|
]
|
|
|
|
|
2022-07-17 09:10:03 +03:00
|
|
|
appEvent :: BrickEvent () e -> EventM () St ()
|
|
|
|
appEvent (VtyEvent e) =
|
2015-06-29 09:45:04 +03:00
|
|
|
case e of
|
2022-07-17 09:10:03 +03:00
|
|
|
V.EvKey V.KEsc [] -> halt
|
2015-07-10 23:34:21 +03:00
|
|
|
V.EvKey (V.KChar ' ') [] -> suspendAndResume $ do
|
2015-06-29 09:45:04 +03:00
|
|
|
putStrLn "Suspended. Please enter something and press enter to resume:"
|
|
|
|
s <- getLine
|
2022-07-17 09:10:03 +03:00
|
|
|
return $ St { _stExternalInput = s }
|
|
|
|
_ -> return ()
|
|
|
|
appEvent _ = return ()
|
2015-06-29 09:45:04 +03:00
|
|
|
|
|
|
|
initialState :: St
|
|
|
|
initialState =
|
|
|
|
St { _stExternalInput = ""
|
|
|
|
}
|
|
|
|
|
2016-10-26 06:19:31 +03:00
|
|
|
theApp :: App St e ()
|
2015-06-29 09:45:04 +03:00
|
|
|
theApp =
|
|
|
|
App { appDraw = drawUI
|
|
|
|
, appChooseCursor = neverShowCursor
|
|
|
|
, appHandleEvent = appEvent
|
2022-07-17 09:10:03 +03:00
|
|
|
, appStartEvent = return ()
|
2017-01-25 00:48:45 +03:00
|
|
|
, appAttrMap = const $ attrMap V.defAttr []
|
2015-06-29 09:45:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
main :: IO ()
|
2015-12-09 18:15:03 +03:00
|
|
|
main =
|
2015-06-29 09:45:04 +03:00
|
|
|
void $ defaultMain theApp initialState
|