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 move cursor flag not working #648

Merged
merged 2 commits into from
Jun 13, 2024
Merged

Conversation

SuperTux88
Copy link
Contributor

I had the problem of my progress bars starting to flicker after adding some more bars, especially over an ssh connection. I then found #42 and from that then found #143, but the fix described there to set m.set_move_cursor(true); didn't make a difference at all.

After some debugging, I found out, that the move_cursor flag was used in the draw_to_term() function, but this is only called from a Drawable::Term, while the set_move_cursor was only set on the MultiState which is only used in the Drawable::Multi. So in the current state, it never has any effect when actually drawing to the terminal.

Then after forwarding the flag to the correct DrawState instance, I noticed, that the first bar always starts drawing one line too high on the last char, so the first line was just off-by-one. This was because the cursor is always on the last char of the last line, and then moving up the number of bars, will always end up one line too high. So just move up one line less, but then the cursor also still needs to be moved to the front of the line.

So this now fixes using of set_move_cursor(true) again, so it can be used to fix the flickering.

Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

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

Thanks for the investigation!

Would you be able to add a test that can help us avoid regressing this in the future?

src/multi.rs Outdated Show resolved Hide resolved
The move_cursor flag needs to be set in the wrapped Term draw state, as
that's the one, that is then actually used to draw to the terminal. The
move_cursor flag in the multi draw state doesn't have any effect on
drawing to the terminal.
The cursor needs to move to the first line (which is one less than the
number of lines, as the cursor is still on the last line), and then also
move to the front of that line (as it was on the last char of the last
line).
@SuperTux88
Copy link
Contributor Author

Thanks for the review.

Would you be able to add a test that can help us avoid regressing this in the future?

I tried to do that, but failed, because the output looks the same, whether it moves the cursor or uses clear, so the test was always green, even when it was broken (so it wasn't useful). But I just noticed moves_since_last_check() where I can check for moves specifically, and added a test using that. So it now fails when it gets broken. 👍

Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@djc djc merged commit 24eaf46 into console-rs:main Jun 13, 2024
10 checks passed
@SuperTux88 SuperTux88 deleted the fix-move_cursor branch June 13, 2024 13:42
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 this pull request may close these issues.

2 participants