aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAyose <ayosec@gmail.com>2021-04-02 00:54:28 +0100
committerAyose <ayosec@gmail.com>2021-04-02 00:58:08 +0100
commit50d717f3b1c9b4265941cf1cbae4e87d8a0db02e (patch)
tree9d1de3650992f1648ef2acb3fa8a7d11baa43fbd
parentb4adf34bb9ce6e28fa0c15ab8b9eaea20303e982 (diff)
downloadr-alacritty-50d717f3b1c9b4265941cf1cbae4e87d8a0db02e.tar.gz
r-alacritty-50d717f3b1c9b4265941cf1cbae4e87d8a0db02e.tar.bz2
r-alacritty-50d717f3b1c9b4265941cf1cbae4e87d8a0db02e.zip
Implementation of the XTSMGRAPHICS sequence.
-rw-r--r--alacritty_terminal/src/ansi.rs4
-rw-r--r--alacritty_terminal/src/graphics/sixel.rs2
-rw-r--r--alacritty_terminal/src/term/mod.rs33
-rw-r--r--docs/escape_support.md1
4 files changed, 38 insertions, 2 deletions
diff --git a/alacritty_terminal/src/ansi.rs b/alacritty_terminal/src/ansi.rs
index 40515837..27b9231e 100644
--- a/alacritty_terminal/src/ansi.rs
+++ b/alacritty_terminal/src/ansi.rs
@@ -471,6 +471,9 @@ pub trait Handler {
/// Report text area size in characters.
fn text_area_size_chars<W: io::Write>(&mut self, _: &mut W) {}
+ /// Report a graphics attribute.
+ fn graphics_attribute<W: io::Write>(&mut self, _: &mut W, _: u16, _: u16) {}
+
/// Create a parser for Sixel data.
fn start_sixel_graphic(&mut self, _params: &Params) -> Option<Box<sixel::Parser>> {
None
@@ -1282,6 +1285,7 @@ where
handler.set_scrolling_region(top, bottom);
},
('S', []) => handler.scroll_up(next_param_or(1) as usize),
+ ('S', [b'?']) => handler.graphics_attribute(writer, next_param_or(0), next_param_or(0)),
('s', []) => handler.save_cursor_position(),
('T', []) => handler.scroll_down(next_param_or(1) as usize),
('t', []) => match next_param_or(1) as usize {
diff --git a/alacritty_terminal/src/graphics/sixel.rs b/alacritty_terminal/src/graphics/sixel.rs
index 476089cc..221fe7cd 100644
--- a/alacritty_terminal/src/graphics/sixel.rs
+++ b/alacritty_terminal/src/graphics/sixel.rs
@@ -33,7 +33,7 @@ use vte::Params;
struct ColorRegister(u16);
/// Number of color registers.
-const MAX_COLOR_REGISTERS: usize = 1024;
+pub const MAX_COLOR_REGISTERS: usize = 1024;
/// Color register for transparent pixels.
const REG_TRANSPARENT: ColorRegister = ColorRegister(u16::MAX);
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs
index ed14fa2f..3568f79c 100644
--- a/alacritty_terminal/src/term/mod.rs
+++ b/alacritty_terminal/src/term/mod.rs
@@ -983,7 +983,7 @@ impl<T: EventListener> Handler for Term<T> {
match intermediate {
None => {
trace!("Reporting primary device attributes");
- let _ = writer.write_all(b"\x1b[?4;6c");
+ let _ = writer.write_all(b"\x1b[?6c");
},
Some('>') => {
trace!("Reporting secondary device attributes");
@@ -1718,6 +1718,37 @@ impl<T: EventListener> Handler for Term<T> {
let _ = write!(writer, "\x1b[8;{};{}t", self.screen_lines(), self.columns());
}
+ #[inline]
+ fn graphics_attribute<W: io::Write>(&mut self, writer: &mut W, pi: u16, pa: u16) {
+ // From Xterm documentation:
+ //
+ // Pi = 1 -> item is number of color registers.
+ // Pi = 2 -> item is Sixel graphics geometry (in pixels).
+ //
+ // Pa = 1 -> read attribute.
+ // Pa = 4 -> read the maximum allowed value.
+ //
+ // Any other request reports an error.
+
+ let (ps, pv) = if pa == 1 || pa == 4 {
+ match pi {
+ 1 => (0, &[sixel::MAX_COLOR_REGISTERS][..]),
+ 2 => (0, &[MAX_GRAPHIC_DIMENSIONS.0, MAX_GRAPHIC_DIMENSIONS.1][..]),
+ _ => (1, &[][..]), // Report error in Pi
+ }
+ } else {
+ (2, &[][..]) // Report error in Pa
+ };
+
+ let _ = write!(writer, "\x1b[?{};{}", pi, ps);
+
+ for item in pv {
+ let _ = write!(writer, ";{}", item);
+ }
+
+ let _ = write!(writer, "S");
+ }
+
fn start_sixel_graphic(&mut self, params: &Params) -> Option<Box<sixel::Parser>> {
let palette = self.graphics.sixel_shared_palette.take();
Some(Box::new(sixel::Parser::new(params, palette)))
diff --git a/docs/escape_support.md b/docs/escape_support.md
index 5008d6a6..bc951753 100644
--- a/docs/escape_support.md
+++ b/docs/escape_support.md
@@ -71,6 +71,7 @@ brevity.
| `CSI SP q` | IMPLEMENTED | |
| `CSI r` | IMPLEMENTED | |
| `CSI S` | IMPLEMENTED | |
+| `CSI ? S` | PARTIAL | Only for reading attributes. |
| `CSI s` | IMPLEMENTED | |
| `CSI T` | IMPLEMENTED | |
| `CSI t` | PARTIAL | Only parameters `22` and `23` are supported |