Skip to content

Commit

Permalink
Merge pull request #150 from epage/wincon
Browse files Browse the repository at this point in the history
fix(stream): Adapt Ansi256 colors for Wincon
  • Loading branch information
epage authored Dec 8, 2023
2 parents 953b2fc + 28e5a96 commit 00e5945
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions crates/anstream/src/adapter/wincon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ impl anstyle_parse::Perform for WinconCapture {
}

let mut style = self.style;
// param/value differences are dependent on the escape code
let mut state = State::Normal;
let mut r = None;
let mut g = None;
let mut is_bg = false;
for param in params {
let mut state = State::Normal;
let mut r = None;
let mut g = None;
let mut is_bg = false;
for value in param {
match (state, *value) {
(State::Normal, 0) => {
Expand Down Expand Up @@ -244,7 +245,7 @@ mod test {
.collect::<Vec<_>>();
let mut state = WinconBytes::new();
let actual = state.extract_next(input.as_bytes()).collect::<Vec<_>>();
assert_eq!(expected, actual);
assert_eq!(expected, actual, "{input:?}");
}

#[test]
Expand Down Expand Up @@ -287,6 +288,21 @@ mod test {
verify(&input, expected);
}

#[test]
fn ansi256_colors() {
// termcolor only supports "brights" via these
let input = format!(
"Hello {}!",
"world".color(owo_colors::XtermColors::UserBrightYellow)
);
let expected = vec![
(anstyle::Style::default(), "Hello "),
(anstyle::Ansi256Color(11).on_default(), "world"),
(anstyle::Style::default(), "!"),
];
verify(&input, expected);
}

proptest! {
#[test]
#[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253
Expand Down

0 comments on commit 00e5945

Please sign in to comment.