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

Empty lines in MultiProgress::println leads to lost output #606

Closed
tgolsson opened this issue Nov 22, 2023 · 4 comments · Fixed by #608
Closed

Empty lines in MultiProgress::println leads to lost output #606

tgolsson opened this issue Nov 22, 2023 · 4 comments · Fixed by #608

Comments

@tgolsson
Copy link
Contributor

tgolsson commented Nov 22, 2023

Associated repro repo: https://github.com/tgolsson/indicatif-repro. It expects the indicatif repo to be checked out adjacently.

I'm debugging this issue in Pantsbuild: pantsbuild/pants#20171, and have isolated a reproduction for a bad print related to multiple repeated \n. On line 225 in that repository, there's a \n\n before the final line. That leads to losing the final line. If it's a single \n, the last line is printed. As far as I can tell while playing around with that message; each time \n\n is seen we lose one line of output from the end. So \n\n seen three times means we lose three lines from the end, and so on.

I'm 95% confident that the error exists here:

indicatif/src/multi.rs

Lines 278 to 282 in f33789e

fn real_len(lines: &[String], width: f64) -> usize {
lines.iter().fold(0, |sum, val| {
sum + (console::measure_text_width(val) as f64 / width).ceil() as usize
})
}

As that will count "zero-width" lines as being no line at all. Indeed, changing that to floor + 1 fixes the issue. It also fixes the issue for single progress bars (that are part of multiprogress), which I guess is because they share state somehow? You can play around with it on my repo by printing to pb instead of multiprogress, again on line 225.

@tgolsson tgolsson changed the title Repeated empty lines in MultiProgressBar::println leads to lost output Repeated empty lines in MultiProgress::println leads to lost output Nov 22, 2023
@tgolsson tgolsson changed the title Repeated empty lines in MultiProgress::println leads to lost output Empty lines in MultiProgress::println leads to lost output Nov 22, 2023
@tgolsson
Copy link
Contributor Author

I think my fix is maybe a bit too simplistic on the other edge now that I think about it, but if the location feels right I can do a robust solution with some proper tests.

@djc
Copy link
Member

djc commented Nov 23, 2023

I don't remember all the context here, but it looks to me like real_len() is about the line width, not about the number of lines? @chris-laplante do you have an intuition for this?

@tgolsson
Copy link
Contributor Author

As far as I can tell, it is the "sum of wrapped line count", i.e., number of lines once wrapping is applied.

@chris-laplante
Copy link
Collaborator

I don't remember all the context here, but it looks to me like real_len() is about the line width, not about the number of lines? @chris-laplante do you have an intuition for this?

I don't have this stored in my head anymore unfortunately :/. I will try to take some time over the coming holiday weeks to look at it.

@djc djc closed this as completed in #608 Dec 12, 2023
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

Successfully merging a pull request may close this issue.

3 participants