on master help sign in
add an example program to test input event handling: vty-event-echo
33bf7c8Corey O'Connor
test/EventEcho.hsnew file+42
@@ -0,0 +1,42 @@
1+module Main where
2+
3+import Graphics.Vty
4+
5+import Control.Applicative
6+import Control.Arrow
7+import Control.Monad.RWS
8+
9+import Data.Sequence (Seq, (<|) )
10+import qualified Data.Sequence as Seq
11+import Data.Foldable
12+
13+event_buffer_size = 1000
14+
15+type App = RWST Vty () (Seq String) IO
16+
17+main = do
18+ vty <- mkVty
19+ _ <- execRWST vty_interact vty Seq.empty
20+ shutdown vty
21+
22+vty_interact :: App ()
23+vty_interact = do
24+ update_display
25+ done <- handle_next_event
26+ unless done vty_interact
27+
28+update_display :: App ()
29+update_display = do
30+ let info = string def_attr "Press ESC to exit."
31+ event_log <- foldMap (string def_attr) <$> get
32+ let pic = pic_for_layers [info,event_log]
33+ vty <- ask
34+ liftIO $ update vty pic
35+
36+handle_next_event = ask >>= liftIO . next_event >>= handle_event
37+ where
38+ handle_event (EvKey KEsc []) = return True
39+ handle_event e = do
40+ modify $ (<|) (show e) >>> Seq.take event_buffer_size
41+ return False
42+
vty.cabal+19
@@ -561,6 +561,25 @@ executable vty-interactive-terminal-test
561 utf8-string >= 0.3 && < 0.4,
561 utf8-string >= 0.3 && < 0.4,
562 vector >= 0.7
562 vector >= 0.7
563
563
564+executable vty-event-echo
565+ main-is: EventEcho.hs
566+ hs-source-dirs: test
567+
568+ default-language: Haskell2010
569+ default-extensions: ScopedTypeVariables
570+
571+ build-depends: vty,
572+ base >= 4 && < 5,
573+ array >= 0.4 && < 2.0,
574+ bytestring,
575+ containers,
576+ lens,
577+ mtl >= 1.1.1.0 && < 2.2,
578+ parallel >= 2.2 && < 3.3,
579+ text >= 0.11.3,
580+ utf8-string >= 0.3 && < 0.4,
581+ vector >= 0.7
582+
564executable vty-rouge
583executable vty-rouge
565 main-is: Rouge.hs
584 main-is: Rouge.hs
566 hs-source-dirs: test
585 hs-source-dirs: test