From 1f1e238d2e54285888a89005233ea877cd5de2af Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Sun, 8 Jul 2018 12:54:35 -0700 Subject: [PATCH] Fix pancurses for windows --- src/backend/curses/pan.rs | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/backend/curses/pan.rs b/src/backend/curses/pan.rs index af9e6a0..0da0e76 100644 --- a/src/backend/curses/pan.rs +++ b/src/backend/curses/pan.rs @@ -317,6 +317,7 @@ impl Backend { pairs: RefCell::new(HashMap::new()), window: Arc::new(window), needs_resize: Arc::new(AtomicBool::new(false)), + #[cfg(unix)] signals, }; @@ -458,22 +459,29 @@ impl backend::Backend for Backend { let resize_running = Arc::clone(&running); let resize_sender = event_sink.clone(); - let signals = self.signals.take().unwrap(); - thread::spawn(move || { - // This thread will listen to SIGWINCH events and report them. - while resize_running.load(Ordering::Relaxed) { - // We know it will only contain SIGWINCH signals, so no need to check. - for _ in signals.pending() { - // Tell ncurses about the new terminal size. - // Well, do the actual resizing later on, in the main thread. - // 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)); + #[cfg(unix)] + { + let signals = self.signals.take().unwrap(); + thread::spawn(move || { + // This thread will listen to SIGWINCH events and report them. + while resize_running.load(Ordering::Relaxed) { + // We know it will only contain SIGWINCH signals, so no need to check. + for _ in signals.pending() { + // Tell ncurses about the new terminal size. + // Well, do the actual resizing later on, in the main thread. + // 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 = InputParser::new(event_sink, Arc::clone(&self.window));