Skip to main content

Escaped

Struct Escaped 

Source
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§

Source§

impl<W: Write> Escaped<W>

Source

pub fn new(inner: W, on: bool) -> Self

Source

pub fn into_json(self) -> Self

Switch an unused writer to JSON escapes.

Source

pub fn json(inner: W, on: bool) -> Self

Trait Implementations§

Source§

impl<W: Write> Drop for Escaped<W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<W: Write> Write for Escaped<W>

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Writes a buffer into this writer, returning how many bytes were written. Read more
Source§

fn flush(&mut self) -> Result<()>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more
Source§

impl<W: WriteColor> WriteColor for Escaped<W>

Source§

fn supports_color(&self) -> bool

Returns true if and only if the underlying writer supports colors.
Source§

fn set_color(&mut self, spec: &ColorSpec) -> Result<()>

Set the color settings of the writer. Read more
Source§

fn reset(&mut self) -> Result<()>

Reset the current color settings to their original settings. Read more
Source§

fn is_synchronous(&self) -> bool

Returns true if and only if the underlying writer must synchronously interact with an end user’s device in order to control colors. By default, this always returns false. Read more
Set the current hyperlink of the writer. Read more
Returns true if and only if the underlying writer supports hyperlinks. Read more

Auto Trait Implementations§

§

impl<W> Freeze for Escaped<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for Escaped<W>
where W: RefUnwindSafe,

§

impl<W> Send for Escaped<W>
where W: Send,

§

impl<W> Sync for Escaped<W>
where W: Sync,

§

impl<W> Unpin for Escaped<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for Escaped<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for Escaped<W>
where W: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.