diff options
author | Joe Wilm <joe@jwilm.com> | 2016-05-30 20:44:37 -0700 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-06-02 19:42:28 -0700 |
commit | 30ec14510935d46e7454863f9a4e63e53bf7728c (patch) | |
tree | 9501fe70ecf582e57903fbc061d3e6a0928f3f33 /src/tty.rs | |
parent | 70b0423a31016798592fc0e96ce316cb3f1e9d46 (diff) | |
download | alacritty-30ec14510935d46e7454863f9a4e63e53bf7728c.tar.gz alacritty-30ec14510935d46e7454863f9a4e63e53bf7728c.zip |
Initial support for Terminal Emulation (woo!)
This patch introduces basic support for terminal emulation. Basic means
commands that don't use paging and are not full screen applications like
vim or tmux. Some paging applications are working properly, such as as
`git log`. Other pagers work reasonably well as long as the help menu is
not accessed.
There is now a central Rgb color type which is shared by the renderer,
terminal emulation, and the pty parser.
The parser no longer owns a Handler. Instead, a mutable reference to a
Handler is provided whenever advancing the parser. This resolved some
potential ownership issues (eg parser owning the `Term` type would've
been unworkable).
Diffstat (limited to 'src/tty.rs')
-rw-r--r-- | src/tty.rs | 51 |
1 files changed, 44 insertions, 7 deletions
@@ -189,7 +189,7 @@ fn execsh() -> ! { } /// Create a new tty and return a handle to interact with it. -pub fn new(rows: u8, cols: u8) -> File { +pub fn new(rows: u8, cols: u8) -> Tty { let (master, slave) = openpty(rows, cols); match fork() { @@ -221,12 +221,49 @@ pub fn new(rows: u8, cols: u8) -> File { libc::close(slave); } - // XXX should this really return a file? - // How should this be done? Could build a File::from_raw_fd, or maybe implement a custom - // type that can be used in a mio event loop? For now, just do the file option. - unsafe { - File::from_raw_fd(master) - } + Tty { fd: master } + } + } +} + +pub struct Tty { + fd: c_int, +} + +impl Tty { + /// Get reader for the TTY + /// + /// XXX File is a bad abstraction here; it closes the fd on drop + pub fn reader(&self) -> File { + unsafe { + File::from_raw_fd(self.fd) + } + } + + /// Get writer for the TTY + /// + /// XXX File is a bad abstraction here; it closes the fd on drop + pub fn writer(&self) -> File { + unsafe { + File::from_raw_fd(self.fd) + } + } + + pub fn resize(&self, rows: usize, cols: usize, px_x: usize, px_y: usize) { + + let win = winsize { + ws_row: rows as libc::c_ushort, + ws_col: cols as libc::c_ushort, + ws_xpixel: px_x as libc::c_ushort, + ws_ypixel: px_y as libc::c_ushort, + }; + + let res = unsafe { + libc::ioctl(self.fd, libc::TIOCSWINSZ, &win as *const _) + }; + + if res < 0 { + die!("ioctl TIOCSWINSZ failed: {}", errno()); } } } |