Struct AutoStream
pub struct AutoStream<S: RawStream> { /* private fields */ }
std::io::Write that adapts ANSI escape codes to the underlying Writes capabilities
This includes
- Stripping colors for non-terminals
- Respecting env variables like NO_COLOR or CLICOLOR
- (windows) Falling back to the wincon API where ENABLE_VIRTUAL_TERMINAL_PROCESSING is unsupported
You can customize auto-detection by calling into
anstyle_query
to get a ColorChoice and then calling [AutoStream::new(stream, choice)].
Implementations
impl AutoStream<Stderr>
fn lock(self) -> AutoStream<StderrLock<'static>>Get exclusive access to the
AutoStreamWhy?
- Faster performance when writing in a loop
- Avoid other threads interleaving output with the current thread
impl AutoStream<Stdout>
fn lock(self) -> AutoStream<StdoutLock<'static>>Get exclusive access to the
AutoStreamWhy?
- Faster performance when writing in a loop
- Avoid other threads interleaving output with the current thread
impl<S> AutoStream<S>
where
S: RawStream,
fn new(raw: S, choice: ColorChoice) -> SelfRuntime control over styling behavior
Example
#fn auto(raw: S) -> SelfAuto-adapt for the stream's capabilities
fn choice(raw: &S) -> ColorChoiceReport the desired choice for the given stream
fn always_ansi(raw: S) -> SelfForce ANSI escape codes to be passed through as-is, no matter what the inner
Writesupports.fn always(raw: S) -> SelfForce color, no matter what the inner
Writesupports.fn never(raw: S) -> SelfOnly pass printable data to the inner
Write.fn into_inner(self) -> SGet the wrapped
RawStreamfn as_inner(&self) -> &SGet the wrapped
RawStreamfn is_terminal(&self) -> boolReturns
trueif the descriptor/handle refers to a terminal/tty.fn current_choice(&self) -> ColorChoicePrefer
AutoStream::choiceThis doesn't report what is requested but what is currently active.
Trait Implementations
impl<S> Write for AutoStream<S>
where
S: RawStream + AsLockedWrite,
fn write(&mut self, buf: &[u8]) -> Result<usize>fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize>fn flush(&mut self) -> Result<()>fn write_all(&mut self, buf: &[u8]) -> Result<()>fn write_fmt(&mut self, args: Arguments<'_>) -> Result<()>
impl<S: Debug + RawStream> Debug for AutoStream<S>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl<S> Freeze for AutoStream<S>
where
StreamInner<S>: Freeze,
impl<S> RefUnwindSafe for AutoStream<S>
where
StreamInner<S>: RefUnwindSafe,
impl<S> Send for AutoStream<S>
where
StreamInner<S>: Send,
impl<S> Sync for AutoStream<S>
where
StreamInner<S>: Sync,
impl<S> Unpin for AutoStream<S>
where
StreamInner<S>: Unpin,
impl<S> UnsafeUnpin for AutoStream<S>
where
StreamInner<S>: UnsafeUnpin,
impl<S> UnwindSafe for AutoStream<S>
where
StreamInner<S>: UnwindSafe,
Blanket Implementations
impl<T> Any for AutoStream<S>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for AutoStream<S>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for AutoStream<S>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for AutoStream<S>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into<U> for AutoStream<S>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for AutoStream<S>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for AutoStream<S>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>