Skip to content

refactor(cli/unstable): make ProgressBar options optional #6407

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

timreichen
Copy link
Contributor

This PR make ProgressBar options an optional argument. This is done by setting options.max to 1 by default. This default value is taken from HTMLProgressElement.

@timreichen timreichen requested a review from kt3k as a code owner February 15, 2025 10:44
@github-actions github-actions bot added the cli label Feb 15, 2025
Copy link

codecov bot commented Feb 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.54%. Comparing base (390845e) to head (5395e07).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6407   +/-   ##
=======================================
  Coverage   94.54%   94.54%           
=======================================
  Files         580      580           
  Lines       43730    43731    +1     
  Branches     6471     6471           
=======================================
+ Hits        41345    41346    +1     
  Misses       2342     2342           
  Partials       43       43           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@BlackAsLight
Copy link
Contributor

I'm not a fan of this change as, I imagine you're always going to want to set a max value, and forgetting to set one where the value goes over max will throw an error

@timreichen
Copy link
Contributor Author

I'm not a fan of this change as, I imagine you're always going to want to set a max value, and forgetting to set one where the value goes over max will throw an error

I don't think value > max should throw. This might lead to unintended bugs with floating-point errors.
So we might want to change that which would pave the way for a default max (as in HTMLProgressElement).

WDYT?

@BlackAsLight
Copy link
Contributor

I'm not a fan of this change as, I imagine you're always going to want to set a max value, and forgetting to set one where the value goes over max will throw an error

I don't think value > max should throw. This might lead to unintended bugs with floating-point errors.

So we might want to change that which would pave the way for a default max (as in HTMLProgressElement).

WDYT?

It will throw when the maths has "-".repeat(-1) in the print function. As it doesn't seem to like negative numbers. It could be wrapped in a Math.max to stop this with the end result be that the progress bar just grows past its bar length.

@timreichen
Copy link
Contributor Author

I'm not a fan of this change as, I imagine you're always going to want to set a max value, and forgetting to set one where the value goes over max will throw an error

I don't think value > max should throw. This might lead to unintended bugs with floating-point errors.
So we might want to change that which would pave the way for a default max (as in HTMLProgressElement).
WDYT?

It will throw when the maths has "-".repeat(-1) in the print function. As it doesn't seem to like negative numbers. It could be wrapped in a Math.max to stop this with the end result be that the progress bar just grows past its bar length.

I'll have a look at that. clamping these values seems like a good idea anyway.

@kt3k
Copy link
Member

kt3k commented Mar 21, 2025

Because this module formats the value as byte numbers by default, setting max=1 as default feels strange to me.

I'm not a fan of this change as, I imagine you're always going to want to set a max value

If we consider max as required argument, then we probably should set max as positional argument instead of option

@timreichen
Copy link
Contributor Author

Because this module formats the value as byte numbers by default, setting max=1 as default feels strange to me.

I'm not a fan of this change as, I imagine you're always going to want to set a max value

If we consider max as required argument, then we probably should set max as positional argument instead of option

I was thinking about this a bit. max = 1 just seems right for a progress indication as a default.
This causes a problem now because the current implementation is geared towards data/downloads which is not the only progress indication type.
So I was wondering:
Should we split up the ProgressBar and the ProgressBarStream implementation, making the ProgressBar sync like Spinner and remove the unit implementation and indicate percentages instead and let ProgressBarStream work like it does now for a data driven indication?

Another option would be to remove the custom fmt property from ProgressBar and instead introduced a style property that determine the format. Something like:

type ProgressBarType = "percentage" | "download"
new ProgressBar({ type: "percentage" }) // [###-------] [30%]
new ProgressBar({ type: "download" }) // [mm:ss] [###-------] [0.40/97.66 KiB]

This would be less customizable but simplify the api. I am aware that I proposed the format property instead of style options.

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