[][src]Trait tcprint::ReportingColors

pub trait ReportingColors {
    fn get_color_for_report(&self, reptype: ReportType) -> &ColorSpec;
}

Specify colors to be used by the tcreport!() macro.

If you are using a custom color palette for your colorized printing, you must implement this trait on your palette structure if you want to use the tcreport!() macro. There is one method to implement, which simply maps between a variant of the ReportType enumeration and a termcolor::ColorSpec reference.

Example

#[macro_use] extern crate tcprint;

use std::default::Default;
use tcprint::{Color, ColorSpec, ColorPrintState, ReportingColors, ReportType};

/// In this app, the only "colorization" we use is that sometimes we underline things.
#[derive(Clone, Debug, Eq, PartialEq)]
struct MyPalette {
    pub ul: ColorSpec,
}

impl Default for MyPalette {
    fn default() -> Self {
        let mut ul = ColorSpec::new();
        ul.set_underline(true);

        MyPalette { ul }
    }
}

// Regardless of the report type, the message prefix ("error:", etc.)
// will be printed with underlining but no special color.
impl ReportingColors for MyPalette {
    fn get_color_for_report(&self, reptype: ReportType) -> &ColorSpec {
        &self.ul
    }
}

fn main() {
    let mut state = ColorPrintState::<MyPalette>::default();
    tcreport!(state, info: "all log reports will be prefixed with underlined text");
}

Required methods

fn get_color_for_report(&self, reptype: ReportType) -> &ColorSpec

Get a termcolor::ColorSpec to be associated with a report message.

This color will be used to print the prefix of the message, which will be something like warning:. The main message itself will be printed with plain colorization.

Loading content...

Implementors

impl ReportingColors for BasicColors[src]

Loading content...