Skip to content

Commit

Permalink
fix: reset shell colors based on the input style (#9243)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Nov 1, 2024
1 parent 9511462 commit 7587eb5
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions crates/common/src/io/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,22 +411,16 @@ impl ShellOut {

/// Write a styled fragment
fn write_stdout(&mut self, fragment: impl fmt::Display, style: &Style) -> Result<()> {
let style = style.render();
let reset = anstyle::Reset.render();

let mut buffer = Vec::new();
write!(buffer, "{style}{fragment}{reset}")?;
write!(buffer, "{style}{fragment}{style:#}")?;
self.stdout().write_all(&buffer)?;
Ok(())
}

/// Write a styled fragment
fn write_stderr(&mut self, fragment: impl fmt::Display, style: &Style) -> Result<()> {
let style = style.render();
let reset = anstyle::Reset.render();

let mut buffer = Vec::new();
write!(buffer, "{style}{fragment}{reset}")?;
write!(buffer, "{style}{fragment}{style:#}")?;
self.stderr().write_all(&buffer)?;
Ok(())
}
Expand Down Expand Up @@ -456,19 +450,17 @@ impl ShellOut {
style: &Style,
justified: bool,
) -> Result<Vec<u8>> {
let style = style.render();
let bold = (anstyle::Style::new() | anstyle::Effects::BOLD).render();
let reset = anstyle::Reset.render();
let bold = anstyle::Style::new().bold();

let mut buffer = Vec::new();
if justified {
write!(&mut buffer, "{style}{status:>12}{reset}")?;
write!(buffer, "{style}{status:>12}{style:#}")?;
} else {
write!(&mut buffer, "{style}{status}{reset}{bold}:{reset}")?;
write!(buffer, "{style}{status}{style:#}{bold}:{bold:#}")?;
}
match message {
Some(message) => {
writeln!(&mut buffer, " {message}")?;
writeln!(buffer, " {message}")?;
}
None => write!(buffer, " ")?,
}
Expand Down

0 comments on commit 7587eb5

Please sign in to comment.