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

Progress bar updates on new lines #360

Closed
wbogocki opened this issue Feb 2, 2022 · 5 comments
Closed

Progress bar updates on new lines #360

wbogocki opened this issue Feb 2, 2022 · 5 comments

Comments

@wbogocki
Copy link
Contributor

wbogocki commented Feb 2, 2022

Here's a new issue as requested.

OS: Windows 11 21H2 Build 22000.376 (latest stable one to my knowledge)
Terminal: VS Code 1.63.2 integrated terminal

Version 0.16 works without issue.

Output for 0.17.0-rc.2:

[#                   ] 0% 🥌 2421/525600 (216061.0691/s) ⏱ 00:00:00 (ETA 00:00:02) | Doing stuff...                                                                                                                                                                                                        [#                   ] 4% 🥌 19922/525600 (275073.6029/s) ⏱ 00:00:00 (ETA 00:00:01) | Doing stuff...                                                                                                                                                                                                       [##                  ] 7% 🥌 38170/525600 (274012.4835/s) ⏱ 00:00:00 (ETA 00:00:01) | Doing stuff...                                                                                                                                                                                                       [###                 ] 11% 🥌 56357/525600 (268608.7784/s) ⏱ 00:00:00 (ETA 00:00:01) | Doing stuff...                                                                                                                                                                                                      [###                 ] 14% 🥌 74228/525600 (265776.8413/s) ⏱ 00:00:00 (ETA 00:00:01) | Doing stuff...                                                                                                                                                                                                      [####                ] 17% 🥌 91943/525600 (264486.1798/s) ⏱ 00:00:00 (ETA 00:00:01) | Doing stuff...                                                                                                                                                                                                      [#####               ] 21% 🥌 109530/525600 (263163.4676/s) ⏱ 00:00:00 (ETA 00:00:01) | Doing stuff...                                                                                                                                                                                                     
[#####               ] 24% 🥌 127014/525600 (262198.9122/s) ⏱ 00:00:00 (ETA 00:00:01) | Doing stuff...                                                                                                                                                                                                     
[######              ] 27% 🥌 144495/525600 (262155.9439/s) ⏱ 00:00:00 (ETA 00:00:01) | Doing stuff...                                                                                                                                                                                                     
[#######             ] 31% 🥌 161966/525600 (262401.5976/s) ⏱ 00:00:00 (ETA 00:00:01) | Doing stuff...                                                                                                                                                                                                     
[#######             ] 34% 🥌 179478/525600 (263230.3474/s) ⏱ 00:00:00 (ETA 00:00:01) | Doing stuff...                                                                                                                                                                                                     
[########            ] 37% 🥌 197030/525600 (262241.7944/s) ⏱ 00:00:00 (ETA 00:00:01) | Doing stuff...                                                                                                                                                                                                     
[#########           ] 41% 🥌 214512/525600 (262512.2539/s) ⏱ 00:00:00 (ETA 00:00:01) | Doing stuff...                                                                                                                                                                                                     
[#########           ] 44% 🥌 232013/525600 (261348.6250/s) ⏱ 00:00:00 (ETA 00:00:01) | Doing stuff...                                                                                                                                                                                                     
[##########          ] 47% 🥌 249437/525600 (261426.8914/s) ⏱ 00:00:00 (ETA 00:00:01) | Doing stuff...                                                                                                                                                                                                     
[###########         ] 51% 🥌 266861/525600 (260778.5318/s) ⏱ 00:00:01 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[###########         ] 54% 🥌 284235/525600 (260765.6675/s) ⏱ 00:00:01 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[############        ] 57% 🥌 301616/525600 (260679.6394/s) ⏱ 00:00:01 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[#############       ] 61% 🥌 318988/525600 (260369.8677/s) ⏱ 00:00:01 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[#############       ] 64% 🥌 336349/525600 (260590.4877/s) ⏱ 00:00:01 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[##############      ] 67% 🥌 353723/525600 (260700.9683/s) ⏱ 00:00:01 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[###############     ] 71% 🥌 371106/525600 (260367.0554/s) ⏱ 00:00:01 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[###############     ] 74% 🥌 388465/525600 (260226.9450/s) ⏱ 00:00:01 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[################    ] 77% 🥌 405804/525600 (259551.2855/s) ⏱ 00:00:01 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[#################   ] 80% 🥌 423098/525600 (259005.1505/s) ⏱ 00:00:01 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[#################   ] 82% 🥌 431731/525600 (258381.1758/s) ⏱ 00:00:01 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[##################  ] 85% 🥌 448942/525600 (257905.5575/s) ⏱ 00:00:01 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[##################  ] 89% 🥌 466110/525600 (256801.1114/s) ⏱ 00:00:01 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[################### ] 92% 🥌 483227/525600 (256387.1104/s) ⏱ 00:00:01 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[####################] 95% 🥌 500304/525600 (256196.1187/s) ⏱ 00:00:01 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[####################] 97% 🥌 508843/525600 (254384.1073/s) ⏱ 00:00:02 (ETA 00:00:00) | Doing stuff...                                                                                                                                                                                                     
[####################] 100% 🥌 525600/525600 (254454.6886/s) ⏱ 00:00:02 (ETA 00:00:00) | Finished       

edit.

Forgot the code 😅

let spinner_style = ProgressStyle::default_bar()
    .template("[{bar}] {percent}% 🥌 {pos}/{len} ({per_sec}) ⏱ {elapsed_precise} (ETA {eta_precise}) | {msg}")
    .progress_chars("## ")
    .on_finish(ProgressFinish::AbandonWithMessage("Stopped".into()));

let spinner = ProgressBar::new_spinner();
spinner.set_length(size);
spinner.set_style(spinner_style);
spinner.set_message("Doing stuff...");
spinner.set_draw_rate(30);

for _ in 0..size {
    ...
    spinner.inc(1);
}

Originally posted by @wbogocki in #318 (comment)

@sigmaSd
Copy link
Contributor

sigmaSd commented Feb 2, 2022

Can u share the code you're using so I can easily test

Also does this happen with windows terminal or cmd?

@wbogocki
Copy link
Contributor Author

wbogocki commented Feb 2, 2022

Pasted the code above, I'm a scatterhead today looks like.

Yes, same behaviour with Windows Terminal.

@wbogocki wbogocki changed the title Progress bar updates on a new lines Progress bar updates on new lines Feb 2, 2022
@sigmaSd
Copy link
Contributor

sigmaSd commented Feb 2, 2022

Using indicatif improved_unicode feature make it work.

Is this still considered a bug or is it an expected behavior since your using 🥌 which the default feature set can't handle (it count it as width 1 incorrectly since its just chars().count())

Also I think this feature gate is not worth it, unicode-width is not a big dependency and I think its essential for nice looking bars, what about at least making it the default?

@wbogocki
Copy link
Contributor Author

wbogocki commented Feb 3, 2022

I see. Thank you.

If the progress bar doesn't handle characters with width>1 correctly by default and also doesn't warn about it then you're likely to see similar bug reports in the future.

For my two cents: I don't have a strong opinion other than I'd only make sure this problem doesn't occur or if it does occur that the solution is right next to it. As you pointed out the unicode-width crate is tiny and has no dependencies of its own so I too am leaning to either using it by default or inlining it.

This solves my problem but I'll leave the issue open in case you want to make the changes. Feel free to close and thanks for the help :)

@djc
Copy link
Collaborator

djc commented Feb 3, 2022

I've enabled unicode-width by default.

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

No branches or pull requests

3 participants