mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 05:07:55 +08:00
always reset colors settings on the output stream after writing (#375)
This is according to: https://docs.rs/termcolor/1.1.2/termcolor/#example-using-standardstream Not resetting the color settings on the stream will leak the style to the shell otherwise. This can be observed when listing mailboxes prior to this patch. Signed-off-by: Robert Günzler <r@gnzler.io> Co-authored-by: Clément DOUIN <soywod@users.noreply.github.com>
This commit is contained in:
@@ -8,12 +8,14 @@ pub trait Print {
|
||||
|
||||
impl Print for &str {
|
||||
fn print(&self, writer: &mut dyn WriteColor) -> Result<()> {
|
||||
writeln!(writer, "{}", self).context("cannot write string to writer")
|
||||
writeln!(writer, "{}", self).context("cannot write string to writer")?;
|
||||
Ok(writer.reset()?)
|
||||
}
|
||||
}
|
||||
|
||||
impl Print for String {
|
||||
fn print(&self, writer: &mut dyn WriteColor) -> Result<()> {
|
||||
self.as_str().print(writer)
|
||||
self.as_str().print(writer)?;
|
||||
Ok(writer.reset()?)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-8
@@ -134,14 +134,8 @@ impl Print for Cell {
|
||||
.context(format!(r#"cannot apply colors to cell "{}""#, self.value))?;
|
||||
|
||||
// Writes the colorized cell to stdout
|
||||
write!(writer, "{}", self.value)
|
||||
.context(format!(r#"cannot print cell "{}""#, self.value))?;
|
||||
|
||||
// Resets color after cell
|
||||
writer
|
||||
.reset()
|
||||
.context(format!(r#"cannot reset color in cell "{}""#, self.value))?;
|
||||
write!(writer, "").context(format!(r#"cannot print cell "{}""#, self.value))
|
||||
write!(writer, "{}", self.value).context(format!(r#"cannot print cell "{}""#, self.value))?;
|
||||
Ok(writer.reset()?)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user