[−][src]Struct grep_printer::UserColorSpec
A single color specification provided by the user.
Format
The format of a Spec is a triple: {type}:{attribute}:{value}. Each
component is defined as follows:
{type}can be one ofpath,line,columnormatch.{attribute}can be one offg,bgorstyle.{attribute}may also be the special valuenone, in which case,{value}can be omitted.{value}is either a color name (forfg/bg) or a style instruction.
{type} controls which part of the output should be styled.
When {attribute} is none, then this should cause any existing style
settings to be cleared for the specified type.
{value} should be a color when {attribute} is fg or bg, or it
should be a style instruction when {attribute} is style. When
{attribute} is none, {value} must be omitted.
Valid colors are black, blue, green, red, cyan, magenta,
yellow, white. Extended colors can also be specified, and are formatted
as x (for 256-bit colors) or x,x,x (for 24-bit true color), where
x is a number between 0 and 255 inclusive. x may be given as a normal
decimal number of a hexadecimal number, where the latter is prefixed by
0x.
Valid style instructions are nobold, bold, intense, nointense,
underline, nounderline.
Example
The standard way to build a UserColorSpec is to parse it from a string.
Once multiple UserColorSpecs have been constructed, they can be provided
to the standard printer where they will automatically be applied to the
output.
A UserColorSpec can also be converted to a termcolor::ColorSpec:
extern crate grep_printer; extern crate termcolor; use termcolor::{Color, ColorSpec}; use grep_printer::UserColorSpec; let user_spec1: UserColorSpec = "path:fg:blue".parse().unwrap(); let user_spec2: UserColorSpec = "match:bg:0xff,0x7f,0x00".parse().unwrap(); let spec1 = user_spec1.to_color_spec(); let spec2 = user_spec2.to_color_spec(); assert_eq!(spec1.fg(), Some(&Color::Blue)); assert_eq!(spec2.bg(), Some(&Color::Rgb(0xFF, 0x7F, 0x00)));
Implementations
impl UserColorSpec[src]
pub fn to_color_spec(&self) -> ColorSpec[src]
Convert this user provided color specification to a specification that
can be used with termcolor. This drops the type of this specification
(where the type indicates where the color is applied in the standard
printer, e.g., to the file path or the line numbers, etc.).
Trait Implementations
impl Clone for UserColorSpec[src]
fn clone(&self) -> UserColorSpec[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
impl Debug for UserColorSpec[src]
impl Eq for UserColorSpec[src]
impl FromStr for UserColorSpec[src]
type Err = ColorError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<UserColorSpec, ColorError>[src]
impl PartialEq<UserColorSpec> for UserColorSpec[src]
fn eq(&self, other: &UserColorSpec) -> bool[src]
fn ne(&self, other: &UserColorSpec) -> bool[src]
impl StructuralEq for UserColorSpec[src]
impl StructuralPartialEq for UserColorSpec[src]
Auto Trait Implementations
impl RefUnwindSafe for UserColorSpec
impl Send for UserColorSpec
impl Sync for UserColorSpec
impl Unpin for UserColorSpec
impl UnwindSafe for UserColorSpec
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,