Fix pancurses for windows

This commit is contained in:
Alexandre Bury 2018-07-08 12:54:35 -07:00
parent 6135b0df79
commit 1f1e238d2e

View File

@ -317,6 +317,7 @@ impl Backend {
pairs: RefCell::new(HashMap::new()), pairs: RefCell::new(HashMap::new()),
window: Arc::new(window), window: Arc::new(window),
needs_resize: Arc::new(AtomicBool::new(false)), needs_resize: Arc::new(AtomicBool::new(false)),
#[cfg(unix)]
signals, signals,
}; };
@ -458,22 +459,29 @@ impl backend::Backend for Backend {
let resize_running = Arc::clone(&running); let resize_running = Arc::clone(&running);
let resize_sender = event_sink.clone(); let resize_sender = event_sink.clone();
let signals = self.signals.take().unwrap();
thread::spawn(move || { #[cfg(unix)]
// This thread will listen to SIGWINCH events and report them. {
while resize_running.load(Ordering::Relaxed) { let signals = self.signals.take().unwrap();
// We know it will only contain SIGWINCH signals, so no need to check. thread::spawn(move || {
for _ in signals.pending() { // This thread will listen to SIGWINCH events and report them.
// Tell ncurses about the new terminal size. while resize_running.load(Ordering::Relaxed) {
// Well, do the actual resizing later on, in the main thread. // We know it will only contain SIGWINCH signals, so no need to check.
// Ncurses isn't really thread-safe so calling resize_term() can crash for _ in signals.pending() {
// other calls like clear() or refresh(). // Tell ncurses about the new terminal size.
needs_resize.store(true, Ordering::Relaxed); // Well, do the actual resizing later on, in the main thread.
resize_sender.send(Some(Event::WindowResize)); // Ncurses isn't really thread-safe so calling resize_term() can crash
// other calls like clear() or refresh().
needs_resize.store(true, Ordering::Relaxed);
resize_sender.send(Some(Event::WindowResize));
}
} }
} });
}); }
// On windows we just forget the sender, so the receiver blocks forever.
#[cfg(not(unix))]
::std::mem::forget(resize_sender);
let mut input_parser = let mut input_parser =
InputParser::new(event_sink, Arc::clone(&self.window)); InputParser::new(event_sink, Arc::clone(&self.window));