Skip to content

Commit

Permalink
refactor(fmt): Use simplified anstyle formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 13, 2024
1 parent 5e0566e commit 8bf7499
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
4 changes: 1 addition & 3 deletions examples/custom_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ fn main() {
// We are reusing `anstyle` but there are `anstyle-*` crates to adapt it to your
// preferred styling crate.
let warn_style = buf.default_level_style(log::Level::Warn);
let reset = warn_style.render_reset();
let warn_style = warn_style.render();
let timestamp = buf.timestamp();

writeln!(
buf,
"My formatted log ({timestamp}): {warn_style}{}{reset}",
"My formatted log ({timestamp}): {warn_style}{}{warn_style:#}",
record.args()
)
})
Expand Down
5 changes: 2 additions & 3 deletions src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,13 @@ struct StyledValue<T> {
#[cfg(feature = "color")]
impl<T: std::fmt::Display> std::fmt::Display for StyledValue<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let style = self.style.render();
let reset = self.style.render_reset();
let style = self.style;

// We need to make sure `f`s settings don't get passed onto the styling but do get passed
// to the value
write!(f, "{style}")?;
self.value.fmt(f)?;
write!(f, "{reset}")?;
write!(f, "{style:#}")?;
Ok(())
}
}
Expand Down

0 comments on commit 8bf7499

Please sign in to comment.