diff --git a/src/formatter.rs b/src/formatter.rs index 2e607335a..ccd6ab145 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -170,8 +170,11 @@ impl Style { pub struct ColorFormatter { output: W, rules: Arc, + /// The stack of currently applied labels. These determine the desired + /// style. labels: Vec, cached_styles: HashMap, Style>, + /// The style we last wrote to the output. current_style: Style, } @@ -191,7 +194,7 @@ impl ColorFormatter { Self::new(output, Arc::new(rules)) } - fn current_style(&mut self) -> Style { + fn requested_style(&mut self) -> Style { if let Some(cached) = self.cached_styles.get(&self.labels) { cached.clone() } else { @@ -231,7 +234,7 @@ impl ColorFormatter { } fn write_new_style(&mut self) -> io::Result<()> { - let new_style = self.current_style(); + let new_style = self.requested_style(); if new_style != self.current_style { if new_style.bold != self.current_style.bold { if new_style.bold.unwrap_or_default() {