From 6777182c708b1a519c1b8891a4a665e836b58e38 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 16 Mar 2023 23:00:34 -1000 Subject: [PATCH] imp: demo: output cleanups --- hledger/Hledger/Cli/Commands/Demo.hs | 24 +++++++++++++++--------- hledger/Hledger/Cli/Commands/Demo.md | 12 ++++++------ hledger/Hledger/Cli/Commands/Demo.txt | 7 ++++--- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Demo.hs b/hledger/Hledger/Cli/Commands/Demo.hs index 318cf5ba3..083bca9ca 100644 --- a/hledger/Hledger/Cli/Commands/Demo.hs +++ b/hledger/Hledger/Cli/Commands/Demo.hs @@ -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 = diff --git a/hledger/Hledger/Cli/Commands/Demo.md b/hledger/Hledger/Cli/Commands/Demo.md index 4d43c693b..712cd7bba 100644 --- a/hledger/Hledger/Cli/Commands/Demo.md +++ b/hledger/Hledger/Cli/Commands/Demo.md @@ -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. ``` diff --git a/hledger/Hledger/Cli/Commands/Demo.txt b/hledger/Hledger/Cli/Commands/Demo.txt index 5769ed9ff..ebf63f99f 100644 --- a/hledger/Hledger/Cli/Commands/Demo.txt +++ b/hledger/Hledger/Cli/Commands/Demo.txt @@ -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: