-
Notifications
You must be signed in to change notification settings - Fork 288
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
Input Reader consumes cursor position LINUX #140
Comments
Is this issue related to #122? In that case, it is probably already fixed in master |
yeah already tested on master, and its seems related to #122 but the fix isn't enough it seems
this makes things better, I can call intoscreenraw outside of the loop and I get less race conditions when I type fast, but it looks more like a workaround for a problem that I still can't pinpoint |
What do you mean with race conditions? You aren't using two threads. Also by making |
I will happily make a pr one I figure out what exactly is the issue. use crossterm::*;
pub struct Term {
cursor: TerminalCursor,
terminal: Terminal,
input: TerminalInput,
}
impl Term {
pub fn new() -> Self {
let crossterm = Crossterm::new();
let cursor = crossterm.cursor();
let terminal = crossterm.terminal();
let input = crossterm.input();
Term {
cursor,
terminal,
input,
}
}
pub fn run(&mut self) -> std::io::Result<()> {
let mut stdin = self.input.read_sync();
let _screen = crossterm::RawScreen::into_raw_mode()?;
loop {
if let Some(key_event) = stdin.next() {
match key_event {
_ => {self.terminal.write(&format!("{} {} || ", self.cursor.pos().0, self.cursor.pos().1));},
}
}
}
}
}
fn main() {
let mut term = Term::new();
term.run().expect("ouch");
} If I type slowly everything works fine but if I type fast I get a lot of |
new hint, pub fn run(&mut self) -> std::io::Result<()> {
let mut stdin = self.input.read_sync();
let _screen = crossterm::RawScreen::into_raw_mode()?;
loop {
if let Some(key_event) = dbg!(stdin.next()) {
let _ = self.cursor.pos();
match key_event {
_ => ()//{self.terminal.write(&format!("{} {} || ", self.cursor.pos().0, self.cursor.pos().1));},
}
}
}
} if I use self.cursor.pos() inside the loop and type fast sometimes I get stdin.next() = Some(Unknown) |
I think I figured out the issue now, the race condition is acessing stdin
when typing fast stdin will still has some leftovers so this wont work
Its better with this patch but I wonder if there is a better way than looping. Also for changes that this means
because pos errors and reset to 0
so when writing multi-line we have to reset pos.x to 0 |
I finally fixed my program by not relying on |
@sigmaSd This is more than just |
@keur I only used sync till now so I wouldn't now, anyhow everything works great now that I'm not using |
this patch works
|
Fixed by #152 |
Hi, first thanks a lot for this awesome project!
While most of time everything is fine typing fast unveils a lot of problems, in particular
https://github.com/TimonPost/crossterm/blob/master/crossterm_cursor/src/sys/unix.rs#L6 returns (0, 0) (when typing fast) so I end up unable to depend on cursor.pos(), also a side effect I noticed
RawScreen::into_raw_mode()
gets disabled after the first key stroke for example hereCurrently to workaround that I call raw screen on each cycle of the loop:
also if use a hack like
rawscreen works normally outside the loop and doesn't get disabled, but a lot of weird issues appear
Hopefully this makes sense, maybe a timeout is needed but I'm not quite sure where the problem lies that's why I'm opening this issue for awareness.
Tested on linux gnome-terminal(wayland)
The text was updated successfully, but these errors were encountered: