Struct Styles

pub struct Styles { /* private fields */ }

Terminal styling definitions

See also [Command::styles][crate::Command::styles].

Example

clap v3 styling

# use clap_builder as clap;
# use clap::builder::styling::*;
let styles = Styles::styled()
    .header(AnsiColor::Yellow.on_default())
    .usage(AnsiColor::Green.on_default())
    .literal(AnsiColor::Green.on_default())
    .placeholder(AnsiColor::Green.on_default());

Implementations

impl Styles

const fn get_header(&self) -> &Style

General Heading style, e.g. [help_heading][crate::Arg::help_heading]

const fn get_error(&self) -> &Style

Error heading

const fn get_usage(&self) -> &Style

Usage heading

const fn get_literal(&self) -> &Style

Literal command-line syntax, e.g. --help

const fn get_placeholder(&self) -> &Style

Descriptions within command-line syntax, e.g. [value_name][crate::Arg::value_name]

const fn get_valid(&self) -> &Style

Highlight suggested usage

const fn get_invalid(&self) -> &Style

Highlight invalid usage

const fn get_context(&self) -> &Style

Highlight all specified contexts, e.g. [default: false]

To specialize the style of the value within the context, see Styles::context_value

const fn get_context_value(&self) -> &Style

Highlight values within all of the context, e.g. the false in [default: false]

If not explicitly set, falls back to context's style.

impl Styles

const fn plain() -> Self

No terminal styling

const fn styled() -> Self

Default terminal styling

const fn header(self, style: Style) -> Self

General Heading style, e.g. [help_heading][crate::Arg::help_heading]

const fn error(self, style: Style) -> Self

Error heading

const fn usage(self, style: Style) -> Self

Usage heading

const fn literal(self, style: Style) -> Self

Literal command-line syntax, e.g. --help

const fn placeholder(self, style: Style) -> Self

Descriptions within command-line syntax, e.g. [value_name][crate::Arg::value_name]

const fn valid(self, style: Style) -> Self

Highlight suggested usage

const fn invalid(self, style: Style) -> Self

Highlight invalid usage

const fn context(self, style: Style) -> Self

Highlight all specified contexts, e.g. [default: false]

To specialize the style of the value within the context, see Styles::context_value

const fn context_value(self, style: Style) -> Self

Highlight values within all of the context, e.g. the false in [default: false]

If not explicitly set, falls back to context's style.

Trait Implementations

impl Clone for Styles

fn clone(&self) -> Self

impl Debug for Styles

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Default for Styles

fn default() -> Self

Auto Trait Implementations

impl Freeze for Styles

impl RefUnwindSafe for Styles

impl Send for Styles

impl Sync for Styles

impl Unpin for Styles

impl UnsafeUnpin for Styles

impl UnwindSafe for Styles

Blanket Implementations

impl<T> Any for Styles where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Styles where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Styles where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Styles where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Styles

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Styles where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for Styles where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Styles where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Styles where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>