aboutsummaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/ansi.rs
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2021-03-30 23:25:38 +0000
committerGitHub <noreply@github.com>2021-03-30 23:25:38 +0000
commit3bd5ac221ab3b122962063edd1f4c10f9f2d117f (patch)
treeb0a367b91611e911344aec9ff35354e5a473b6aa /alacritty_terminal/src/ansi.rs
parent974392cdc6fdf1ba0d213145ae578a9316e9d404 (diff)
downloadalacritty-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/ansi.rs')
-rw-r--r--alacritty_terminal/src/ansi.rs46
1 files changed, 22 insertions, 24 deletions
diff --git a/alacritty_terminal/src/ansi.rs b/alacritty_terminal/src/ansi.rs
index b46aec0b..44c92d3e 100644
--- a/alacritty_terminal/src/ansi.rs
+++ b/alacritty_terminal/src/ansi.rs
@@ -299,13 +299,13 @@ pub trait Handler {
fn goto_col(&mut self, _: Column) {}
/// Insert blank characters in current line starting from cursor.
- fn insert_blank(&mut self, _: Column) {}
+ fn insert_blank(&mut self, _: usize) {}
/// Move cursor up `rows`.
- fn move_up(&mut self, _: Line) {}
+ fn move_up(&mut self, _: usize) {}
/// Move cursor down `rows`.
- fn move_down(&mut self, _: Line) {}
+ fn move_down(&mut self, _: usize) {}
/// Identify the terminal (should write back to the pty stream).
fn identify_terminal<W: io::Write>(&mut self, _: &mut W, _intermediate: Option<char>) {}
@@ -320,10 +320,10 @@ pub trait Handler {
fn move_backward(&mut self, _: Column) {}
/// Move cursor down `rows` and set to column 1.
- fn move_down_and_cr(&mut self, _: Line) {}
+ fn move_down_and_cr(&mut self, _: usize) {}
/// Move cursor up `rows` and set to column 1.
- fn move_up_and_cr(&mut self, _: Line) {}
+ fn move_up_and_cr(&mut self, _: usize) {}
/// Put `count` tabs.
fn put_tab(&mut self, _count: u16) {}
@@ -352,16 +352,16 @@ pub trait Handler {
fn set_horizontal_tabstop(&mut self) {}
/// Scroll up `rows` rows.
- fn scroll_up(&mut self, _: Line) {}
+ fn scroll_up(&mut self, _: usize) {}
/// Scroll down `rows` rows.
- fn scroll_down(&mut self, _: Line) {}
+ fn scroll_down(&mut self, _: usize) {}
/// Insert `count` blank lines.
- fn insert_blank_lines(&mut self, _: Line) {}
+ fn insert_blank_lines(&mut self, _: usize) {}
/// Delete `count` lines.
- fn delete_lines(&mut self, _: Line) {}
+ fn delete_lines(&mut self, _: usize) {}
/// Erase `count` chars in current line following cursor.
///
@@ -373,7 +373,7 @@ pub trait Handler {
///
/// Deleting a character is like the delete key on the keyboard - everything
/// to the right of the deleted things is shifted left.
- fn delete_chars(&mut self, _: Column) {}
+ fn delete_chars(&mut self, _: usize) {}
/// Move backward `count` tabs.
fn move_backward_tabs(&mut self, _count: u16) {}
@@ -1122,11 +1122,9 @@ where
};
match (action, intermediates) {
- ('@', []) => handler.insert_blank(Column(next_param_or(1) as usize)),
- ('A', []) => {
- handler.move_up(Line(next_param_or(1) as usize));
- },
- ('B', []) | ('e', []) => handler.move_down(Line(next_param_or(1) as usize)),
+ ('@', []) => handler.insert_blank(next_param_or(1) as usize),
+ ('A', []) => handler.move_up(next_param_or(1) as usize),
+ ('B', []) | ('e', []) => handler.move_down(next_param_or(1) as usize),
('b', []) => {
if let Some(c) = self.state.preceding_char {
for _ in 0..next_param_or(1) {
@@ -1141,9 +1139,9 @@ where
handler.identify_terminal(writer, intermediates.get(0).map(|&i| i as char))
},
('D', []) => handler.move_backward(Column(next_param_or(1) as usize)),
- ('d', []) => handler.goto_line(Line(next_param_or(1) as usize - 1)),
- ('E', []) => handler.move_down_and_cr(Line(next_param_or(1) as usize)),
- ('F', []) => handler.move_up_and_cr(Line(next_param_or(1) as usize)),
+ ('d', []) => handler.goto_line(Line(next_param_or(1) as i32 - 1)),
+ ('E', []) => handler.move_down_and_cr(next_param_or(1) as usize),
+ ('F', []) => handler.move_up_and_cr(next_param_or(1) as usize),
('G', []) | ('`', []) => handler.goto_col(Column(next_param_or(1) as usize - 1)),
('g', []) => {
let mode = match next_param_or(0) {
@@ -1158,7 +1156,7 @@ where
handler.clear_tabs(mode);
},
('H', []) | ('f', []) => {
- let y = next_param_or(1) as usize;
+ let y = next_param_or(1) as i32;
let x = next_param_or(1) as usize;
handler.goto(Line(y - 1), Column(x - 1));
},
@@ -1198,7 +1196,7 @@ where
handler.clear_line(mode);
},
- ('L', []) => handler.insert_blank_lines(Line(next_param_or(1) as usize)),
+ ('L', []) => handler.insert_blank_lines(next_param_or(1) as usize),
('l', intermediates) => {
for param in params_iter.map(|param| param[0]) {
match Mode::from_primitive(intermediates.get(0), param) {
@@ -1207,7 +1205,7 @@ where
}
}
},
- ('M', []) => handler.delete_lines(Line(next_param_or(1) as usize)),
+ ('M', []) => handler.delete_lines(next_param_or(1) as usize),
('m', []) => {
if params.is_empty() {
handler.terminal_attribute(Attr::Reset);
@@ -1221,7 +1219,7 @@ where
}
},
('n', []) => handler.device_status(writer, next_param_or(0) as usize),
- ('P', []) => handler.delete_chars(Column(next_param_or(1) as usize)),
+ ('P', []) => handler.delete_chars(next_param_or(1) as usize),
('q', [b' ']) => {
// DECSCUSR (CSI Ps SP q) -- Set Cursor Style.
let cursor_style_id = next_param_or(0);
@@ -1247,9 +1245,9 @@ where
handler.set_scrolling_region(top, bottom);
},
- ('S', []) => handler.scroll_up(Line(next_param_or(1) as usize)),
+ ('S', []) => handler.scroll_up(next_param_or(1) as usize),
('s', []) => handler.save_cursor_position(),
- ('T', []) => handler.scroll_down(Line(next_param_or(1) as usize)),
+ ('T', []) => handler.scroll_down(next_param_or(1) as usize),
('t', []) => match next_param_or(1) as usize {
14 => handler.text_area_size_pixels(writer),
18 => handler.text_area_size_chars(writer),