imp: demo: output cleanups
This commit is contained in:
parent
2d496609bc
commit
6777182c70
@ -13,8 +13,7 @@ module Hledger.Cli.Commands.Demo (
|
||||
|
||||
import Hledger
|
||||
import Hledger.Cli.CliOptions
|
||||
import Control.Monad (forM_)
|
||||
import System.Exit (exitSuccess, exitFailure)
|
||||
import System.Exit (exitFailure)
|
||||
import Text.Printf
|
||||
import Control.Concurrent (threadDelay)
|
||||
import System.Process (callProcess)
|
||||
@ -47,7 +46,10 @@ demomode = hledgerCommandMode
|
||||
[]
|
||||
[generalflagsgroup3]
|
||||
[]
|
||||
([], Just $ argsFlag "[NUM|NAME|STR] [-- ASCIINEMAOPTS]")
|
||||
([], Just $ argsFlag optsstr)
|
||||
|
||||
optsstr = "[NUM|PREFIX|SUBSTR] [-- ASCIINEMAOPTS]"
|
||||
usagestr = "Usage: hledger demo " <> optsstr
|
||||
|
||||
-- | The demo command.
|
||||
demo :: CliOpts -> Journal -> IO ()
|
||||
@ -55,15 +57,13 @@ demo CliOpts{rawopts_=rawopts, reportspec_=ReportSpec{_rsQuery=_query}} _j = do
|
||||
-- demos <- getCurrentDirectory >>= readDemos
|
||||
let args = listofstringopt "args" rawopts
|
||||
case args of
|
||||
[] -> do
|
||||
forM_ (zip [(1::Int)..] demos) $ \(i, Demo t _) -> printf "%d) %s\n" i t
|
||||
exitSuccess
|
||||
|
||||
[] -> putStrLn usagestr >> printDemos
|
||||
(a:as) ->
|
||||
case findDemo demos a of
|
||||
Nothing -> do
|
||||
putStrLn $ a <> " not recognized"
|
||||
putStrLn "Usage: hledger-demo [NUM|NAME|STR], run with no arguments to see a list"
|
||||
putStrLn $ "No demo \"" <> a <> "\" was found."
|
||||
putStrLn usagestr
|
||||
printDemos
|
||||
exitFailure
|
||||
|
||||
Just (Demo t c) -> do
|
||||
@ -90,6 +90,12 @@ findDemo ds s =
|
||||
where
|
||||
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.
|
||||
runAsciinemaPlay :: ByteString -> [String] -> IO ()
|
||||
runAsciinemaPlay content args =
|
||||
|
||||
@ -5,7 +5,7 @@ Play small demos of hledger usage in the terminal.
|
||||
_FLAGS
|
||||
|
||||
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.
|
||||
|
||||
During playback, several keys are available:
|
||||
@ -13,14 +13,14 @@ During playback, several keys are available:
|
||||
- . step forward (while paused)
|
||||
- CTRL-c quit early
|
||||
|
||||
asciinema options can be added following a double-dash;
|
||||
list them with `asciinema -h`. `-s` (speed) and
|
||||
`-i` (max idle time) are particularly useful.
|
||||
asciinema options can be added following a double dash, such as
|
||||
`-s` (adjust speed) and `-i` (limit idle time).
|
||||
Run `asciinema -h` to list these.
|
||||
|
||||
Examples:
|
||||
```shell
|
||||
$ hledger demo # list available demos
|
||||
$ hledger demo 1 # play the first demo
|
||||
$ hledger demo install -s5 -i.5 # play the demo named or containing "install",
|
||||
# at 5x speed, limiting idle time to 0.5s.
|
||||
$ hledger demo install -s5 -i.5 # play the install demo at 5x speed,
|
||||
# with pauses limited to half a second.
|
||||
```
|
||||
|
||||
@ -5,13 +5,14 @@ Play small demos of hledger usage in the terminal.
|
||||
_FLAGS
|
||||
|
||||
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 - .
|
||||
step forward (while paused) - CTRL-c quit early
|
||||
|
||||
asciinema options can be added following a double-dash; list them with
|
||||
asciinema -h. -s (speed) and -i (max idle time) are particularly useful.
|
||||
asciinema options can be added following a double dash, such as -s
|
||||
(adjust speed) and -i (limit idle time). Run asciinema -h to list them.
|
||||
|
||||
Examples:
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user