Skip to content

Commit 7587eb5

Browse files
authored
fix: reset shell colors based on the input style (#9243)
1 parent 9511462 commit 7587eb5

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

crates/common/src/io/shell.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -411,22 +411,16 @@ impl ShellOut {
411411

412412
/// Write a styled fragment
413413
fn write_stdout(&mut self, fragment: impl fmt::Display, style: &Style) -> Result<()> {
414-
let style = style.render();
415-
let reset = anstyle::Reset.render();
416-
417414
let mut buffer = Vec::new();
418-
write!(buffer, "{style}{fragment}{reset}")?;
415+
write!(buffer, "{style}{fragment}{style:#}")?;
419416
self.stdout().write_all(&buffer)?;
420417
Ok(())
421418
}
422419

423420
/// Write a styled fragment
424421
fn write_stderr(&mut self, fragment: impl fmt::Display, style: &Style) -> Result<()> {
425-
let style = style.render();
426-
let reset = anstyle::Reset.render();
427-
428422
let mut buffer = Vec::new();
429-
write!(buffer, "{style}{fragment}{reset}")?;
423+
write!(buffer, "{style}{fragment}{style:#}")?;
430424
self.stderr().write_all(&buffer)?;
431425
Ok(())
432426
}
@@ -456,19 +450,17 @@ impl ShellOut {
456450
style: &Style,
457451
justified: bool,
458452
) -> Result<Vec<u8>> {
459-
let style = style.render();
460-
let bold = (anstyle::Style::new() | anstyle::Effects::BOLD).render();
461-
let reset = anstyle::Reset.render();
453+
let bold = anstyle::Style::new().bold();
462454

463455
let mut buffer = Vec::new();
464456
if justified {
465-
write!(&mut buffer, "{style}{status:>12}{reset}")?;
457+
write!(buffer, "{style}{status:>12}{style:#}")?;
466458
} else {
467-
write!(&mut buffer, "{style}{status}{reset}{bold}:{reset}")?;
459+
write!(buffer, "{style}{status}{style:#}{bold}:{bold:#}")?;
468460
}
469461
match message {
470462
Some(message) => {
471-
writeln!(&mut buffer, " {message}")?;
463+
writeln!(buffer, " {message}")?;
472464
}
473465
None => write!(buffer, " ")?,
474466
}

0 commit comments

Comments
 (0)