tty-spinner
tty-spinner copied to clipboard
Add timer
Feature request: Show a timer next to the spinner, to show how long the process has been running?
# Current syntax:
spinner = TTY::Spinner.new("[:spinner] Loading ...", format: :pulse_2)
# Possible syntax:
spinner = TTY::Spinner.new("[:spinner] Running for :timer", format: :pulse_2)
# => [/] Running for 1:30:12
# Possible syntax:
spinner = TTY::Spinner.new("[:spinner] Running for :timer", format: :pulse_2, timer_format: '%Hh%m')
# => [/] Running for 1h30
If you're interested, I can have a look at making a PR?
I like the idea. The tty-progressbar gem already supports similar :elapsed token, you can check it out for inspiration. I don't necessarily aim to mirror token naming but some parity/similarity helps. Anyway, please submit PR.
I'm a big fan of keeping things consistent.
Speaking of which, we're using two types of placeholders across the TTY suite. e.g.: :spinner Loading... and "|:slider| %d%%".
It would be possible to use one style to achieve the same thing:
"[%<spinner>s] %<volume>03i" % {spinner: "/", volume: 3 }
=> "[/] 003"
It's a bit more complex though :thinking:
Thanks for pointing out the inconsistent formatting in the tty-prompt slider but that's less of an issue. By and large, the TTY suite is consistent in the way it applies tokens. Tokens are more 'powerful' than simple string substitutions as they have access to internal state and can manage more complex behaviours. The tty-progressbar :bar token is a very good example of this. I'd prefer to keep similar token behaviour in tty-spinner. Do you have time to submit PR with your suggestion?