diff options
author | Kevin Zheng <kevzheng@umich.edu> | 2019-06-09 13:02:15 -0500 |
---|---|---|
committer | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-06-09 18:02:15 +0000 |
commit | 204c46c7f9469a9d58ccc882afbd057f8675ef11 (patch) | |
tree | cfea8ffc5e096fcd32718e6dd75d376d6ca0da9c /alacritty_terminal/src/ansi.rs | |
parent | f59aa19892724f41e3a56817fb69e95413312920 (diff) | |
download | alacritty-204c46c7f9469a9d58ccc882afbd057f8675ef11.tar.gz alacritty-204c46c7f9469a9d58ccc882afbd057f8675ef11.zip |
Fix dynamic multi-color escape codes
Diffstat (limited to 'alacritty_terminal/src/ansi.rs')
-rw-r--r-- | alacritty_terminal/src/ansi.rs | 65 |
1 files changed, 24 insertions, 41 deletions
diff --git a/alacritty_terminal/src/ansi.rs b/alacritty_terminal/src/ansi.rs index bff59de5..27c07a57 100644 --- a/alacritty_terminal/src/ansi.rs +++ b/alacritty_terminal/src/ansi.rs @@ -537,10 +537,10 @@ pub enum NamedColor { Foreground = 256, /// The background color Background, - /// Color for the text under the cursor - CursorText, /// Color for the cursor itself Cursor, + /// Color for the text under the cursor + CursorText, /// Dim black DimBlack, /// Dim red @@ -793,47 +793,30 @@ where unhandled(params); }, - // Get/set foreground color - b"10" => { - if params.len() >= 2 { - if let Some(color) = parse_rgb_color(params[1]) { - self.handler.set_color(NamedColor::Foreground as usize, color); - return; - } else if params[1] == b"?" { - self.handler.dynamic_color_sequence( - writer, - 10, - NamedColor::Foreground as usize, - ); - return; - } - } - unhandled(params); - }, - - // Get/set background color - b"11" => { + // Get/set Foreground, Background, Cursor colors + b"10" | b"11" | b"12" => { if params.len() >= 2 { - if let Some(color) = parse_rgb_color(params[1]) { - self.handler.set_color(NamedColor::Background as usize, color); - return; - } else if params[1] == b"?" { - self.handler.dynamic_color_sequence( - writer, - 11, - NamedColor::Background as usize, - ); - return; - } - } - unhandled(params); - }, + if let Some(mut dynamic_code) = parse_number(params[0]) { + for param in ¶ms[1..] { + // 10 is the first dynamic color, also the foreground + let offset = dynamic_code as usize - 10; + let index = NamedColor::Foreground as usize + offset; + + // End of setting dynamic colors + if index > NamedColor::Cursor as usize { + unhandled(params); + break; + } - // Set text cursor color - b"12" => { - if params.len() >= 2 { - if let Some(color) = parse_rgb_color(params[1]) { - self.handler.set_color(NamedColor::Cursor as usize, color); + if let Some(color) = parse_rgb_color(param) { + self.handler.set_color(index, color); + } else if param == b"?" { + self.handler.dynamic_color_sequence(writer, dynamic_code, index); + } else { + unhandled(params); + } + dynamic_code += 1; + } return; } } |