imp: demo: output cleanups

This commit is contained in:
Simon Michael 2023-03-16 23:00:34 -10:00
parent 2d496609bc
commit 6777182c70
3 changed files with 25 additions and 18 deletions

View File

@ -13,8 +13,7 @@ module Hledger.Cli.Commands.Demo (
import Hledger import Hledger
import Hledger.Cli.CliOptions import Hledger.Cli.CliOptions
import Control.Monad (forM_) import System.Exit (exitFailure)
import System.Exit (exitSuccess, exitFailure)
import Text.Printf import Text.Printf
import Control.Concurrent (threadDelay) import Control.Concurrent (threadDelay)
import System.Process (callProcess) import System.Process (callProcess)
@ -47,7 +46,10 @@ demomode = hledgerCommandMode
[] []
[generalflagsgroup3] [generalflagsgroup3]
[] []
([], Just $ argsFlag "[NUM|NAME|STR] [-- ASCIINEMAOPTS]") ([], Just $ argsFlag optsstr)
optsstr = "[NUM|PREFIX|SUBSTR] [-- ASCIINEMAOPTS]"
usagestr = "Usage: hledger demo " <> optsstr
-- | The demo command. -- | The demo command.
demo :: CliOpts -> Journal -> IO () demo :: CliOpts -> Journal -> IO ()
@ -55,15 +57,13 @@ demo CliOpts{rawopts_=rawopts, reportspec_=ReportSpec{_rsQuery=_query}} _j = do
-- demos <- getCurrentDirectory >>= readDemos -- demos <- getCurrentDirectory >>= readDemos
let args = listofstringopt "args" rawopts let args = listofstringopt "args" rawopts
case args of case args of
[] -> do [] -> putStrLn usagestr >> printDemos
forM_ (zip [(1::Int)..] demos) $ \(i, Demo t _) -> printf "%d) %s\n" i t
exitSuccess
(a:as) -> (a:as) ->
case findDemo demos a of case findDemo demos a of
Nothing -> do Nothing -> do
putStrLn $ a <> " not recognized" putStrLn $ "No demo \"" <> a <> "\" was found."
putStrLn "Usage: hledger-demo [NUM|NAME|STR], run with no arguments to see a list" putStrLn usagestr
printDemos
exitFailure exitFailure
Just (Demo t c) -> do Just (Demo t c) -> do
@ -90,6 +90,12 @@ findDemo ds s =
where where
sl = lowercase s sl = lowercase s
printDemos :: IO ()
printDemos = putStrLn $ unlines $
"Demos:" :
"" :
[show i <> ") " <> t | (i, Demo t _) <- zip [(1::Int)..] demos]
-- | Run asciinema play, passing content to its stdin. -- | Run asciinema play, passing content to its stdin.
runAsciinemaPlay :: ByteString -> [String] -> IO () runAsciinemaPlay :: ByteString -> [String] -> IO ()
runAsciinemaPlay content args = runAsciinemaPlay content args =

View File

@ -5,7 +5,7 @@ Play small demos of hledger usage in the terminal.
_FLAGS _FLAGS
Run this command with no argument to list the demos. Run this command with no argument to list the demos.
To play a demo, write its number or name or a substring. To play a demo, write its number or a prefix or substring of its title.
asciinema must be installed. asciinema must be installed.
During playback, several keys are available: During playback, several keys are available:
@ -13,14 +13,14 @@ During playback, several keys are available:
- . step forward (while paused) - . step forward (while paused)
- CTRL-c quit early - CTRL-c quit early
asciinema options can be added following a double-dash; asciinema options can be added following a double dash, such as
list them with `asciinema -h`. `-s` (speed) and `-s` (adjust speed) and `-i` (limit idle time).
`-i` (max idle time) are particularly useful. Run `asciinema -h` to list these.
Examples: Examples:
```shell ```shell
$ hledger demo # list available demos $ hledger demo # list available demos
$ hledger demo 1 # play the first demo $ hledger demo 1 # play the first demo
$ hledger demo install -s5 -i.5 # play the demo named or containing "install", $ hledger demo install -s5 -i.5 # play the install demo at 5x speed,
# at 5x speed, limiting idle time to 0.5s. # with pauses limited to half a second.
``` ```

View File

@ -5,13 +5,14 @@ Play small demos of hledger usage in the terminal.
_FLAGS _FLAGS
Run this command with no argument to list the demos. To play a demo, Run this command with no argument to list the demos. To play a demo,
write its number or name or a substring. asciinema must be installed. write its number or a prefix or substring of its title. asciinema must
be installed.
During playback, several keys are available: - SPACE pause/unpause - . During playback, several keys are available: - SPACE pause/unpause - .
step forward (while paused) - CTRL-c quit early step forward (while paused) - CTRL-c quit early
asciinema options can be added following a double-dash; list them with asciinema options can be added following a double dash, such as -s
asciinema -h. -s (speed) and -i (max idle time) are particularly useful. (adjust speed) and -i (limit idle time). Run asciinema -h to list them.
Examples: Examples: