-
-
Notifications
You must be signed in to change notification settings - Fork 28
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 manual_stop option #53
base: master
Are you sure you want to change the base?
Add manual_stop option #53
Conversation
examples/multi/multi_manual_stop.rb
Outdated
|
||
spinners = TTY::Spinner::Multi.new("[:spinner] Top level spinner", { | ||
manual_stop: true, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/IndentHash: Indent the right brace the same as the first position after the preceding left parenthesis.
examples/multi/multi_manual_stop.rb
Outdated
require_relative "../../lib/tty-spinner" | ||
|
||
spinners = TTY::Spinner::Multi.new("[:spinner] Top level spinner", { | ||
manual_stop: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/IndentHash: Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.
Style/TrailingCommaInHashLiteral: Avoid comma after the last item of a hash.
examples/multi/multi_manual_stop.rb
Outdated
|
||
require_relative "../../lib/tty-spinner" | ||
|
||
spinners = TTY::Spinner::Multi.new("[:spinner] Top level spinner", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter.
lib/tty/spinner/multi.rb
Outdated
@@ -49,13 +49,18 @@ class Multi | |||
# clear ouptut when finished | |||
# @option options [Float] :interval | |||
# the interval for auto spinning | |||
# @option options [Boolean] :manual_stop | |||
# the top spinner (if present) doesn’t automatically stop when all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/AsciiComments: Use only ascii symbols in comments.
spec/unit/multi/auto_spin_spec.rb
Outdated
|
||
spinner = spinners.register("three") { |sp| jobs << "three"; sp.success } | ||
spinner.run | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
spec/unit/multi/auto_spin_spec.rb
Outdated
it 'keeps the top level spinner spinning' do | ||
spinners = TTY::Spinner::Multi.new("top", output: output, manual_stop: true) | ||
jobs = [] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
|
||
context 'when manual_stop option is set' do | ||
it 'keeps the top level spinner spinning' do | ||
spinners = TTY::Spinner::Multi.new("top", output: output, manual_stop: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [82/80]
spec/unit/multi/auto_spin_spec.rb
Outdated
@@ -28,5 +28,27 @@ | |||
spinners.auto_spin | |||
|
|||
expect(jobs).to match_array(%w[one two]) | |||
expect(spinners.top_spinner.done?).to be(true) | |||
end | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
f4a00da
to
5ff5412
Compare
Describe the change
This adds the
manual_stop
option (defaulting tofalse
) to multi spinners, so that the top-level spinner will never stop spinning until it is stopped manually.See
examples/multi/multi_manual_stop.rb
:Screencast.from.2024-07-23.01-16-33.mp4
Why are we doing this?
Closes #45
In our specific use case, we’re working on integrating tty-spinner into our development tool GDK to work with Rake and later allow parallel updates. We only want to show spinners for currently running tasks, and not pre-register spinners in case we later want to skip them to reduce visual noise. By gaining manual control over the top-level spinner, we can keep it spinning until all tasks have finished.
Benefits
Present a better user experience in use cases such as our’s or the one detailed in #45.
Drawbacks
Manual control over the top level spinner could be confusing for a developer, so they might end up keeping the spinner running indefinitely, breaking the output until the process exits. Though this can already happen if not all registered are stopped.
Requirements
master
branch?