diff options
author | Joe Wilm <joe@jwilm.com> | 2016-11-19 16:16:20 -0800 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-11-19 21:34:11 -0800 |
commit | 66dbd29cd194a4c84f796f32827429895c2a3bba (patch) | |
tree | 5f5322cdae53d4fc295fe85f519192e9d38aab03 /src/tty.rs | |
parent | d97996e19de6856c23c51d05ec10f10db41e309d (diff) | |
download | alacritty-66dbd29cd194a4c84f796f32827429895c2a3bba.tar.gz alacritty-66dbd29cd194a4c84f796f32827429895c2a3bba.zip |
Add support for recording/running ref tests
Ref tests use a recording of the terminal protocol and a serialization
of the grid state to check that the parsing and action handling systems
produce the correct result. Ref tests may be recorded by running
alacritty with `--ref-test` and closing the terminal by using the window
"X" button. At that point, the recording is fully written to disk, and a
serialization of important state is recorded. Those files should be
moved to an appropriate folder in the `tests/ref/` tree, and the
`ref_test!` macro invocation should be updated accordingly.
A couple of changes were necessary to make this work:
* Ref tests shouldn't create a pty; the pty was refactored out of the
`Term` type.
* Repeatable lines/cols were needed; on startup, the terminal is resized
* by default to 80x24 though that may be changed by passing
`--dimensions w h`.
* Calculating window size based on desired rows/columns and font metrics
required making load_font callable multiple times.
* Refactor types into library crate so they may be imported in an
integration test.
* A whole bunch of types needed symmetric serialization and
deserialization. Mostly this was just adding derives, but the custom
deserialization of Rgb had to change to a deserialize_with function.
This initially adds one ref test as a sanity check, and more will be
added in subsequent commits. This initial ref tests just starts the
terminal and runs `ll`.
Diffstat (limited to 'src/tty.rs')
-rw-r--r-- | src/tty.rs | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -23,6 +23,8 @@ use std::ptr; use libc::{self, winsize, c_int, pid_t, WNOHANG, WIFEXITED, WEXITSTATUS, SIGCHLD}; +use index::{Line, Column}; + /// Process ID of child process /// /// Necessary to put this in static storage for `sigchld` to have access @@ -236,8 +238,8 @@ fn execsh() -> ! { } /// Create a new tty and return a handle to interact with it. -pub fn new(rows: u8, cols: u8) -> Tty { - let (master, slave) = openpty(rows, cols); +pub fn new(lines: Line, cols: Column) -> Pty { + let (master, slave) = openpty(lines.0 as _, cols.0 as _); match fork() { Relation::Child => { @@ -280,16 +282,16 @@ pub fn new(rows: u8, cols: u8) -> Tty { set_nonblocking(master); } - Tty { fd: master } + Pty { fd: master } } } } -pub struct Tty { +pub struct Pty { fd: c_int, } -impl Tty { +impl Pty { /// Get reader for the TTY /// /// XXX File is a bad abstraction here; it closes the fd on drop @@ -299,9 +301,11 @@ impl Tty { } } - pub fn resize(&self, rows: usize, cols: usize, px_x: usize, px_y: usize) { + pub fn resize(&self, lines: Line, cols: Column, px_x: usize, px_y: usize) { + let lines = lines.0; + let cols = cols.0; let win = winsize { - ws_row: rows as libc::c_ushort, + ws_row: lines 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, |