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
|
|
|
|
|
|
|
|
event_buffer_size = 1000
|
|
|
|
|
|
|
|
type App = RWST Vty () (Seq String) IO
|
|
|
|
|
|
|
|
main = do
|
2014-01-27 01:25:13 +04:00
|
|
|
vty <- mkVty def
|
2013-10-27 04:04:52 +04:00
|
|
|
_ <- execRWST vty_interact vty Seq.empty
|
|
|
|
shutdown vty
|
|
|
|
|
|
|
|
vty_interact :: App ()
|
|
|
|
vty_interact = do
|
|
|
|
update_display
|
|
|
|
done <- handle_next_event
|
|
|
|
unless done vty_interact
|
|
|
|
|
|
|
|
update_display :: App ()
|
|
|
|
update_display = do
|
|
|
|
let info = string def_attr "Press ESC to exit."
|
|
|
|
event_log <- foldMap (string def_attr) <$> get
|
2013-10-27 04:06:35 +04:00
|
|
|
let pic = pic_for_image $ info <-> event_log
|
2013-10-27 04:04:52 +04:00
|
|
|
vty <- ask
|
|
|
|
liftIO $ update vty pic
|
|
|
|
|
|
|
|
handle_next_event = ask >>= liftIO . next_event >>= handle_event
|
|
|
|
where
|
|
|
|
handle_event (EvKey KEsc []) = return True
|
|
|
|
handle_event e = do
|
|
|
|
modify $ (<|) (show e) >>> Seq.take event_buffer_size
|
|
|
|
return False
|
|
|
|
|