Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 55 additions & 6 deletions crates/anstyle-svg/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ impl anstyle_parse::Perform for AnsiCapture {
style = style.underline();
state = CsiState::Underline;
}
(CsiState::Normal, 21) => {
style |= anstyle::Effects::DOUBLE_UNDERLINE;
break;
}
(CsiState::Normal, 7) => {
style = style.invert();
break;
Expand All @@ -154,6 +150,48 @@ impl anstyle_parse::Perform for AnsiCapture {
style = style.strikethrough();
break;
}
(CsiState::Normal, 21) => {
style |= anstyle::Effects::DOUBLE_UNDERLINE;
break;
}
(CsiState::Normal, 22) => {
style = style.effects(
style
.get_effects()
.remove(anstyle::Effects::BOLD)
.remove(anstyle::Effects::DIMMED),
);
break;
}
(CsiState::Normal, 23) => {
style = style.effects(style.get_effects().remove(anstyle::Effects::ITALIC));
break;
}
(CsiState::Normal, 24) => {
style = style.effects(
style
.get_effects()
.remove(anstyle::Effects::UNDERLINE)
.remove(anstyle::Effects::DOUBLE_UNDERLINE)
.remove(anstyle::Effects::CURLY_UNDERLINE)
.remove(anstyle::Effects::DOTTED_UNDERLINE)
.remove(anstyle::Effects::DASHED_UNDERLINE),
);
break;
}
(CsiState::Normal, 27) => {
style = style.effects(style.get_effects().remove(anstyle::Effects::INVERT));
break;
}
(CsiState::Normal, 28) => {
style = style.effects(style.get_effects().remove(anstyle::Effects::HIDDEN));
break;
}
(CsiState::Normal, 29) => {
style = style
.effects(style.get_effects().remove(anstyle::Effects::STRIKETHROUGH));
break;
}
(CsiState::Normal, 30..=37) => {
let color = to_ansi_color(value - 30).expect("within 4-bit range");
style = style.fg_color(Some(color.into()));
Expand Down Expand Up @@ -184,6 +222,10 @@ impl anstyle_parse::Perform for AnsiCapture {
color_target = ColorTarget::Underline;
state = CsiState::PrepareCustomColor;
}
(CsiState::Normal, 59) => {
style = style.underline_color(None);
break;
}
(CsiState::Normal, 90..=97) => {
let color = to_ansi_color(value - 90)
.expect("within 4-bit range")
Expand Down Expand Up @@ -233,8 +275,15 @@ impl anstyle_parse::Perform for AnsiCapture {
}
},
(CsiState::Underline, 0) => {
style =
style.effects(style.get_effects().remove(anstyle::Effects::UNDERLINE));
style = style.effects(
style
.get_effects()
.remove(anstyle::Effects::UNDERLINE)
.remove(anstyle::Effects::DOUBLE_UNDERLINE)
.remove(anstyle::Effects::CURLY_UNDERLINE)
.remove(anstyle::Effects::DOTTED_UNDERLINE)
.remove(anstyle::Effects::DASHED_UNDERLINE),
);
}
(CsiState::Underline, 1) => {
// underline already set
Expand Down
45 changes: 45 additions & 0 deletions crates/anstyle-svg/tests/sgr_off_codes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<style>
.fg { color: #AAAAAA }
.bg { background: #000000 }
.bg-white { background: #AAAAAA; user-select: none; }
.fg-black { color: #000000 }
.container {
line-height: 18px;
}
.bold { font-weight: bold; }
.italic { font-style: italic; }
.underline { text-decoration-line: underline; }
.strikethrough { text-decoration-line: line-through; }
.dimmed { opacity: 0.4; }
.hidden { opacity: 0; }
span {
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
white-space: pre;
line-height: 18px;
}
</style>
</head>

<body class="bg">

<div class="container fg">
<span class="bold">bold</span><span> normal</span><br />
<span class="dimmed">dim</span><span> normal</span><br />
<span class="italic">italic</span><span> normal</span><br />
<span class="underline">underline</span><span> normal</span><br />
<span class="bg-white">██████</span><span> </span><br />
<span class="fg-black">invert</span><span> normal</span><br />
<span class="hidden">hidden</span><span> normal</span><br />
<span class="strikethrough">strikethrough</span><span> normal</span><br />
<span class="underline bold italic">all three</span><span class="underline italic"> no bold</span><span class="underline"> no italic</span><span> plain</span><br />
<br />
</div>

</body>
</html>
49 changes: 49 additions & 0 deletions crates/anstyle-svg/tests/sgr_off_codes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions crates/anstyle-svg/tests/sgr_off_codes.vte
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bold normal
dim normal
italic normal
underline normal
invert normal
hidden normal
strikethrough normal
all three no bold no italic plain
54 changes: 54 additions & 0 deletions crates/anstyle-svg/tests/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,57 @@ fn custom_background_color_html() {
snapbox::file!["custom_background_color.html": Text].raw()
);
}

#[test]
fn sgr_off_codes() {
let input = std::fs::read_to_string("tests/sgr_off_codes.vte").unwrap();
let actual = anstyle_svg::Term::new().render_svg(&input);
snapbox::assert_data_eq!(actual, snapbox::file!["sgr_off_codes.svg": Text].raw());
}

#[test]
fn sgr_off_codes_html() {
let input = std::fs::read_to_string("tests/sgr_off_codes.vte").unwrap();
let actual = anstyle_svg::Term::new().render_html(&input);
snapbox::assert_data_eq!(actual, snapbox::file!["sgr_off_codes.html": Text].raw());
}

#[test]
fn underline_subparams() {
let input = std::fs::read_to_string("tests/underline_subparams.vte").unwrap();
let actual = anstyle_svg::Term::new().render_svg(&input);
snapbox::assert_data_eq!(
actual,
snapbox::file!["underline_subparams.svg": Text].raw()
);
}

#[test]
fn underline_subparams_html() {
let input = std::fs::read_to_string("tests/underline_subparams.vte").unwrap();
let actual = anstyle_svg::Term::new().render_html(&input);
snapbox::assert_data_eq!(
actual,
snapbox::file!["underline_subparams.html": Text].raw()
);
}

#[test]
fn underline_color_reset() {
let input = std::fs::read_to_string("tests/underline_color_reset.vte").unwrap();
let actual = anstyle_svg::Term::new().render_svg(&input);
snapbox::assert_data_eq!(
actual,
snapbox::file!["underline_color_reset.svg": Text].raw()
);
}

#[test]
fn underline_color_reset_html() {
let input = std::fs::read_to_string("tests/underline_color_reset.vte").unwrap();
let actual = anstyle_svg::Term::new().render_html(&input);
snapbox::assert_data_eq!(
actual,
snapbox::file!["underline_color_reset.html": Text].raw()
);
}
35 changes: 35 additions & 0 deletions crates/anstyle-svg/tests/underline_color_reset.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<style>
.fg { color: #AAAAAA }
.bg { background: #000000 }
.underline-ansi256-202 { text-decoration-line: underline; text-decoration-color: #FF5F00 }
.underline-rgb-0080FF { text-decoration-line: underline; text-decoration-color: #0080FF }
.underline-rgb-FF0000 { text-decoration-line: underline; text-decoration-color: #FF0000 }
.container {
line-height: 18px;
}
.underline { text-decoration-line: underline; }
span {
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
white-space: pre;
line-height: 18px;
}
</style>
</head>

<body class="bg">

<div class="container fg">
<span class="underline-rgb-FF0000 underline">red underline</span><span class="underline"> default color underline</span><span> normal</span><br />
<span class="underline-ansi256-202 underline">orange underline</span><span class="underline"> default color underline</span><span> normal</span><br />
<span class="underline-rgb-0080FF underline">blue underline</span><span class="underline"> default color underline</span><span> normal</span><br />
<br />
</div>

</body>
</html>
33 changes: 33 additions & 0 deletions crates/anstyle-svg/tests/underline_color_reset.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions crates/anstyle-svg/tests/underline_color_reset.vte
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
red underline default color underline normal
orange underline default color underline normal
[58:2:0:128:255mblue underline default color underline normal
38 changes: 38 additions & 0 deletions crates/anstyle-svg/tests/underline_subparams.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<style>
.fg { color: #AAAAAA }
.bg { background: #000000 }
.container {
line-height: 18px;
}
.underline { text-decoration-line: underline; }
.double-underline { text-decoration-line: underline; text-decoration-style: double; }
.curly-underline { text-decoration-line: underline; text-decoration-style: wavy; }
.dotted-underline { text-decoration-line: underline; text-decoration-style: dotted; }
.dashed-underline { text-decoration-line: underline; text-decoration-style: dashed; }
span {
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
white-space: pre;
line-height: 18px;
}
</style>
</head>

<body class="bg">

<div class="container fg">
<span class="underline">underline</span><span> normal</span><br />
<span class="double-underline">double</span><span> normal</span><br />
<span class="curly-underline">curly</span><span> normal</span><br />
<span class="dotted-underline">dotted</span><span> normal</span><br />
<span class="dashed-underline">dashed</span><span> normal</span><br />
<br />
</div>

</body>
</html>
Loading
Loading