[][src]Struct term_string::TermStyle

pub struct TermStyle { /* fields omitted */ }

Styling info for TermString.

Internally, TermStyle has zero or more Attrs set.

Methods

impl TermStyle
[src]

Convenient methods for setting, unsetting, and checking Attr variants in a TermStyle variable.

This block has helper methods for Attr variants with no data:

(bold, dim, blink, reverse, secure)

Examples

let mut style = TermStyle::bold();
assert!(style.has_bold());
style.unset_bold();
assert!(!style.has_bold());

Create a new TermStyle with Attr::Bold set.

This is equivalent to TermStyle::from([Attr::Bold]).

Create a new TermStyle with Attr::Dim set.

This is equivalent to TermStyle::from([Attr::Dim]).

Create a new TermStyle with Attr::Blink set.

This is equivalent to TermStyle::from([Attr::Blink]).

Create a new TermStyle with Attr::Reverse set.

This is equivalent to TermStyle::from([Attr::Reverse]).

Create a new TermStyle with Attr::Secure set.

This is equivalent to TermStyle::from([Attr::Secure]).

Check if Attr::Bold is set in style.

Check if Attr::Dim is set in style.

Check if Attr::Blink is set in style.

Check if Attr::Reverse is set in style.

Check if Attr::Secure is set in style.

Set/Add Attr::Bold to style.

The chaining equivalent of add_bold().

Set/Add Attr::Dim to style.

The chaining equivalent of add_dim().

Set/Add Attr::Blink to style.

The chaining equivalent of add_blink().

Set/Add Attr::Reverse to style.

The chaining equivalent of add_reverse().

Set/Add Attr::Secure to style.

The chaining equivalent of add_secure().

Unset/Remove Attr::Bold from style.

The chaining equivalent of unset_bold().

Unset/Remove Attr::Dim from style.

The chaining equivalent of unset_dim().

Unset/Remove Attr::Blink from style.

The chaining equivalent of unset_blink().

Unset/Remove Attr::Reverse from style.

The chaining equivalent of unset_reverse().

Unset/Remove Attr::Secure from style.

The chaining equivalent of unset_secure().

impl TermStyle
[src]

Convenient methods for setting, unsetting, and checking Attr variants in a TermStyle variable.

This block has helper methods for Attr variants with bool data:

(italic, underline, standout)

Note

Unlike the attribute variants in the above block, those attributes have bool data. This is because those capabilities were a late addition to the terminfo database. And when they were added, they were added in pairs (enter capability mode, exit capability mode).

There is no reason and no need to set any of those attributes with false here, as styles are fully reset between writes/prints. The API is still fully exposed to stay close and introduce no magic over what the term crate exposes (Attr is a re-export of term::Attr).

Examples

let mut style = TermStyle::underline(true);
// Returns true if underline is set, to true or false.
assert!(style.has_underline());
assert!(style.has_exact_underline(true));
assert!(!style.has_exact_underline(false));
// style.unset_exact_underline(true);
// Unsets whether underline is true or false.
style.unset_underline();
assert!(!style.has_underline());

Create a new TermStyle with Attr::Italic(arg) set.

This is equivalent to TermStyle::from([Attr::Italic(arg) ]).

Create a new TermStyle with Attr::Underline(arg) set.

This is equivalent to TermStyle::from([Attr::Underline(arg) ]).

Create a new TermStyle with Attr::Standout(arg) set.

This is equivalent to TermStyle::from([Attr::Standout(arg) ]).

Check if Attr::Italic(val) is set in style. where val can be any value of bool.

Check if Attr::Italic(arg) is set in style.

Check if Attr::Underline(val) is set in style. where val can be any value of bool.

Check if Attr::Underline(arg) is set in style.

Check if Attr::Standout(val) is set in style. where val can be any value of bool.

Check if Attr::Standout(arg) is set in style.

Set/Add Attr::Italic(arg) to style.

The chaining equivalent of add_italic().

Set/Add Attr::Italic(arg) to style, if Attr::Italic is not already set.

The chaining equivalent of or_italic().

Set/Add Attr::Underline(arg) to style.

The chaining equivalent of add_underline().

Set/Add Attr::Underline(arg) to style, if Attr::Underline is not already set.

The chaining equivalent of or_underline().

Set/Add Attr::Standout(arg) to style.

The chaining equivalent of add_standout().

Set/Add Attr::Standout(arg) to style, if Attr::Standout is not already set.

The chaining equivalent of or_standout().

Unset/Remove Attr::Italic(val) from style. where val can be any value of bool.

The chaining equivalent of unset_italic().

Unset/Remove Attr::Italic(arg) from style.

The chaining equivalent of unset_exact_italic().

Unset/Remove Attr::Underline(val) from style. where val can be any value of bool.

The chaining equivalent of unset_underline().

Unset/Remove Attr::Underline(arg) from style.

The chaining equivalent of unset_exact_underline().

Unset/Remove Attr::Standout(val) from style. where val can be any value of bool.

The chaining equivalent of unset_standout().

Unset/Remove Attr::Standout(arg) from style.

The chaining equivalent of unset_exact_standout().

impl TermStyle
[src]

Convenient methods for setting, unsetting, and checking Attr variants in a TermStyle variable.

This block has helper methods for Attr variants with Color data:

(fg, bg)

Examples

use term_string::{TermStyle, color};

let mut style = TermStyle::fg(color::BLUE);
style += TermStyle::bg(color::WHITE);
// ==========
assert!(style.has_fg());
assert!(style.has_bg());
// ==========
assert!(style.has_exact_fg(color::BLUE));
assert!(style.has_exact_bg(color::WHITE));
// ==========
assert!(!style.has_exact_fg(color::RED));
assert!(!style.has_exact_bg(color::GREEN));
// ==========
style.unset_exact_fg(color::RED); // no effect
style.unset_exact_bg(color::GREEN); // no effect
assert!(!style.has_exact_fg(color::RED));
assert!(!style.has_exact_bg(color::GREEN));
// ==========
style.unset_fg();
style.unset_bg();
assert!(!style.has_fg());
assert!(!style.has_bg());

Create a new TermStyle with Attr::ForegroundColor(arg) set.

This is equivalent to TermStyle::from([Attr::ForegroundColor(arg) ]).

Create a new TermStyle with Attr::BackgroundColor(arg) set.

This is equivalent to TermStyle::from([Attr::BackgroundColor(arg) ]).

Check if Attr::ForegroundColor(val) is set in style. where val can be any value of Color.

Check if Attr::ForegroundColor(arg) is set in style.

Check if Attr::BackgroundColor(val) is set in style. where val can be any value of Color.

Check if Attr::BackgroundColor(arg) is set in style.

Set/Add Attr::ForegroundColor(arg) to style.

The chaining equivalent of add_fg().

Set/Add Attr::ForegroundColor(arg) to style, if Attr::ForegroundColor is not already set.

The chaining equivalent of or_fg().

Set/Add Attr::BackgroundColor(arg) to style.

The chaining equivalent of add_bg().

Set/Add Attr::BackgroundColor(arg) to style, if Attr::BackgroundColor is not already set.

The chaining equivalent of or_bg().

Unset/Remove Attr::ForegroundColor(val) from style. where val can be any value of Color.

The chaining equivalent of unset_fg().

Unset/Remove Attr::ForegroundColor(arg) from style.

The chaining equivalent of unset_exact_fg().

Unset/Remove Attr::BackgroundColor(val) from style. where val can be any value of Color.

The chaining equivalent of unset_bg().

Unset/Remove Attr::BackgroundColor(arg) from style.

The chaining equivalent of unset_exact_bg().

impl TermStyle
[src]

Methods that take Attr as an argument. Note that Attr is a Copy enum type.

TermStyle has attr set. Exact is referring to attr's data, if exists, being included in the check.

Examples

use term_string::{TermStyle, Attr};

let style = TermStyle::underline(true);
assert!(style.has_exact_attr(Attr::Underline(true)));
assert!(!style.has_exact_attr(Attr::Underline(false)));

TermStyle has attr set. Variant is referring to attr's data, if exists, being excluded from the check.

Examples

use term_string::{TermStyle, Attr};

let style = TermStyle::underline(true);
assert!(style.has_variant_attr(Attr::Underline(true)));
assert!(style.has_variant_attr(Attr::Underline(false)));

Unset/Remove the exact Attr from TermStyle.

Examples

use term_string::{TermStyle, Attr};

let mut style = TermStyle::underline(true);

// this does nothing, no exact match
style.unset_exact_attr(Attr::Underline(false));
assert_ne!(style, TermStyle::default());

// this unsets underline, exact match
style.unset_exact_attr(Attr::Underline(true));
assert_eq!(style, TermStyle::default());

Unset/Remove the variant Attr from TermStyle.

Examples

use term_string::{TermStyle, Attr};

let mut style = TermStyle::underline(true);

// this unsets underline, even without exact match
style.unset_variant_attr(Attr::Underline(false));
assert_eq!(style, TermStyle::default());

Set/Add attr to TermStyle, unless the same variant has been already set.

Examples

use term_string::{TermStyle, Attr, color};

let mut style = TermStyle::default();

// Add red background
style.or_attr(Attr::BackgroundColor(color::RED));
assert!(style.has_exact_bg(color::RED));

// Add green background if background is not already set
style.or_attr(Attr::BackgroundColor(color::GREEN));
// Since background was already set, it's still red
assert!(style.has_exact_bg(color::RED));

Set/Add attr to TermStyle, overriding the same variant if it was already set.

Examples

use term_string::{TermStyle, Attr, color};

let mut style = TermStyle::default();

// Add red background
style.add_attr(Attr::BackgroundColor(color::RED));
assert!(style.has_exact_bg(color::RED));

// Add green background, overriding already set background
style.add_attr(Attr::BackgroundColor(color::GREEN));
// background will always be green after the above line
assert!(style.has_exact_bg(color::GREEN));

The chaining equivalent of unset_exact_attr().

The chaining equivalent of unset_variant_attr().

The chaining equivalent of add_attr().

The chaining equivalent of or_attr().

impl TermStyle
[src]

Methods that take Into<Self> as an argument. So you can either pass TermStyle, or Attr arrays or slices.

These methods mirror the behavior of the methods above that take a single Attr argument, except they apply to all attributes set in the style passed as argument.

Examples

use term_string::{TermStyle, Attr};

let st1 = TermStyle::default()
  .with_attr(Attr::Bold)
  .with_attr(Attr::Underline(true));

let st2 = TermStyle::default()
  .with_style([Attr::Bold, Attr::Underline(true)]);

assert_eq!(st1, st2);
assert!(st1.has_exact_style([Attr::Bold, Attr::Underline(true)]));
assert!(st2.has_exact_style(st1));

Apply has_exact_attr() to all Attrs set in other.

Apply has_variant_attr() to all Attrs set in other.

Apply unset_exact_attr() to all Attrs set in other.

Apply unset_variant_attr() to all Attrs set in other.

Apply or_attr() to all Attrs set in other.

Apply add_attr() to all Attrs set in other.

The chaining equivalent of add_style().

The chaining equivalent of or_style().

The chaining equivalent of unset_exact_style().

The chaining equivalent of unset_variant_style().

impl TermStyle
[src]

Other methods

Resets style to default.

Checks if both styles have the same exact attributes set. This is used for implementing PartialEq, so you should probably use that instead.

Examples

use term_string::{TermStyle, Attr};

let st1 = TermStyle::bold() + TermStyle::underline(true);
let st2 = st1 + TermStyle::reverse();
assert!(st1.eq_style([Attr::Underline(true), Attr::Bold]));
// Needless to say, subset != equal
assert!(!st2.eq_style(st1));

Checks if both styles have the same exact attribute variants set.

Examples

use term_string::{TermStyle, Attr};

let st1 = TermStyle::bold() + TermStyle::underline(true);
let st2 = st1 + TermStyle::reverse();
assert!(st1.eq_variant_style([Attr::Underline(true), Attr::Bold]));
// Same variant, different data still counts as equal
assert!(st1.eq_variant_style([Attr::Underline(false), Attr::Bold]));

Trait Implementations

impl Copy for TermStyle
[src]

impl Clone for TermStyle
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Default for TermStyle
[src]

Returns the "default value" for a type. Read more

impl Debug for TermStyle
[src]

Formats the value using the given formatter. Read more

impl PartialEq for TermStyle
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<A> From<A> for TermStyle where
    A: Borrow<[Attr]>, 
[src]

Get a TermStyle from Attr arrays or slices.

Performs the conversion.

impl<IS> BitOr<IS> for TermStyle where
    IS: Into<Self>, 
[src]

Check out or_style() and or_attr().

The resulting type after applying the | operator.

Performs the | operation.

impl<IS> BitOrAssign<IS> for TermStyle where
    IS: Into<Self>, 
[src]

Performs the |= operation.

impl<IS> Add<IS> for TermStyle where
    IS: Into<Self>, 
[src]

Check out add_style() and add_attr().

The resulting type after applying the + operator.

Performs the + operation.

impl<IS> AddAssign<IS> for TermStyle where
    IS: Into<Self>, 
[src]

Performs the += operation.

impl<IS> Sub<IS> for TermStyle where
    IS: Into<Self>, 
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<IS> SubAssign<IS> for TermStyle where
    IS: Into<Self>, 
[src]

Performs the -= operation.

Auto Trait Implementations

impl Send for TermStyle

impl Sync for TermStyle