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

Make cursor screen specific #169

Open
TimonPost opened this issue Jun 22, 2019 · 4 comments
Open

Make cursor screen specific #169

TimonPost opened this issue Jun 22, 2019 · 4 comments

Comments

@TimonPost
Copy link
Member

Task Description

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.

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)

Task Todo

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. https://github.com/nsf/termbox-go/blob/master/api.go#L129

@Kestrer
Copy link
Contributor

Kestrer commented May 2, 2020

Does this still apply with crossterm's current API? Either way, the title should be changed.

@TimonPost
Copy link
Member Author

I believe it is. It is related to the alternate screen and main screen. If one disables the cursor on an alternate screen it will still be disabled if it leaves the alternate screen.

@kallekankaanpaa
Copy link

Can't reproduce this on Windows 10, tried both cmd and powershell.

Here's the code I used to test it

use crossterm::cursor::Hide;
use crossterm::style::Print;
use crossterm::terminal::{EnterAlternateScreen, LeaveAlternateScreen};
use crossterm::{ExecutableCommand, Result};
use std::io::stdout;
use std::{thread, time};

pub fn main() -> Result<()> {
    let mut stdout = stdout();
    let two_secs = time::Duration::from_secs(2);
    stdout.execute(Print("Primary"))?;
    thread::sleep(two_secs);
    stdout
        .execute(EnterAlternateScreen)?
        .execute(Print("Alternate"))?;
    thread::sleep(two_secs);
    stdout.execute(Hide)?;
    thread::sleep(two_secs);
    stdout.execute(LeaveAlternateScreen)?;
    thread::sleep(two_secs);

    Ok(())
}

@lesleyrs
Copy link
Contributor

lesleyrs commented Apr 6, 2023

Ah so that's why it wasn't added yet, I guess we can track my change here #775 for a reminder to revert it once this gets added.

december1981 pushed a commit to december1981/crossterm that referenced this issue Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants