pub struct Escaped<W: Write> { /* private fields */ }Expand description
A writer that shows control bytes as text — \x1b rather than a real ESC —
so the terminal displays them instead of acting on them.
It sits between the printers and their termcolor::Buffer. trg’s own
colours never pass through write: termcolor emits them from set_color
and reset, which are delegated untouched, so they keep working while every
byte that came out of a log or a member name is neutralised.
Escaped: C0 controls except tab and newline, DEL, and the UTF-8 encoded C1 controls U+0080..U+009F (U+009B is a CSI on terminals that honour C1). A carriage return is kept when it is half of a CRLF line ending — escaping it would litter every line of a Windows log — and escaped on its own, where it moves the cursor back over the line and can hide what came before it.
Both of the two-byte decisions (CR then LF, C2 then a C1 byte) can straddle two writes, so the first byte is held back until the next one arrives. A held byte survives a colour change — grep-printer resets colour between a match ending in CR and its LF — and is settled on flush and on drop.
Escaped::json renders the same bytes as JSON escapes (\u007f), because
the JSON printer’s output is already-encoded JSON: serde escapes C0 itself
but leaves DEL and C1 raw inside strings, and those are the only places
such bytes can appear.
A literal \x1b already in a log prints the same as an escaped ESC. That
ambiguity is accepted: backslashes are not escaped, so Windows paths and
regexes in logs stay readable.
Implementations§
Trait Implementations§
Source§impl<W: Write> Write for Escaped<W>
impl<W: Write> Write for Escaped<W>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Source§impl<W: WriteColor> WriteColor for Escaped<W>
impl<W: WriteColor> WriteColor for Escaped<W>
Source§fn supports_color(&self) -> bool
fn supports_color(&self) -> bool
Source§fn set_color(&mut self, spec: &ColorSpec) -> Result<()>
fn set_color(&mut self, spec: &ColorSpec) -> Result<()>
Source§fn reset(&mut self) -> Result<()>
fn reset(&mut self) -> Result<()>
Source§fn is_synchronous(&self) -> bool
fn is_synchronous(&self) -> bool
false. Read more