Getting cursor position still panics
Hi!
I would like to report an old but big issue of Termion that still exists:
cursor_pos()
panics when using stdin in other thread that the one of the call.
The following two examples demonstrate the problem: Using thread:
use std::io;
use std::thread;
use termion::cursor::DetectCursorPos;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
fn main() {
let mut stdout = io::stdout().into_raw_mode().unwrap();
let handle = thread::spawn(|| {
let stdin = io::stdin();
for _input in stdin.keys() {}
});
let (init_a, init_b) = stdout.cursor_pos().unwrap(); //panics !
println!("{}:{}", init_a, init_b);
handle.join().unwrap();
}
Using async_stdin()
use std::io::{self, Read};
use termion::async_stdin;
use termion::cursor::DetectCursorPos;
use termion::raw::IntoRawMode;
fn main() {
let mut stdout = io::stdout().into_raw_mode().unwrap();
let mut stdin = async_stdin().bytes();
let (init_a, init_b) = stdout.cursor_pos().unwrap(); //panics !
println!("{}:{}", init_a, init_b);
}
What does that mean ?
Its means that it is actually impossible to retrieve the cursor position when using async_stdin
or when stdin is used in another thread.
But using stdin in another thread is the only way to handle input events without blocking the current thread, so it is simply a huge use case !
Actually I can not believe that a library like Termion has this kind of problem! I mean, this issue greatly limits the usages of the library.
Edited by doums