From 6e57df3afe4d2360dac5ac25d52a2339c938e9d3 Mon Sep 17 00:00:00 2001 From: Manu Thambi Date: Fri, 9 Aug 2019 12:35:15 -0400 Subject: [PATCH 1/2] Bugfix: In the Display implementation of Infix, after a reset, use the correct target style. --- src/ansi.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ansi.rs b/src/ansi.rs index d2f54b3..7d200f0 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -293,7 +293,7 @@ impl fmt::Display for Infix { }, Difference::Reset => { let f: &mut fmt::Write = f; - write!(f, "{}{}", RESET, self.0.prefix()) + write!(f, "{}{}", RESET, self.1.prefix()) }, Difference::NoDifference => { Ok(()) // nothing to write @@ -363,4 +363,12 @@ mod test { test!(hidden: Style::new().hidden(); "hi" => "\x1B[8mhi\x1B[0m"); test!(stricken: Style::new().strikethrough(); "hi" => "\x1B[9mhi\x1B[0m"); + #[test] + fn test_infix() { + assert_eq!(Style::new().dimmed().infix(Style::new()).to_string(), "\x1B[0m"); + assert_eq!(White.dimmed().infix(White.normal()).to_string(), "\x1B[0m\x1B[37m"); + assert_eq!(White.normal().infix(White.bold()).to_string(), "\x1B[1m"); + assert_eq!(White.normal().infix(Blue.normal()).to_string(), "\x1B[34m"); + assert_eq!(Blue.bold().infix(Blue.bold()).to_string(), ""); + } } From 0cbe910015b3762f03adf77bee17514157f332d6 Mon Sep 17 00:00:00 2001 From: Manu Thambi Date: Fri, 9 Aug 2019 12:52:10 -0400 Subject: [PATCH 2/2] Updated the documentation for Style::infix() and Colour::infix() to make clear which is the current style/colour and which is the next one. --- src/ansi.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ansi.rs b/src/ansi.rs index 7d200f0..aaf2152 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -167,9 +167,9 @@ impl Style { Prefix(self) } - /// The infix bytes between this style and another. These are the bytes - /// that tell the terminal to either use a different colour or font style - /// _or_ to reset entirely, depending on the two styles. + /// The infix bytes between this style and `next` style. These are the bytes + /// that tell the terminal to change the style to `next`. These may include + /// a reset followed by the next colour and style, depending on the two styles. /// /// # Examples /// @@ -188,8 +188,8 @@ impl Style { /// assert_eq!("", /// style.infix(style).to_string()); /// ``` - pub fn infix(self, other: Style) -> Infix { - Infix(self, other) + pub fn infix(self, next: Style) -> Infix { + Infix(self, next) } /// The suffix for this style. These are the bytes that tell the terminal @@ -237,8 +237,8 @@ impl Colour { Prefix(self.normal()) } - /// The infix bytes between this style and another. These are the bytes - /// that tell the terminal to use the second colour, or to do nothing if + /// The infix bytes between this colour and `next` colour. These are the bytes + /// that tell the terminal to use the `next` colour, or to do nothing if /// the two colours are equal. /// /// See also [`Style::infix`](struct.Style.html#method.infix). @@ -251,8 +251,8 @@ impl Colour { /// assert_eq!("\x1b[33m", /// Red.infix(Yellow).to_string()); /// ``` - pub fn infix(self, other: Colour) -> Infix { - Infix(self.normal(), other.normal()) + pub fn infix(self, next: Colour) -> Infix { + Infix(self.normal(), next.normal()) } /// The suffix for this colour as a `Style`. These are the bytes that