diff --git a/examples/widgets_basic.rs b/examples/widgets_basic.rs index d0a7b2559..3fb471b30 100644 --- a/examples/widgets_basic.rs +++ b/examples/widgets_basic.rs @@ -1,6 +1,8 @@ //! This example shows how to make a basic widget that accumulates //! text input and renders it to the screen extern crate failure; +#[cfg(unix)] +extern crate libc; extern crate termwiz; use failure::Error; @@ -20,6 +22,14 @@ struct MainScreen { cursor: Cell, } +#[cfg(unix)] +fn catch_winch() { + extern "C" fn dummy(_: libc::c_int) {} + unsafe { + libc::signal(libc::SIGWINCH, dummy as usize); + } +} + impl WidgetImpl for MainScreen { fn process_event(&mut self, event: &WidgetEvent) -> EventDisposition { match event { @@ -43,6 +53,8 @@ impl WidgetImpl for MainScreen { fn render_to_surface(&self, surface: &mut Surface) { surface.add_change(Change::ClearScreen(AnsiColor::Blue.into())); + let dims = surface.dimensions(); + surface.add_change(format!("surface size is {:?}\r\n", dims)); surface.add_change(self.buf.clone()); // Allow the surface rendering code to figure out where the // cursor ends up, then stash a copy of that information for @@ -61,6 +73,9 @@ impl WidgetImpl for MainScreen { } fn main() -> Result<(), Error> { + #[cfg(unix)] + catch_winch(); + let caps = Capabilities::new_from_env()?; let mut buf = BufferedTerminal::new(new_terminal(caps)?)?; @@ -91,6 +106,9 @@ fn main() -> Result<(), Error> { } } + if buf.check_for_resize()? { + buf.add_change(Change::ClearScreen(Default::default())); + } screen.render_to_screen(&mut buf)?; buf.flush()?; } diff --git a/src/terminal/buffered.rs b/src/terminal/buffered.rs index f12297ad5..bd58c7e0f 100644 --- a/src/terminal/buffered.rs +++ b/src/terminal/buffered.rs @@ -97,8 +97,8 @@ impl BufferedTerminal { let size = self.terminal.get_screen_size()?; let (width, height) = self.surface.dimensions(); - if width != size.cols || height != size.rows { - self.surface.resize(width, height); + if (width != size.cols) || (height != size.rows) { + self.surface.resize(size.cols, size.rows); Ok(true) } else { Ok(false) diff --git a/src/terminal/unix.rs b/src/terminal/unix.rs index e5cd3eebb..17dbbbccc 100644 --- a/src/terminal/unix.rs +++ b/src/terminal/unix.rs @@ -331,6 +331,7 @@ impl Terminal for UnixTerminal { Ok(result) } Err(ref e) if e.kind() == ErrorKind::WouldBlock => Ok(None), + Err(ref e) if e.kind() == ErrorKind::Interrupted => Ok(None), Err(e) => Err(format_err!("failed to read input {}", e)), } }