tty-spinner icon indicating copy to clipboard operation
tty-spinner copied to clipboard

Add timer

Open cyclotron3k opened this issue 5 years ago • 3 comments
trafficstars

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?

cyclotron3k avatar Nov 18 '20 04:11 cyclotron3k

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.

piotrmurach avatar Nov 21 '20 20:11 piotrmurach

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:

cyclotron3k avatar Nov 25 '20 02:11 cyclotron3k

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?

piotrmurach avatar Nov 25 '20 22:11 piotrmurach