mirror of
https://github.com/wez/wezterm.git
synced 2024-12-25 22:33:52 +03:00
Trying to improve resize detection and processing
This commit is contained in:
parent
250fb20fca
commit
16dbbb2bad
@ -1,6 +1,8 @@
|
|||||||
//! This example shows how to make a basic widget that accumulates
|
//! This example shows how to make a basic widget that accumulates
|
||||||
//! text input and renders it to the screen
|
//! text input and renders it to the screen
|
||||||
extern crate failure;
|
extern crate failure;
|
||||||
|
#[cfg(unix)]
|
||||||
|
extern crate libc;
|
||||||
extern crate termwiz;
|
extern crate termwiz;
|
||||||
|
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
@ -20,6 +22,14 @@ struct MainScreen {
|
|||||||
cursor: Cell<ParentRelativeCoords>,
|
cursor: Cell<ParentRelativeCoords>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
fn catch_winch() {
|
||||||
|
extern "C" fn dummy(_: libc::c_int) {}
|
||||||
|
unsafe {
|
||||||
|
libc::signal(libc::SIGWINCH, dummy as usize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl WidgetImpl for MainScreen {
|
impl WidgetImpl for MainScreen {
|
||||||
fn process_event(&mut self, event: &WidgetEvent) -> EventDisposition {
|
fn process_event(&mut self, event: &WidgetEvent) -> EventDisposition {
|
||||||
match event {
|
match event {
|
||||||
@ -43,6 +53,8 @@ impl WidgetImpl for MainScreen {
|
|||||||
|
|
||||||
fn render_to_surface(&self, surface: &mut Surface) {
|
fn render_to_surface(&self, surface: &mut Surface) {
|
||||||
surface.add_change(Change::ClearScreen(AnsiColor::Blue.into()));
|
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());
|
surface.add_change(self.buf.clone());
|
||||||
// Allow the surface rendering code to figure out where the
|
// Allow the surface rendering code to figure out where the
|
||||||
// cursor ends up, then stash a copy of that information for
|
// cursor ends up, then stash a copy of that information for
|
||||||
@ -61,6 +73,9 @@ impl WidgetImpl for MainScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Error> {
|
fn main() -> Result<(), Error> {
|
||||||
|
#[cfg(unix)]
|
||||||
|
catch_winch();
|
||||||
|
|
||||||
let caps = Capabilities::new_from_env()?;
|
let caps = Capabilities::new_from_env()?;
|
||||||
|
|
||||||
let mut buf = BufferedTerminal::new(new_terminal(caps)?)?;
|
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)?;
|
screen.render_to_screen(&mut buf)?;
|
||||||
buf.flush()?;
|
buf.flush()?;
|
||||||
}
|
}
|
||||||
|
@ -97,8 +97,8 @@ impl<T: Terminal> BufferedTerminal<T> {
|
|||||||
let size = self.terminal.get_screen_size()?;
|
let size = self.terminal.get_screen_size()?;
|
||||||
let (width, height) = self.surface.dimensions();
|
let (width, height) = self.surface.dimensions();
|
||||||
|
|
||||||
if width != size.cols || height != size.rows {
|
if (width != size.cols) || (height != size.rows) {
|
||||||
self.surface.resize(width, height);
|
self.surface.resize(size.cols, size.rows);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else {
|
} else {
|
||||||
Ok(false)
|
Ok(false)
|
||||||
|
@ -331,6 +331,7 @@ impl Terminal for UnixTerminal {
|
|||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
Err(ref e) if e.kind() == ErrorKind::WouldBlock => Ok(None),
|
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)),
|
Err(e) => Err(format_err!("failed to read input {}", e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user