aboutsummaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/ansi.rs
diff options
context:
space:
mode:
Diffstat (limited to 'alacritty_terminal/src/ansi.rs')
-rw-r--r--alacritty_terminal/src/ansi.rs36
1 files changed, 22 insertions, 14 deletions
diff --git a/alacritty_terminal/src/ansi.rs b/alacritty_terminal/src/ansi.rs
index 8475685d..c5ddb3bf 100644
--- a/alacritty_terminal/src/ansi.rs
+++ b/alacritty_terminal/src/ansi.rs
@@ -806,6 +806,8 @@ pub enum Attr {
Foreground(Color),
/// Set indexed background color.
Background(Color),
+ /// Underline color.
+ UnderlineColor(Option<Color>),
}
/// Identifiers which can be assigned to a graphic character set.
@@ -1364,13 +1366,7 @@ fn attrs_from_sgr_parameters(params: &mut ParamsIter<'_>) -> Vec<Option<Attr>> {
let mut iter = params.map(|param| param[0]);
parse_sgr_color(&mut iter).map(Attr::Foreground)
},
- [38, params @ ..] => {
- let rgb_start = if params.len() > 4 { 2 } else { 1 };
- let rgb_iter = params[rgb_start..].iter().copied();
- let mut iter = iter::once(params[0]).chain(rgb_iter);
-
- parse_sgr_color(&mut iter).map(Attr::Foreground)
- },
+ [38, params @ ..] => handle_colon_rgb(params).map(Attr::Foreground),
[39] => Some(Attr::Foreground(Color::Named(NamedColor::Foreground))),
[40] => Some(Attr::Background(Color::Named(NamedColor::Black))),
[41] => Some(Attr::Background(Color::Named(NamedColor::Red))),
@@ -1384,14 +1380,16 @@ fn attrs_from_sgr_parameters(params: &mut ParamsIter<'_>) -> Vec<Option<Attr>> {
let mut iter = params.map(|param| param[0]);
parse_sgr_color(&mut iter).map(Attr::Background)
},
- [48, params @ ..] => {
- let rgb_start = if params.len() > 4 { 2 } else { 1 };
- let rgb_iter = params[rgb_start..].iter().copied();
- let mut iter = iter::once(params[0]).chain(rgb_iter);
-
- parse_sgr_color(&mut iter).map(Attr::Background)
- },
+ [48, params @ ..] => handle_colon_rgb(params).map(Attr::Background),
[49] => Some(Attr::Background(Color::Named(NamedColor::Background))),
+ [58] => {
+ let mut iter = params.map(|param| param[0]);
+ parse_sgr_color(&mut iter).map(|color| Attr::UnderlineColor(Some(color)))
+ },
+ [58, params @ ..] => {
+ handle_colon_rgb(params).map(|color| Attr::UnderlineColor(Some(color)))
+ },
+ [59] => Some(Attr::UnderlineColor(None)),
[90] => Some(Attr::Foreground(Color::Named(NamedColor::BrightBlack))),
[91] => Some(Attr::Foreground(Color::Named(NamedColor::BrightRed))),
[92] => Some(Attr::Foreground(Color::Named(NamedColor::BrightGreen))),
@@ -1416,6 +1414,16 @@ fn attrs_from_sgr_parameters(params: &mut ParamsIter<'_>) -> Vec<Option<Attr>> {
attrs
}
+/// Handle colon separated rgb color escape sequence.
+#[inline]
+fn handle_colon_rgb(params: &[u16]) -> Option<Color> {
+ let rgb_start = if params.len() > 4 { 2 } else { 1 };
+ let rgb_iter = params[rgb_start..].iter().copied();
+ let mut iter = iter::once(params[0]).chain(rgb_iter);
+
+ parse_sgr_color(&mut iter)
+}
+
/// Parse a color specifier from list of attributes.
fn parse_sgr_color(params: &mut dyn Iterator<Item = u16>) -> Option<Color> {
match params.next() {