-
Notifications
You must be signed in to change notification settings - Fork 286
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 position swallowed by input reader #199
Cursor position swallowed by input reader #199
Comments
Hi, what version are you using? This is an issue that had been solved some time ago. |
@TimonPost - I believe this is from the latest version released on crates.io |
I rewrote this example for the latest use std::io::Write;
use crossterm::{cursor, input, InputEvent, KeyEvent, RawScreen, Result};
fn main() -> Result<()> {
let _screen = RawScreen::into_raw_mode();
let input = input();
let mut stdin = input.read_async();
let cursor = cursor();
print!("> ");
let _ = std::io::stdout().flush()?;
let mut _reset_position = cursor.pos()?;
loop {
if let Some(key) = stdin.next() {
match key {
InputEvent::Keyboard(KeyEvent::Esc) => break,
InputEvent::Keyboard(KeyEvent::Enter) => {
print!("\r\n> ");
let _ = std::io::stdout().flush();
_reset_position = cursor.pos()?;
}
_ => {}
}
}
}
Ok(())
} Didn't debug it yet, but the described symptoms are same on macOS. This code:
|
And I can confirm that it behaves correctly when I comment out both |
Backtrace ...
Hang caused by this line: Seems like it's waiting for the @TimonPost does it ring a bell? You said you believe it was fixed, maybe you know what's going on from top of your head. |
Seems like a racing problem. We ask for the cursor position with |
Here's the input I've got (in this exact order):
When the example quits immediately:
When the example is waiting for the enter, I hit it and the it ends:
As you can see, the sequence This must be synced somehow. |
I have no direct answer for that. This topic has come up in the past checkout : |
Another comment from @MaulingMonkey: This has a few problems:
|
This example will fail back to the terminal or hang after hitting enter 1-5 times (on Linux):
The text was updated successfully, but these errors were encountered: