diff options
author | Christian Duerr <contact@christianduerr.com> | 2021-03-30 23:25:38 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-30 23:25:38 +0000 |
commit | 3bd5ac221ab3b122962063edd1f4c10f9f2d117f (patch) | |
tree | b0a367b91611e911344aec9ff35354e5a473b6aa /alacritty_terminal/src/tty | |
parent | 974392cdc6fdf1ba0d213145ae578a9316e9d404 (diff) | |
download | alacritty-3bd5ac221ab3b122962063edd1f4c10f9f2d117f.tar.gz alacritty-3bd5ac221ab3b122962063edd1f4c10f9f2d117f.zip |
Unify the grid line indexing types
Previously Alacritty was using two different ways to reference lines in
the terminal. Either a `usize`, or a `Line(usize)`. These indexing
systems both served different purposes, but made it difficult to reason
about logic involving these systems because of its inconsistency.
To resolve this issue, a single new `Line(i32)` type has been
introduced. All existing references to lines and points now rely on
this definition of a line.
The indexing starts at the top of the terminal region with the line 0,
which matches the line 1 used by escape sequences. Each line in the
history becomes increasingly negative and the bottommost line is equal
to the number of visible lines minus one.
Having a system which goes into the negatives allows following the
escape sequence's indexing system closely, while at the same time making
it trivial to implement `Ord` for points.
The Alacritty UI crate is the only place which has a different indexing
system, since rendering and input puts the zero line at the top of the
viewport, rather than the top of the terminal region.
All instances which refer to a number of lines/columns instead of just a
single Line/Column have also been changed to use a `usize` instead. This
way a Line/Column will always refer to a specific place in the grid and
no confusion is created by having a count of lines as a possible index
into the grid storage.
Diffstat (limited to 'alacritty_terminal/src/tty')
-rw-r--r-- | alacritty_terminal/src/tty/unix.rs | 5 | ||||
-rw-r--r-- | alacritty_terminal/src/tty/windows/conpty.rs | 9 |
2 files changed, 8 insertions, 6 deletions
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs index 9cce1983..ba59bb66 100644 --- a/alacritty_terminal/src/tty/unix.rs +++ b/alacritty_terminal/src/tty/unix.rs @@ -25,6 +25,7 @@ use signal_hook::{self as sighook, iterator::Signals}; use crate::config::{Config, Program}; use crate::event::OnResize; +use crate::grid::Dimensions; use crate::term::SizeInfo; use crate::tty::{ChildEvent, EventedPty, EventedReadWrite}; @@ -357,8 +358,8 @@ pub trait ToWinsize { impl<'a> ToWinsize for &'a SizeInfo { fn to_winsize(&self) -> winsize { winsize { - ws_row: self.screen_lines().0 as libc::c_ushort, - ws_col: self.cols().0 as libc::c_ushort, + ws_row: self.screen_lines() as libc::c_ushort, + ws_col: self.columns() as libc::c_ushort, ws_xpixel: self.width() as libc::c_ushort, ws_ypixel: self.height() as libc::c_ushort, } diff --git a/alacritty_terminal/src/tty/windows/conpty.rs b/alacritty_terminal/src/tty/windows/conpty.rs index de3d8d4e..919bd00f 100644 --- a/alacritty_terminal/src/tty/windows/conpty.rs +++ b/alacritty_terminal/src/tty/windows/conpty.rs @@ -19,6 +19,7 @@ use winapi::um::wincontypes::{COORD, HPCON}; use crate::config::Config; use crate::event::OnResize; +use crate::grid::Dimensions; use crate::term::SizeInfo; use crate::tty::windows::child::ChildExitWatcher; use crate::tty::windows::{cmdline, win32_string, Pty}; @@ -185,11 +186,11 @@ impl OnResize for Conpty { /// Helper to build a COORD from a SizeInfo, returning None in overflow cases. fn coord_from_sizeinfo(size: &SizeInfo) -> Option<COORD> { - let cols = size.cols().0; - let lines = size.screen_lines().0; + let lines = size.screen_lines(); + let columns = size.columns(); - if cols <= i16::MAX as usize && lines <= i16::MAX as usize { - Some(COORD { X: cols as i16, Y: lines as i16 }) + if columns <= i16::MAX as usize && lines <= i16::MAX as usize { + Some(COORD { X: columns as i16, Y: lines as i16 }) } else { None } |