From 3f16e8ed6023900094d85d6b7996e96166488088 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Mon, 18 Jun 2018 16:50:09 -0700 Subject: [PATCH] Do not use chan_signal on windows --- Cargo.toml | 2 +- src/backend/curses/pan.rs | 15 ++++++++++++++- src/lib.rs | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5c5e986..9bd8449 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ version = "1.0.0" optional = true version = "1.3.1" -[dependencies.chan-signal] +[target.'cfg(unix)'.dependencies.chan-signal] version = "0.3" [dependencies.ncurses] diff --git a/src/backend/curses/pan.rs b/src/backend/curses/pan.rs index f67fb8d..0b3f363 100644 --- a/src/backend/curses/pan.rs +++ b/src/backend/curses/pan.rs @@ -364,6 +364,19 @@ fn on_resize() { pancurses::resize_term(size.y as i32, size.x as i32); } +#[cfg(unix)] +fn resize_channel() -> chan::Receiver { + chan_signal::notify(&[chan_signal::Signal::WINCH]) +} + +#[cfg(not(unix))] +fn resize_channel() -> chan::Receiver<()> { + let (sender, receiver) = chan::async(); + // Forget the sender, so the channel doesn't close, but never completes. + ::std::mem::forget(sender); + receiver +} + impl backend::Backend for Backend { fn screen_size(&self) -> Vec2 { // Coordinates are reversed here @@ -438,7 +451,7 @@ impl backend::Backend for Backend { &mut self, event_sink: chan::Sender, stops: chan::Receiver, ) { - let resize = chan_signal::notify(&[chan_signal::Signal::WINCH]); + let resize = resize_channel(); let (sender, receiver) = chan::async(); let needs_resize = Arc::clone(&self.needs_resize); diff --git a/src/lib.rs b/src/lib.rs index 0f404ac..56e869c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,7 +74,11 @@ extern crate chan; #[macro_use] extern crate maplit; +// We use chan_signal to detect SIGWINCH. +// It's not how windows work, so no need to use that. +#[cfg(unix)] extern crate chan_signal; + extern crate libc; extern crate num; extern crate owning_ref;