diff options
author | Andrew Cady <d@cryptonomic.net> | 2022-09-14 14:14:15 -0400 |
---|---|---|
committer | Andrew Cady <d@cryptonomic.net> | 2022-09-14 14:14:15 -0400 |
commit | 6fd0eb8089e26b9c79a7c76511217f7f5b6c6111 (patch) | |
tree | 07f3a9339499277e4662ed14cfaf08ebce582ad9 | |
parent | ccc300ab3e7c16a5c080127f9b7cb6298d034dc6 (diff) |
vty
-rwxr-xr-x | countdown.hs | 41 | ||||
-rw-r--r-- | package.yaml | 5 |
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 #-} | ||
11 | import Rebase.Prelude hiding (toList) | 12 | import Rebase.Prelude hiding (toList) |
12 | import Control.Lens | 13 | import Control.Lens hiding ((<|)) |
13 | import Data.Foldable (toList) | 14 | import Data.Foldable (toList) |
14 | import Data.Ratio | 15 | import Data.Ratio |
15 | import Text.Printf | 16 | import Text.Printf |
17 | import Graphics.Vty | ||
18 | import Data.Time.LocalTime | ||
19 | import Control.Monad.RWS | ||
20 | import Data.Sequence (Seq, (<|)) | ||
21 | import qualified Data.Sequence as Seq | ||
22 | |||
23 | eventBufferSize = 1000 | ||
24 | |||
25 | billion :: Integer | ||
26 | billion = 1000 * 1000 * 1000 | ||
27 | |||
28 | ageOfUniverseInYears :: Integer | ||
29 | ageOfUniverseInYears = 13 * billion | ||
30 | |||
31 | type App = RWST Vty () (Seq String) IO | ||
32 | |||
33 | vtyInteract :: Bool -> App () | ||
34 | vtyInteract shouldExit = do | ||
35 | updateDisplay | ||
36 | unless shouldExit $ handleNextEvent >>= vtyInteract | ||
37 | |||
38 | handleNextEvent = ask >>= liftIO . nextEvent >>= handleEvent | ||
39 | where | ||
40 | handleEvent e = do | ||
41 | modify $ (<|) (show e) >>> Seq.take eventBufferSize | ||
42 | return $ e == EvKey KEsc [] | ||
43 | |||
44 | updateDisplay :: App () | ||
45 | updateDisplay = 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 | ||
17 | main :: IO () | 52 | main :: IO () |
18 | main = do | 53 | main = 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 | ||
9 | executables: | 14 | executables: |
10 | countdown: | 15 | countdown: |