diff options
| author | kumattau <kumattau@gmail.com> | 2022-10-21 03:09:54 +0900 |
|---|---|---|
| committer | kumattau <kumattau@gmail.com> | 2022-10-21 03:09:54 +0900 |
| commit | 615e72ed9763a695737419ff93e81574d30fd41c (patch) | |
| tree | 48648a027cfb7d8ba2560858f118563d0ae46d90 | |
| parent | a9335fcb11d1fd9fd4d5c31468e27e0a531fd140 (diff) | |
| download | r-alacritty-615e72ed9763a695737419ff93e81574d30fd41c.tar.gz r-alacritty-615e72ed9763a695737419ff93e81574d30fd41c.tar.bz2 r-alacritty-615e72ed9763a695737419ff93e81574d30fd41c.zip | |
CSI XTSMGRAPHICS Pi=2, Pa=1 should return dimensions that fit in text area
| -rw-r--r-- | alacritty_terminal/src/term/mod.rs | 83 |
1 files changed, 66 insertions, 17 deletions
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index a35fade2..8461d256 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -1998,32 +1998,81 @@ impl<T: EventListener> Handler for Term<T> { fn graphics_attribute(&mut self, pi: u16, pa: u16) { // From Xterm documentation: // + // CSI ? Pi ; Pa ; Pv S + // // Pi = 1 -> item is number of color registers. // Pi = 2 -> item is Sixel graphics geometry (in pixels). + // Pi = 3 -> item is ReGIS graphics geometry (in pixels). // // Pa = 1 -> read attribute. + // Pa = 2 -> reset to default. + // Pa = 3 -> set to value in Pv. // Pa = 4 -> read the maximum allowed value. // - // Any other request reports an error. + // Pv is ignored by xterm except when setting (Pa == 3). + // Pv = n <- A single integer is used for color registers. + // Pv = width ; height <- Two integers for graphics geometry. + // + // xterm replies with a control sequence of the same form: + // + // CSI ? Pi ; Ps ; Pv S + // + // where Ps is the status: + // Ps = 0 <- success. + // Ps = 1 <- error in Pi. + // Ps = 2 <- error in Pa. + // Ps = 3 <- failure. + // + // On success, Pv represents the value read or set. - let (ps, pv) = if pa == 1 || pa == 4 { - match pi { - 1 => (0, &[sixel::MAX_COLOR_REGISTERS][..]), - 2 => (0, &MAX_GRAPHIC_DIMENSIONS[..]), - _ => (1, &[][..]), // Report error in Pi + fn generate_response(pi: u16, ps: u16, pv: &[usize]) -> String { + let mut text = format!("\x1b[?{};{}", pi, ps); + for item in pv { + let _ = write!(&mut text, ";{}", item); + } + text.push('S'); + text + } + + let (ps, pv) = match pi { + 1 => { + match pa { + 1 => (0, &[sixel::MAX_COLOR_REGISTERS][..]), // current value is always the maximum + 2 => (3, &[][..]), // Report unsupported + 3 => (3, &[][..]), // Report unsupported + 4 => (0, &[sixel::MAX_COLOR_REGISTERS][..]), + _ => (2, &[][..]), // Report error in Pa + } + } + 2 => { + match pa { + 1 => { + self.event_proxy.send_event(Event::TextAreaSizeRequest(Arc::new(move |window_size| { + let width = window_size.num_cols * window_size.cell_width; + let height = window_size.num_lines * window_size.cell_height; + let graphic_dimensions = [ + cmp::min(width as usize, MAX_GRAPHIC_DIMENSIONS[0]), + cmp::min(height as usize, MAX_GRAPHIC_DIMENSIONS[1])]; + + let (ps, pv) = (0, &graphic_dimensions[..]); + generate_response(pi, ps, pv) + }))); + return; + } + 2 => (3, &[][..]), // Report unsupported + 3 => (3, &[][..]), // Report unsupported + 4 => (0, &MAX_GRAPHIC_DIMENSIONS[..]), + _ => (2, &[][..]), // Report error in Pa + } + } + 3 => { + (1, &[][..]) // Report error in Pi (ReGIS unknown) + } + _ => { + (1, &[][..]) // Report error in Pi } - } else { - (2, &[][..]) // Report error in Pa }; - - let mut text = format!("\x1b[?{};{}", pi, ps); - - for item in pv { - let _ = write!(&mut text, ";{}", item); - } - - text.push('S'); - self.event_proxy.send_event(Event::PtyWrite(text)); + self.event_proxy.send_event(Event::PtyWrite(generate_response(pi, ps, pv))); } fn start_sixel_graphic(&mut self, params: &Params) -> Option<Box<sixel::Parser>> { |