mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-05 17:15:12 +00: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:
parent
4d91a5d74e
commit
5a2d7fa6b5
|
@ -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()?)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()?)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue