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

Fix setting the current progress for an indeterminate bar #56

Merged
merged 1 commit into from
Nov 10, 2024

Conversation

alexcwatt
Copy link
Contributor

Describe the change

I noticed that #current= failed for indeterminate progress bars. The primary test I added would error like this:

     ArgumentError:
       comparison of NilClass with 5 failed

I added a new ArgumentError guard to also preserve the existing, desirable, behavior of not supporting #current = nil, and a test to cover this. Note that current = nil was already raising ArgumentError in both the determinate and indeterminate cases (comparison of Integer with nil failed, comparison of NilClass with 0 failed, etc.); now the error message is one that we set.

Why are we doing this?

As far as I can tell, there's no reason that current = shouldn't work for indeterminate progress bars. It seems that indeterminate progress bars are meant to have a current value, and can have it by calling .advance, so adding support seems consistent with the rest of the library.

Benefits

It's quite nice to be able to set current progress for indeterminate progress bars!

Drawbacks

I don't have any to highlight.

Requirements

  • Tests written & passing locally?
  • Code style checked?
  • Rebased with master branch?
  • Documentation updated?
  • Changelog updated?

Copy link
Owner

@piotrmurach piotrmurach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Alex 👋

Thank you for using the tty-progressbar and submitting this PR.

I left a comment about the parameter type check. Let me know what you think. The current support for indeterminate progress change is, of course, desirable.

lib/tty/progressbar.rb Show resolved Hide resolved
lib/tty/progressbar.rb Outdated Show resolved Hide resolved
@alexcwatt
Copy link
Contributor Author

@piotrmurach The errors now focus on "numeric" instead of a particular class. Let me know what you think!

Copy link
Owner

@piotrmurach piotrmurach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making changes so quickly. There is a tiny issue to address for consistency. That should be all.

spec/unit/set_current_spec.rb Outdated Show resolved Hide resolved
@alexcwatt
Copy link
Contributor Author

@piotrmurach I've made that small change for consistency

@alexcwatt
Copy link
Contributor Author

@piotrmurach let me know if you want me to do anything else to make this mergeable

@piotrmurach
Copy link
Owner

@alexcwatt This is on my list, I promise I'm not ignoring you. Please bear with me.

@piotrmurach piotrmurach changed the title ProgressBar#current= supports indeterminate progress bars too Fix setting the current progress for an indeterminate bar Nov 10, 2024
@piotrmurach piotrmurach merged commit 3d1bfbb into piotrmurach:master Nov 10, 2024
18 of 20 checks passed
@piotrmurach
Copy link
Owner

@alexcwatt Released v0.18.3. Once again thanks for the PR!

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

Successfully merging this pull request may close these issues.

3 participants