mirror of
https://github.com/wez/wezterm.git
synced 2024-12-25 14:22:37 +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
|
||||
//! 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<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 {
|
||||
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()?;
|
||||
}
|
||||
|
@ -97,8 +97,8 @@ impl<T: Terminal> BufferedTerminal<T> {
|
||||
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)
|
||||
|
@ -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)),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user