termcolor

Trait WriteColor

Source
pub trait WriteColor: Write {
    // Required methods
    fn supports_color(&self) -> bool;
    fn set_color(&mut self, spec: &ColorSpec) -> Result<()>;
    fn reset(&mut self) -> Result<()>;

    // Provided method
    fn is_synchronous(&self) -> bool { ... }
}
Expand description

This trait describes the behavior of writers that support colored output.

Required Methods§

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.

Subsequent writes to this writer will use these settings until either reset is called or new color settings are set.

If there was a problem setting the color settings, then an error is returned.

Source

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

Reset the current color settings to their original settings.

If there was a problem resetting the color settings, then an error is returned.

Provided Methods§

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.

In practice, this should return true if the underlying writer is manipulating colors using the Windows console APIs.

This is useful for writing generic code (such as a buffered writer) that can perform certain optimizations when the underlying writer doesn’t rely on synchronous APIs. For example, ANSI escape sequences can be passed through to the end user’s device as is.

Implementations on Foreign Types§

Source§

impl<'a, T: ?Sized + WriteColor> WriteColor for &'a mut T

Source§

fn supports_color(&self) -> bool

Source§

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

Source§

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

Source§

fn is_synchronous(&self) -> bool

Source§

impl<T: ?Sized + WriteColor> WriteColor for Box<T>

Source§

fn supports_color(&self) -> bool

Source§

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

Source§

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

Source§

fn is_synchronous(&self) -> bool

Implementors§