`cursor_pos` in multi-thread?
Created by: lotabout
The support for query cursor position is introduced by this MR: https://github.com/ticki/termion/pull/93, however the function cursor_pos
did not work when stdin
is used in another thread.
I believe it is common to have two independent thread for handling input and drawing the result.
Here is an example that causes trouble.
use termion::raw::{IntoRawMode, RawTerminal};
use termion::event::{Key, Event};
use termion::input::TermRead;
use termion::cursor::DetectCursorPos;
use std::io::{Write, stdout, stdin};
use std::thread;
fn main() {
let stdin = stdin();
let mut stdout = stdout().into_raw_mode().unwrap();
thread::spawn(move || {
while true {
let (y, x) = stdout.cursor_pos().unwrap();
println!("y: {}, x: {}", y, x);
thread::sleep_ms(500);
}
});
for c in stdin.events() {
let evt = c.unwrap();
match evt {
Event::Key(Key::Char('q')) => break,
Event::Key(Key::Char(k)) => {
println!("{}", k);
}
_ => {println!("Other");}
}
}
}