/
HtopAsciinema.hs
98 lines (82 loc) · 2.4 KB
/
HtopAsciinema.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# OPTIONS_GHC -fplugin=Polysemy.Plugin #-}
module Polytype.Examples.HtopAsciinema where
import Polytype
-- | Record a demo of htop interaction
-- using asciicast logger.
htopAsciinemaExample :: FilePath -> IO ()
htopAsciinemaExample outputFile =
void
. runFinal
. embedToFinal @IO
. resourceToIO
. runTeletypeAsciinema "htop demo" outputFile (ptyOptsExeArgs "htop" [])
-- . runLogShow
-- . teletypeLog -- enable for debugging raw input / output
. asyncToIOFinal
. runDelayAsync @MilliSeconds
. runDelayAsync @Seconds
. runDelayAsync @Minutes
$ do
waitString "Load average"
waitString "Help"
writeTTY "\ESC[11~" -- F1
waitString "incremental"
writeTTY "\ESC[11~"
waitString "Uptime"
delay @Seconds 2
void $ async $ forever $ readTTY >> pure ()
void $ async $ do
--writeTTY "\ESC[13~"
display "Welcome to htop demo!"
display "Recorded with polytype"
display "Press h or F1 for help"
writeTTY "h"
delay @Seconds 5
writeTTY "h"
delay @Seconds 2
display "Search feature - F3"
writeTTY "\ESC[13~"
writeLineSlowly "htop"
delay @Seconds 5
display "Filtering feature - F4"
writeTTY "\ESC[14~"
writeLineSlowly "polytype"
delay @Seconds 5
display ""
writeTTY "\ESC[14~"
writeLineSlowly "htop"
delay @Seconds 5
display "Sorted - F5"
writeTTY "\ESC[15~"
delay @Seconds 5
display "Toggle program path - p"
writeTTY "p"
delay @Seconds 5
display "That's all for now!"
display "Lets toggle program path for a bit"
forever $ do
writeTTY "p"
delay @Seconds 5
delay @Minutes 2
display "Thanks for watching"
writeTTY "q"
readTTY
where
writeSlowly [] = delay @Seconds 1
writeSlowly (x:xs) = do
writeTTY [x]
delay @MilliSeconds 100
writeSlowly xs
writeLineSlowly msg = writeSlowly msg >> writeLine ""
display :: Members '[Teletype String, Delay Seconds, Delay MilliSeconds] r
=> String
-> Sem r ()
display msg = do
writeTTY "\ESC[14~"
writeTTY "\ESC~"
writeTTY "\ESC[14~"
writeSlowly msg
writeTTY "\ESC~"