[][src]Struct tcprint::ColorPrintState

pub struct ColorPrintState<C> { /* fields omitted */ }

State for colorized printing.

This structure holds the state needed for colorized printing, namely:

  1. Handles to colorized versions of the standard output and error streams
  2. A palette of colors to use when printing

Your app should generally create one of these structures early upon startup, and then pass references to it to all modules that need to print to the terminal. Those modules should then use tcprintln!(), tcreport!(), and related macros to print colorized output to the terminal.

The type parameter C should be a structure containing public fields of type termcolor::ColorSpec. These will be accessed inside the macros to simplify the creation of colorized output. The structure BasicColors provided by this crate is a simple default that aims to suffice for most purposes. If you want to use tcreport!(), the type C must implement the ReportingColors trait.

Example

#[macro_use] extern crate tcprint;

use tcprint::{BasicColors, ColorPrintState};

let mut state = ColorPrintState::<BasicColors>::default();
tcreport!(state, warning: "rogue needs food, badly!");

See the crate-level documentation for an example of how to use this structure with a custom color palette.

Technical Note

The design of this type was the best solution I could come up with for figuring out how to centralize the colored-printing state in a single value, while preserving extensibility and avoiding problems with the borrow-checker. You could imagine using an enumeration of possible colors instead of having the palette type C with public fields, but the only way I could see to get that to work would require some heavyweight macros.

Implementations

impl<C> ColorPrintState<C>[src]

pub fn new(colors: C) -> Self[src]

Initialize colorized printing state.

It is generally preferable to have your color palette type C implement Default, and then just create an instance of this type using Default::default().

pub fn flush(&mut self) -> Result<()>[src]

Flush the output streams.

This method flushes standard output and error.

Trait Implementations

impl<C: Default> Default for ColorPrintState<C>[src]

Auto Trait Implementations

impl<C> RefUnwindSafe for ColorPrintState<C> where
    C: RefUnwindSafe

impl<C> Send for ColorPrintState<C> where
    C: Send

impl<C> Sync for ColorPrintState<C> where
    C: Sync

impl<C> Unpin for ColorPrintState<C> where
    C: Unpin

impl<C> UnwindSafe for ColorPrintState<C> where
    C: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.