aboutsummaryrefslogtreecommitdiff
path: root/alacritty_terminal
diff options
context:
space:
mode:
authorAyose Cazorla <ayosec@gmail.com>2020-08-28 22:26:03 +0000
committerGitHub <noreply@github.com>2020-08-28 22:26:03 +0000
commitcdf5e51e742d67d1b96940a5096210725a1e51e8 (patch)
tree4652f37d8a9c32d3da4670d8706c96158caf1d72 /alacritty_terminal
parentee2c5a6cdd6a07f18b99a50b9d2737bd8ea391c4 (diff)
downloadalacritty-cdf5e51e742d67d1b96940a5096210725a1e51e8.tar.gz
alacritty-cdf5e51e742d67d1b96940a5096210725a1e51e8.zip
Add escape to report text area size
This implements the escapes `CSI 14 t` and `CSI 18 t` which report the text area size in pixels and characters.
Diffstat (limited to 'alacritty_terminal')
-rw-r--r--alacritty_terminal/src/ansi.rs8
-rw-r--r--alacritty_terminal/src/selection.rs2
-rw-r--r--alacritty_terminal/src/term/mod.rs52
-rw-r--r--alacritty_terminal/src/vi_mode.rs2
-rw-r--r--alacritty_terminal/tests/ref.rs2
5 files changed, 46 insertions, 20 deletions
diff --git a/alacritty_terminal/src/ansi.rs b/alacritty_terminal/src/ansi.rs
index 8f1cf07f..5038b734 100644
--- a/alacritty_terminal/src/ansi.rs
+++ b/alacritty_terminal/src/ansi.rs
@@ -316,6 +316,12 @@ pub trait Handler {
/// Pop the last title from the stack.
fn pop_title(&mut self) {}
+
+ /// Report text area size in pixels.
+ fn text_area_size_pixels<W: io::Write>(&mut self, _: &mut W) {}
+
+ /// Report text area size in characters.
+ fn text_area_size_chars<W: io::Write>(&mut self, _: &mut W) {}
}
/// Describes shape of cursor.
@@ -1080,6 +1086,8 @@ where
('s', None) => handler.save_cursor_position(),
('T', None) => handler.scroll_down(Line(next_param_or(1) as usize)),
('t', None) => match next_param_or(1) as usize {
+ 14 => handler.text_area_size_pixels(writer),
+ 18 => handler.text_area_size_chars(writer),
22 => handler.push_title(),
23 => handler.pop_title(),
_ => unhandled!(),
diff --git a/alacritty_terminal/src/selection.rs b/alacritty_terminal/src/selection.rs
index 83dea824..450a4633 100644
--- a/alacritty_terminal/src/selection.rs
+++ b/alacritty_terminal/src/selection.rs
@@ -418,7 +418,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- Term::new(&MockConfig::default(), &size, Mock)
+ Term::new(&MockConfig::default(), size, Mock)
}
/// Test case of single cell selection.
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs
index 97025386..15499e07 100644
--- a/alacritty_terminal/src/term/mod.rs
+++ b/alacritty_terminal/src/term/mod.rs
@@ -745,6 +745,9 @@ pub struct Term<T> {
/// Current forward and backward buffer search regexes.
regex_search: Option<RegexSearch>,
+
+ /// Information about window dimensions.
+ size: SizeInfo,
}
impl<T> Term<T> {
@@ -758,7 +761,7 @@ impl<T> Term<T> {
self.dirty = true;
}
- pub fn new<C>(config: &Config<C>, size: &SizeInfo, event_proxy: T) -> Term<T> {
+ pub fn new<C>(config: &Config<C>, size: SizeInfo, event_proxy: T) -> Term<T> {
let num_cols = size.cols();
let num_lines = size.lines();
@@ -795,6 +798,7 @@ impl<T> Term<T> {
title_stack: Vec::new(),
selection: None,
regex_search: None,
+ size,
}
}
@@ -964,7 +968,9 @@ impl<T> Term<T> {
}
/// Resize terminal to new dimensions.
- pub fn resize(&mut self, size: &SizeInfo) {
+ pub fn resize(&mut self, size: SizeInfo) {
+ self.size = size;
+
let old_cols = self.cols();
let old_lines = self.screen_lines();
let num_cols = max(size.cols(), Column(MIN_SIZE));
@@ -2219,6 +2225,18 @@ impl<T: EventListener> Handler for Term<T> {
self.set_title(popped);
}
}
+
+ #[inline]
+ fn text_area_size_pixels<W: io::Write>(&mut self, writer: &mut W) {
+ let width = self.size.cell_width as usize * self.cols().0;
+ let height = self.size.cell_height as usize * self.screen_lines().0;
+ let _ = write!(writer, "\x1b[4;{};{}t", height, width);
+ }
+
+ #[inline]
+ fn text_area_size_chars<W: io::Write>(&mut self, writer: &mut W) {
+ let _ = write!(writer, "\x1b[8;{};{}t", self.screen_lines(), self.cols());
+ }
}
/// Terminal version for escape sequence reports.
@@ -2342,7 +2360,7 @@ pub mod test {
padding_y: 0.,
dpr: 1.,
};
- let mut term = Term::new(&Config::<()>::default(), &size, ());
+ let mut term = Term::new(&Config::<()>::default(), size, ());
// Fill terminal with content.
for (line, text) in lines.iter().rev().enumerate() {
@@ -2399,7 +2417,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Mock);
+ let mut term = Term::new(&MockConfig::default(), size, Mock);
let mut grid: Grid<Cell> = Grid::new(Line(3), Column(5), 0, Cell::default());
for i in 0..5 {
for j in 0..2 {
@@ -2455,7 +2473,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Mock);
+ let mut term = Term::new(&MockConfig::default(), size, Mock);
let mut grid: Grid<Cell> = Grid::new(Line(1), Column(5), 0, Cell::default());
for i in 0..5 {
grid[Line(0)][Column(i)].c = 'a';
@@ -2484,7 +2502,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Mock);
+ let mut term = Term::new(&MockConfig::default(), size, Mock);
let mut grid: Grid<Cell> = Grid::new(Line(3), Column(3), 0, Cell::default());
for l in 0..3 {
if l != 1 {
@@ -2529,7 +2547,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Mock);
+ let mut term = Term::new(&MockConfig::default(), size, Mock);
let cursor = Point::new(Line(0), Column(0));
term.configure_charset(CharsetIndex::G0, StandardCharset::SpecialCharacterAndLineDrawing);
term.input('a');
@@ -2548,7 +2566,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Mock);
+ let mut term = Term::new(&MockConfig::default(), size, Mock);
// Add one line of scrollback.
term.grid.scroll_up(&(Line(0)..Line(1)), Line(1), Cell::default());
@@ -2578,7 +2596,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Mock);
+ let mut term = Term::new(&MockConfig::default(), size, Mock);
// Create 10 lines of scrollback.
for _ in 0..19 {
@@ -2589,7 +2607,7 @@ mod tests {
// Increase visible lines.
size.height = 30.;
- term.resize(&size);
+ term.resize(size);
assert_eq!(term.history_size(), 0);
assert_eq!(term.grid.cursor.point, Point::new(Line(19), Column(0)));
@@ -2606,7 +2624,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Mock);
+ let mut term = Term::new(&MockConfig::default(), size, Mock);
// Create 10 lines of scrollback.
for _ in 0..19 {
@@ -2620,7 +2638,7 @@ mod tests {
// Increase visible lines.
size.height = 30.;
- term.resize(&size);
+ term.resize(size);
// Leave alt screen.
term.unset_mode(ansi::Mode::SwapScreenAndSetRestoreCursor);
@@ -2640,7 +2658,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Mock);
+ let mut term = Term::new(&MockConfig::default(), size, Mock);
// Create 10 lines of scrollback.
for _ in 0..19 {
@@ -2651,7 +2669,7 @@ mod tests {
// Increase visible lines.
size.height = 5.;
- term.resize(&size);
+ term.resize(size);
assert_eq!(term.history_size(), 15);
assert_eq!(term.grid.cursor.point, Point::new(Line(4), Column(0)));
@@ -2668,7 +2686,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Mock);
+ let mut term = Term::new(&MockConfig::default(), size, Mock);
// Create 10 lines of scrollback.
for _ in 0..19 {
@@ -2682,7 +2700,7 @@ mod tests {
// Increase visible lines.
size.height = 5.;
- term.resize(&size);
+ term.resize(size);
// Leave alt screen.
term.unset_mode(ansi::Mode::SwapScreenAndSetRestoreCursor);
@@ -2702,7 +2720,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&MockConfig::default(), &size, Mock);
+ let mut term = Term::new(&MockConfig::default(), size, Mock);
// Title None by default.
assert_eq!(term.title, None);
diff --git a/alacritty_terminal/src/vi_mode.rs b/alacritty_terminal/src/vi_mode.rs
index 965cd3d5..53534f73 100644
--- a/alacritty_terminal/src/vi_mode.rs
+++ b/alacritty_terminal/src/vi_mode.rs
@@ -416,7 +416,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- Term::new(&MockConfig::default(), &size, Mock)
+ Term::new(&MockConfig::default(), size, Mock)
}
#[test]
diff --git a/alacritty_terminal/tests/ref.rs b/alacritty_terminal/tests/ref.rs
index 54031022..5036a3ed 100644
--- a/alacritty_terminal/tests/ref.rs
+++ b/alacritty_terminal/tests/ref.rs
@@ -102,7 +102,7 @@ fn ref_test(dir: &Path) {
let mut config = MockConfig::default();
config.scrolling.set_history(ref_config.history_size);
- let mut terminal = Term::new(&config, &size, Mock);
+ let mut terminal = Term::new(&config, size, Mock);
let mut parser = ansi::Processor::new();
for byte in recording {