2013-10-27 04:04:52 +04:00
|
|
|
module Main where
|
|
|
|
|
|
|
|
import Graphics.Vty
|
|
|
|
|
|
|
|
import Control.Applicative
|
|
|
|
import Control.Arrow
|
|
|
|
import Control.Monad.RWS
|
|
|
|
|
2014-01-27 01:25:13 +04:00
|
|
|
import Data.Default (def)
|
2013-10-27 04:04:52 +04:00
|
|
|
import Data.Sequence (Seq, (<|) )
|
|
|
|
import qualified Data.Sequence as Seq
|
|
|
|
import Data.Foldable
|
|
|
|
|
2014-04-12 04:51:13 +04:00
|
|
|
eventBufferSize = 1000
|
2013-10-27 04:04:52 +04:00
|
|
|
|
|
|
|
type App = RWST Vty () (Seq String) IO
|
|
|
|
|
|
|
|
main = do
|
2014-01-27 01:25:13 +04:00
|
|
|
vty <- mkVty def
|
2014-04-12 04:51:13 +04:00
|
|
|
_ <- execRWST (vtyInteract False) vty Seq.empty
|
2013-10-27 04:04:52 +04:00
|
|
|
shutdown vty
|
|
|
|
|
2014-04-12 04:51:13 +04:00
|
|
|
vtyInteract :: Bool -> App ()
|
|
|
|
vtyInteract shouldExit = do
|
|
|
|
updateDisplay
|
|
|
|
unless shouldExit $ handleNextEvent >>= vtyInteract
|
2013-10-27 04:04:52 +04:00
|
|
|
|
2014-04-12 04:51:13 +04:00
|
|
|
updateDisplay :: App ()
|
|
|
|
updateDisplay = do
|
|
|
|
let info = string defAttr "Press ESC to exit."
|
|
|
|
eventLog <- foldMap (string defAttr) <$> get
|
|
|
|
let pic = picForImage $ info <-> eventLog
|
2013-10-27 04:04:52 +04:00
|
|
|
vty <- ask
|
|
|
|
liftIO $ update vty pic
|
|
|
|
|
2014-04-12 04:51:13 +04:00
|
|
|
handleNextEvent = ask >>= liftIO . nextEvent >>= handleEvent
|
2013-10-27 04:04:52 +04:00
|
|
|
where
|
2014-04-12 04:51:13 +04:00
|
|
|
handleEvent e = do
|
|
|
|
modify $ (<|) (show e) >>> Seq.take eventBufferSize
|
2014-01-29 11:13:25 +04:00
|
|
|
return $ e == EvKey KEsc []
|
2013-10-27 04:04:52 +04:00
|
|
|
|