on master help sign in
add a demo program to vty distribution
commite010924c61402928c719bba1c91a9a0db040fff6 authorCorey O'Connor <coreyoconnor@gmail.com> dateSat 3 May 2014, 16:33 (12 years ago) parent5b30b8d
2 files changed+72−17
Demo.hs+41 vty.cabal+31−17
Demo.hsnew file+41
@@ -0,0 +1,41 @@
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.Default (def)
10+import Data.Sequence (Seq, (<|) )
11+import qualified Data.Sequence as Seq
12+import Data.Foldable
13+
14+eventBufferSize = 1000
15+
16+type App = RWST Vty () (Seq String) IO
17+
18+main = do
19+ vty <- mkVty def
20+ _ <- execRWST (vtyInteract False) vty Seq.empty
21+ shutdown vty
22+
23+vtyInteract :: Bool -> App ()
24+vtyInteract shouldExit = do
25+ updateDisplay
26+ unless shouldExit $ handleNextEvent >>= vtyInteract
27+
28+updateDisplay :: App ()
29+updateDisplay = do
30+ let info = string defAttr "Press ESC to exit."
31+ eventLog <- foldMap (string defAttr) <$> get
32+ let pic = picForImage $ info <-> eventLog
33+ vty <- ask
34+ liftIO $ update vty pic
35+
36+handleNextEvent = ask >>= liftIO . nextEvent >>= handleEvent
37+ where
38+ handleEvent e = do
39+ modify $ (<|) (show e) >>> Seq.take eventBufferSize
40+ return $ e == EvKey KEsc []
41+
vty.cabal+31−17
@@ -31,7 +31,7 @@ description:
3131 &#169; 2006-2007 Stefan O'Rear; BSD3 license.
3232 .
3333 &#169; Corey O'Connor; BSD3 license.
34−cabal-version: >= 1.18.0
34+cabal-version: >= 1.20.0
3535build-type: Simple
3636data-files: README.md,
3737 TODO,
@@ -116,6 +116,20 @@ library
116116
117117 cc-options: -O2 -fpic
118118
119+executable vty-demo
120+ main-is: Demo.hs
121+
122+ default-language: Haskell2010
123+ default-extensions: ScopedTypeVariables
124+ ghc-options: -threaded
125+
126+ build-depends: vty,
127+ base >= 4 && < 5,
128+ containers,
129+ data-default >= 0.5.3,
130+ lens,
131+ mtl >= 1.1.1.0 && < 2.2
132+
119133test-suite verify-attribute-ops
120134 default-language: Haskell2010
121135 default-extensions: ScopedTypeVariables
@@ -123,7 +137,7 @@ test-suite verify-attribute-ops
123137 hs-source-dirs: test
124138 test-module: VerifyAttributeOps
125139 build-depends: vty,
126− Cabal == 1.18.*,
140+ Cabal == 1.20.*,
127141 QuickCheck >= 2.4,
128142 random == 1.0.*,
129143 base >= 4 && < 5,
@@ -155,7 +169,7 @@ test-suite verify-using-mock-terminal
155169 Verify.Graphics.Vty.Output
156170
157171 build-depends: vty,
158− Cabal == 1.18.*,
172+ Cabal == 1.20.*,
159173 QuickCheck >= 2.4,
160174 random == 1.0.*,
161175 base >= 4 && < 5,
@@ -188,7 +202,7 @@ test-suite verify-terminal
188202 Verify.Graphics.Vty.Output
189203
190204 build-depends: vty,
191− Cabal == 1.18.*,
205+ Cabal == 1.20.*,
192206 QuickCheck >= 2.4,
193207 random == 1.0.*,
194208 base >= 4 && < 5,
@@ -220,7 +234,7 @@ test-suite verify-display-attributes
220234 Verify.Graphics.Vty.Span
221235
222236 build-depends: vty,
223− Cabal == 1.18.*,
237+ Cabal == 1.20.*,
224238 QuickCheck >= 2.4,
225239 random == 1.0.*,
226240 base >= 4 && < 5,
@@ -246,7 +260,7 @@ test-suite verify-empty-image-props
246260 other-modules: Verify
247261
248262 build-depends: vty,
249− Cabal == 1.18.*,
263+ Cabal == 1.20.*,
250264 QuickCheck >= 2.4,
251265 random == 1.0.*,
252266 base >= 4 && < 5,
@@ -273,7 +287,7 @@ test-suite verify-eval-terminfo-caps
273287 Verify.Graphics.Vty.Output
274288
275289 build-depends: vty,
276− Cabal == 1.18.*,
290+ Cabal == 1.20.*,
277291 QuickCheck >= 2.4,
278292 random == 1.0.*,
279293 base >= 4 && < 5,
@@ -303,7 +317,7 @@ test-suite verify-image-ops
303317 Verify.Graphics.Vty.Image
304318
305319 build-depends: vty,
306− Cabal == 1.18.*,
320+ Cabal == 1.20.*,
307321 QuickCheck >= 2.4,
308322 random == 1.0.*,
309323 base >= 4 && < 5,
@@ -331,7 +345,7 @@ test-suite verify-image-trans
331345 Verify.Graphics.Vty.Image
332346
333347 build-depends: vty,
334− Cabal == 1.18.*,
348+ Cabal == 1.20.*,
335349 QuickCheck >= 2.4,
336350 random == 1.0.*,
337351 base >= 4 && < 5,
@@ -358,7 +372,7 @@ test-suite verify-inline
358372 Verify.Graphics.Vty.Output
359373
360374 build-depends: vty,
361− Cabal == 1.18.*,
375+ Cabal == 1.20.*,
362376 QuickCheck >= 2.4,
363377 random == 1.0.*,
364378 base >= 4 && < 5,
@@ -386,7 +400,7 @@ test-suite verify-parse-terminfo-caps
386400 Verify.Graphics.Vty.Output
387401
388402 build-depends: vty,
389− Cabal == 1.18.*,
403+ Cabal == 1.20.*,
390404 QuickCheck >= 2.4,
391405 random == 1.0.*,
392406 base >= 4 && < 5,
@@ -418,7 +432,7 @@ test-suite verify-simple-span-generation
418432 Verify.Graphics.Vty.Span
419433
420434 build-depends: vty,
421− Cabal == 1.18.*,
435+ Cabal == 1.20.*,
422436 QuickCheck >= 2.4,
423437 random == 1.0.*,
424438 base >= 4 && < 5,
@@ -450,7 +464,7 @@ test-suite verify-crop-span-generation
450464 Verify.Graphics.Vty.Span
451465
452466 build-depends: vty,
453− Cabal == 1.18.*,
467+ Cabal == 1.20.*,
454468 QuickCheck >= 2.4,
455469 random == 1.0.*,
456470 base >= 4 && < 5,
@@ -482,7 +496,7 @@ test-suite verify-layers-span-generation
482496 Verify.Graphics.Vty.Span
483497
484498 build-depends: vty,
485− Cabal == 1.18.*,
499+ Cabal == 1.20.*,
486500 QuickCheck >= 2.4,
487501 random == 1.0.*,
488502 base >= 4 && < 5,
@@ -508,7 +522,7 @@ test-suite verify-utf8-width
508522 other-modules: Verify
509523
510524 build-depends: vty,
511− Cabal == 1.18.*,
525+ Cabal == 1.20.*,
512526 QuickCheck >= 2.4,
513527 random == 1.0.*,
514528 base >= 4 && < 5,
@@ -532,7 +546,7 @@ test-suite verify-using-mock-input
532546 main-is: VerifyUsingMockInput.hs
533547
534548 build-depends: vty,
535− Cabal == 1.18.*,
549+ Cabal == 1.20.*,
536550 data-default >= 0.5.3,
537551 QuickCheck >= 2.4,
538552 smallcheck == 1.*,
@@ -565,7 +579,7 @@ test-suite verify-config
565579 main-is: VerifyConfig.hs
566580
567581 build-depends: vty,
568− Cabal == 1.18.*,
582+ Cabal == 1.20.*,
569583 data-default >= 0.5.3,
570584 HUnit,
571585 QuickCheck >= 2.4,