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

Always restore hidden cursor #30

Merged

Conversation

drbrain
Copy link
Contributor

@drbrain drbrain commented Jul 17, 2018

Through some subtleties it is possible for the progress bar to not
restore the cursor:

b = TTY::ProgressBar.new "stuff |:bar|",
                         hide_cursor: true,
                         no_width: true,
                         total: 5,
                         width: 5

b.finish

Prior to this commit when #finish executes it will not restore the
cursor.

Tracing through #finish, while hide_cursor is true, we skip restoring
the cursor because the last render width is still 0 as we have not
rendered. We haven't completed the progress bar so we are not #done?.
We then #render.

In #render we are still not #done? so we hide the cursor because
hide_cursor is true, our last render width is still zero, and the
current value is not the total.

This leaves the cursor hidden when we exit the program.

This commit moves cursor restoration to the ensure block of finish so it
should always run, even if we are #done?

Through some subtleties it is possible for the progress bar to not
restore the cursor:

    b = TTY::ProgressBar.new "stuff |:bar|",
                             hide_cursor: true,
                             no_width: true,
                             total: 5,
                             width: 5

    b.finish

Prior to this commit when #finish executes it will not restore the
cursor.

Tracing through #finish, while `hide_cursor` is true, we skip restoring
the cursor because the last render width is still 0 as we have not
rendered.  We haven't completed the progress bar so we are not #done?.
We then #render.

In #render we are still not #done? so we hide the cursor because
`hide_cursor` is true, our last render width is still zero, and the
current value is not the total.

This leaves the cursor hidden when we exit the program.

This commit moves cursor restoration to the ensure block of finish so it
should always run, even if we are #done?
@coveralls
Copy link

coveralls commented Jul 17, 2018

Coverage Status

Coverage decreased (-1.6%) to 96.11% when pulling 223bfcd on drbrain:drbrain/improve-restore-cursor into a662108 on piotrmurach:master.

@piotrmurach piotrmurach merged commit 9b25c91 into piotrmurach:master Jul 19, 2018
@drbrain drbrain deleted the drbrain/improve-restore-cursor branch July 19, 2018 17:58
@piotrmurach
Copy link
Owner

@drbrain Thanks! Your PRs are mega, I like the way you provide a full description of the issue, makes super easy to review and merge! ❤️ Released v0.15.1 with your patch!

@drbrain
Copy link
Contributor Author

drbrain commented Jul 19, 2018

This library is nicely designed so I don't have to do too much to slip a change in

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.

3 participants