Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timer #44

Open
cyclotron3k opened this issue Nov 18, 2020 · 3 comments
Open

Add timer #44

cyclotron3k opened this issue Nov 18, 2020 · 3 comments

Comments

@cyclotron3k
Copy link

cyclotron3k commented Nov 18, 2020

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?

@piotrmurach
Copy link
Owner

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.

@cyclotron3k
Copy link
Author

cyclotron3k commented Nov 25, 2020

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 🤔

@piotrmurach
Copy link
Owner

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants