diff options
author | Joe Wilm <joe@jwilm.com> | 2016-12-12 09:31:48 -0800 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-12-12 09:31:48 -0800 |
commit | 1a1b740c38cfbadff4cd985ee925ac024627d2b9 (patch) | |
tree | 98f51ebedcc1abff0101da7747403b0d8aee698f /src/tty.rs | |
parent | 4e9a307bed50fc02f101eb6cbfa4d39283dd6b8c (diff) | |
download | alacritty-1a1b740c38cfbadff4cd985ee925ac024627d2b9.tar.gz alacritty-1a1b740c38cfbadff4cd985ee925ac024627d2b9.zip |
Remove need for Rc<RefCell<_>> usage
This adds a trait OnResize and a separate method handle_resize to the
display. Instead of having a callback to receive resize events, a list
of &mut OnResize are passed to this new method. Doing this allowed the
only RefCell usage in the codebase to be removed :).
Diffstat (limited to 'src/tty.rs')
-rw-r--r-- | src/tty.rs | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -23,6 +23,9 @@ use std::ptr; use libc::{self, winsize, c_int, pid_t, WNOHANG, WIFEXITED, WEXITSTATUS, SIGCHLD}; +use term::SizeInfo; +use display::OnResize; + /// Process ID of child process /// /// Necessary to put this in static storage for `sigchld` to have access @@ -326,6 +329,23 @@ pub trait ToWinsize { fn to_winsize(&self) -> winsize; } +impl<'a> ToWinsize for &'a SizeInfo { + fn to_winsize(&self) -> winsize { + winsize { + ws_row: self.lines().0 as libc::c_ushort, + ws_col: self.cols().0 as libc::c_ushort, + ws_xpixel: self.width as libc::c_ushort, + ws_ypixel: self.height as libc::c_ushort, + } + } +} + +impl OnResize for Pty { + fn on_resize(&mut self, size: &SizeInfo) { + self.resize(size); + } +} + unsafe fn set_nonblocking(fd: c_int) { use libc::{fcntl, F_SETFL, F_GETFL, O_NONBLOCK}; |