| --- a/Android.bp 2023-11-07 14:29:55.304929829 +0100 |
| +++ b/Android.bp 2023-11-07 14:30:05.916987569 +0100 |
| @@ -16,7 +16,7 @@ |
| "regex", |
| ], |
| rustlibs: [ |
| - "libanstyle", |
| + "libtermcolor", |
| "libitertools", |
| "libpredicates_core", |
| "libregex", |
| @@ -47,7 +47,7 @@ |
| "regex", |
| ], |
| rustlibs: [ |
| - "libanstyle", |
| + "libtermcolor", |
| "libitertools", |
| "libpredicates_core", |
| "libpredicates_tree", |
| --- a/src/color.rs 2006-07-24 03:21:28.000000000 +0200 |
| +++ b/src/color.rs 2023-11-07 14:26:51.131915579 +0100 |
| @@ -1,17 +1,29 @@ |
| -#[derive(Copy, Clone, Debug, Default)] |
| +use std::io::Write; |
| +use termcolor::{Color, ColorSpec, WriteColor}; |
| + |
| +#[derive(Clone, Debug, Default)] |
| pub(crate) struct Palette { |
| - description: anstyle::Style, |
| - var: anstyle::Style, |
| - expected: anstyle::Style, |
| + description: ColorSpec, |
| + var: ColorSpec, |
| + expected: ColorSpec, |
| } |
| |
| impl Palette { |
| pub(crate) fn new(alternate: bool) -> Self { |
| if alternate && cfg!(feature = "color") { |
| Self { |
| - description: anstyle::AnsiColor::Blue.on_default() | anstyle::Effects::BOLD, |
| - var: anstyle::AnsiColor::Red.on_default() | anstyle::Effects::BOLD, |
| - expected: anstyle::AnsiColor::Green.on_default() | anstyle::Effects::BOLD, |
| + description: ColorSpec::new() |
| + .set_fg(Some(Color::Blue)) |
| + .set_bold(true) |
| + .clone(), |
| + var: ColorSpec::new() |
| + .set_fg(Some(Color::Red)) |
| + .set_bold(true) |
| + .clone(), |
| + expected: ColorSpec::new() |
| + .set_fg(Some(Color::Green)) |
| + .set_bold(true) |
| + .clone(), |
| } |
| } else { |
| Self::plain() |
| @@ -26,27 +38,27 @@ |
| } |
| } |
| |
| - pub(crate) fn description<D: std::fmt::Display>(self, display: D) -> Styled<D> { |
| - Styled::new(display, self.description) |
| + pub(crate) fn description<D: std::fmt::Display>(&self, display: D) -> Styled<D> { |
| + Styled::new(display, self.description.clone()) |
| } |
| |
| - pub(crate) fn var<D: std::fmt::Display>(self, display: D) -> Styled<D> { |
| - Styled::new(display, self.var) |
| + pub(crate) fn var<D: std::fmt::Display>(&self, display: D) -> Styled<D> { |
| + Styled::new(display, self.var.clone()) |
| } |
| |
| - pub(crate) fn expected<D: std::fmt::Display>(self, display: D) -> Styled<D> { |
| - Styled::new(display, self.expected) |
| + pub(crate) fn expected<D: std::fmt::Display>(&self, display: D) -> Styled<D> { |
| + Styled::new(display, self.expected.clone()) |
| } |
| } |
| |
| #[derive(Debug)] |
| pub(crate) struct Styled<D> { |
| display: D, |
| - style: anstyle::Style, |
| + style: ColorSpec, |
| } |
| |
| impl<D: std::fmt::Display> Styled<D> { |
| - pub(crate) fn new(display: D, style: anstyle::Style) -> Self { |
| + pub(crate) fn new(display: D, style: ColorSpec) -> Self { |
| Self { display, style } |
| } |
| } |
| @@ -55,10 +67,11 @@ |
| #[inline] |
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| if f.alternate() { |
| - write!(f, "{}", self.style.render())?; |
| - self.display.fmt(f)?; |
| - write!(f, "{}", self.style.render_reset())?; |
| - Ok(()) |
| + let mut buf = termcolor::Buffer::ansi(); |
| + buf.set_color(&self.style).unwrap(); |
| + write!(&mut buf, "{}", &self.display).unwrap(); |
| + buf.reset().unwrap(); |
| + write!(f, "{}", String::from_utf8(buf.into_inner()).unwrap()) |
| } else { |
| self.display.fmt(f) |
| } |