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

cursor.hide() isn't scoped to the current screen reference #63

Closed
imdaveho opened this issue Dec 18, 2018 · 7 comments
Closed

cursor.hide() isn't scoped to the current screen reference #63

imdaveho opened this issue Dec 18, 2018 · 7 comments

Comments

@imdaveho
Copy link
Contributor

imdaveho commented Dec 18, 2018

a quick example is if I pass in a new alternative screen and call

let ct = Crossterm::from_screen(&alternative.screen);
let cursor = ct.cursor();
cursor.hide();

When switching back -- dropping the new screen that was created just for the alternative screen; the terminal still has the cursor hidden. Is this intended behavior, or do we want to have cursor behaviors scoped to the current screen?

I would imagine something like cursor.show() and .hide() works at the terminal level, so even if we create new screens, it's not like we can only modify cursor behavior for those screens...

Edit: yep, just confirmed with the alternate_screen.rs example file and it indeed doesn't scope the cursor only to the alt screen. Haven't checked by starting a new screen from within the example; but I'm sure it's related.

@TimonPost
Copy link
Member

Thanks for creating the issue. This should be screen specific I need. However it is supposed to do that. I'll give it a look why this is not happening.

@TimonPost TimonPost added this to the 0.6 milestone Dec 28, 2018
@TimonPost
Copy link
Member

    let screen = crossterm::Screen::default();
    match screen.enable_alternate_modes(false) {
        Ok(alternative) => {
            let ct = crossterm::Crossterm::from_screen(&alternative.screen);
            let cursor = ct.cursor();
            cursor.hide();
        }
        Err(e) => {}

I can't find why this would occur. I tested in on windows and got the same result as you. I still need to give it a test on a UNIX based machine and see if it is the same there. Also, I might chek if termion has the same problem.

@TimonPost TimonPost removed this from the 0.6 milestone Jan 27, 2019
@imdaveho
Copy link
Contributor Author

imdaveho commented Jan 29, 2019

I think this issue is due to not restoring the previous console/terminal settings on shutdown. When applying syscalls to hide or show cursor, it needs to be reversed on exit -- checkout termbox-go's implementation.

@TimonPost
Copy link
Member

yes, that might be true. Did you check this for Unix systems? For WinApi it also seems like it operates terminal based and not screen based.

@imdaveho
Copy link
Contributor Author

I didn't check exactly on Unix systems, but looking at termbox-go: https://github.com/nsf/termbox-go/blob/master/api.go#L129

Notice how the code, upon closing, re-establishes some default state like showing the cursor back into stdout. Not sure if Unix-y systems has an equivalent to winapi's GetConsoleState, but it would be preferable to restore the preexisting state, rather than overwriting state (even if they are sane defaults)

@TimonPost
Copy link
Member

Ah, oke. It is just resetting everything back to default.

@TimonPost
Copy link
Member

Closing in favor of https://github.com/TimonPost/crossterm/issues/new

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

2 participants