summaryrefslogtreecommitdiffstats
path: root/alacritty_terminal
diff options
context:
space:
mode:
authorDaftMouse <daftmouse@protonmail.com>2022-01-15 00:35:05 -0300
committerGitHub <noreply@github.com>2022-01-15 03:35:05 +0000
commit60ef17e8e98b0ed219a145881d10ecd6b9f26e85 (patch)
tree3e257a8ad78e9b8eb0a4c54fd909fe1bc7d31b4e /alacritty_terminal
parente38f51c6bd73999e4e36110ca21cdb473de00bd5 (diff)
Add ´?´ support to OSC 4
Diffstat (limited to 'alacritty_terminal')
-rw-r--r--alacritty_terminal/src/ansi.rs49
-rw-r--r--alacritty_terminal/src/term/mod.rs4
2 files changed, 44 insertions, 9 deletions
diff --git a/alacritty_terminal/src/ansi.rs b/alacritty_terminal/src/ansi.rs
index 25ea8af3..869d051b 100644
--- a/alacritty_terminal/src/ansi.rs
+++ b/alacritty_terminal/src/ansi.rs
@@ -972,17 +972,28 @@ where
// Set color index.
b"4" => {
- if params.len() > 1 && params.len() % 2 != 0 {
- for chunk in params[1..].chunks(2) {
- let index = parse_number(chunk[0]);
- let color = xparse_color(chunk[1]);
- if let (Some(i), Some(c)) = (index, color) {
- self.handler.set_color(i as usize, c);
- return;
- }
+ if params.len() <= 1 || params.len() % 2 == 0 {
+ unhandled(params);
+ return;
+ }
+
+ for chunk in params[1..].chunks(2) {
+ let index = match parse_number(chunk[0]) {
+ Some(index) => index,
+ None => {
+ unhandled(params);
+ continue;
+ },
+ };
+
+ if let Some(c) = xparse_color(chunk[1]) {
+ self.handler.set_color(index as usize, c);
+ } else if chunk[1] == b"?" {
+ self.handler.dynamic_color_sequence(index, index as usize, terminator);
+ } else {
+ unhandled(params);
}
}
- unhandled(params);
},
// Get/set Foreground, Background, Cursor colors.
@@ -1494,6 +1505,7 @@ mod tests {
charset: StandardCharset,
attr: Option<Attr>,
identity_reported: bool,
+ color: Option<Rgb>,
}
impl Handler for MockHandler {
@@ -1517,6 +1529,10 @@ mod tests {
fn reset_state(&mut self) {
*self = Self::default();
}
+
+ fn set_color(&mut self, _: usize, c: Rgb) {
+ self.color = Some(c);
+ }
}
impl Default for MockHandler {
@@ -1526,6 +1542,7 @@ mod tests {
charset: StandardCharset::Ascii,
attr: None,
identity_reported: false,
+ color: None,
}
}
}
@@ -1724,4 +1741,18 @@ mod tests {
fn parse_number_too_large() {
assert_eq!(parse_number(b"321"), None);
}
+
+ #[test]
+ fn parse_osc4_set_color() {
+ let bytes: &[u8] = b"\x1b]4;0;#fff\x1b\\";
+
+ let mut parser = Processor::new();
+ let mut handler = MockHandler::default();
+
+ for byte in bytes {
+ parser.advance(&mut handler, *byte);
+ }
+
+ assert_eq!(handler.color, Some(Rgb { r: 0xf0, g: 0xf0, b: 0xf0 }));
+ }
}
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs
index ce939401..2f0989ef 100644
--- a/alacritty_terminal/src/term/mod.rs
+++ b/alacritty_terminal/src/term/mod.rs
@@ -818,6 +818,10 @@ impl<T> Term<T> {
cursor_cell.bg = bg;
cursor_cell.flags = flags;
}
+
+ pub fn colors(&self) -> &Colors {
+ &self.colors
+ }
}
impl<T> Dimensions for Term<T> {