summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2022-09-14 14:14:15 -0400
committerAndrew Cady <d@cryptonomic.net>2022-09-14 14:14:15 -0400
commit6fd0eb8089e26b9c79a7c76511217f7f5b6c6111 (patch)
tree07f3a9339499277e4662ed14cfaf08ebce582ad9
parentccc300ab3e7c16a5c080127f9b7cb6298d034dc6 (diff)
vty
-rwxr-xr-xcountdown.hs41
-rw-r--r--package.yaml5
2 files changed, 45 insertions, 1 deletions
diff --git a/countdown.hs b/countdown.hs
index 1795a02..cfa8f2d 100755
--- a/countdown.hs
+++ b/countdown.hs
@@ -8,12 +8,51 @@
8#-} 8#-}
9{-# language NoImplicitPrelude #-} 9{-# language NoImplicitPrelude #-}
10{-# language RecordWildCards #-} 10{-# language RecordWildCards #-}
11{-# language FlexibleContexts #-}
11import Rebase.Prelude hiding (toList) 12import Rebase.Prelude hiding (toList)
12import Control.Lens 13import Control.Lens hiding ((<|))
13import Data.Foldable (toList) 14import Data.Foldable (toList)
14import Data.Ratio 15import Data.Ratio
15import Text.Printf 16import Text.Printf
17import Graphics.Vty
18import Data.Time.LocalTime
19import Control.Monad.RWS
20import Data.Sequence (Seq, (<|))
21import qualified Data.Sequence as Seq
22
23eventBufferSize = 1000
24
25billion :: Integer
26billion = 1000 * 1000 * 1000
27
28ageOfUniverseInYears :: Integer
29ageOfUniverseInYears = 13 * billion
30
31type App = RWST Vty () (Seq String) IO
32
33vtyInteract :: Bool -> App ()
34vtyInteract shouldExit = do
35 updateDisplay
36 unless shouldExit $ handleNextEvent >>= vtyInteract
37
38handleNextEvent = ask >>= liftIO . nextEvent >>= handleEvent
39 where
40 handleEvent e = do
41 modify $ (<|) (show e) >>> Seq.take eventBufferSize
42 return $ e == EvKey KEsc []
43
44updateDisplay :: App ()
45updateDisplay = do
46 let info = string defAttr "Press ESC to exit."
47 eventLog <- foldMap (string defAttr) <$> get
48 let pic = picForImage $ info <-> eventLog
49 vty <- ask
50 liftIO $ update vty pic
16 51
17main :: IO () 52main :: IO ()
18main = do 53main = do
54 now <- getCurrentTime
55 vty <- mkVty defaultConfig
56 _ <- execRWST (vtyInteract False) vty (Seq.empty)
57 shutdown vty
19 return () 58 return ()
diff --git a/package.yaml b/package.yaml
index 6f8baa7..071bcd7 100644
--- a/package.yaml
+++ b/package.yaml
@@ -5,6 +5,11 @@ dependencies:
5- base 5- base
6- rebase 6- rebase
7- lens 7- lens
8- vty
9- time
10- mtl
11- data-default
12- containers
8 13
9executables: 14executables:
10 countdown: 15 countdown: