Fix wide element styling to work with 'improved_unicode' feature as well #357
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
From style.rs, line 385:
When the
improved_unicode
feature is off,measure_text_width
just counts characters. Consider the case of rendering the default progress bar style.cur
will be something like\x00 0/10
. In this casemeasure_text_width
returns the width as 6 since it is counting the null byte. This bug is what led to the addition of line 394 to offset it (in #350):When
improved_unicode
is on,measure_text_width
correctly returns 5 because it ignores the control character. However, the aforementioned line adds a 1 which causes the progress bar to spill a character onto the next line of the terminal.To reproduce, simply run
cargo test --features=improved_unicode
on current main branch. You will get several test failures caused by'attempt to subtract with overflow', src/draw_target.rs:402:44
None of the automated tests caught this because they run in an environment without a tty, so indicatif considers the bars "hidden" and thus nothing is rendered. I spotted this as part of developing the in-memory terminal (#354).