pub struct StyleSheet {
    pub fg: Option<Color>,
    pub bg: Option<Color>,
    pub att: Attributes,
}
Expand description

Style definitions that can be applied to the rendered content.

Example

use inquire::ui::{Attributes, Color, StyleSheet};

let style_sheet = StyleSheet::default();

assert!(style_sheet.is_empty());

let style_sheet = style_sheet
    .with_bg(Color::DarkBlue)
    .with_attr(Attributes::ITALIC | Attributes::BOLD);

assert!(!style_sheet.is_empty());

Fields§

§fg: Option<Color>

Foreground color of text.

§bg: Option<Color>

Background color of text.

§att: Attributes

Attributes applied to text.

Implementations§

source§

impl StyleSheet

source

pub fn new() -> StyleSheet

Creates a style sheet with no colors and no attributes

source

pub fn empty() -> StyleSheet

A stylesheet with no colors and no attributes.

source

pub fn is_empty(&self) -> bool

Check if the stylesheet contains no colors and no attributes.

source

pub fn with_fg(self, fg: Color) -> StyleSheet

Copies the StyleSheet to a new one set with the defined foreground Color.

source

pub fn with_bg(self, bg: Color) -> StyleSheet

Copies the StyleSheet to a new one set with the defined background Color.

source

pub fn with_attr(self, attributes: Attributes) -> StyleSheet

Copies the style sheet to a new one with the specified attributes.

Warning: this does not keep the previously applied attributes. If you want to just set a new attribute and keep the others, you need to apply the OR operation yourself.

Example
use inquire::ui::{Attributes, Color, StyleSheet};

let style_sheet = StyleSheet::default().with_attr(Attributes::BOLD);
assert_eq!(true,  style_sheet.att.contains(Attributes::BOLD));
assert_eq!(false, style_sheet.att.contains(Attributes::ITALIC));

let style_sheet = style_sheet.with_attr(Attributes::ITALIC);
assert_eq!(false, style_sheet.att.contains(Attributes::BOLD));
assert_eq!(true,  style_sheet.att.contains(Attributes::ITALIC));

let style_sheet = style_sheet.with_attr(style_sheet.att | Attributes::BOLD);
assert_eq!(true, style_sheet.att.contains(Attributes::BOLD));
assert_eq!(true, style_sheet.att.contains(Attributes::ITALIC));

Trait Implementations§

source§

impl Clone for StyleSheet

source§

fn clone(&self) -> StyleSheet

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for StyleSheet

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for StyleSheet

source§

fn default() -> StyleSheet

A stylesheet with no colors and no attributes.

source§

impl PartialEq<StyleSheet> for StyleSheet

source§

fn eq(&self, other: &StyleSheet) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for StyleSheet

source§

impl Eq for StyleSheet

source§

impl StructuralEq for StyleSheet

source§

impl StructuralPartialEq for StyleSheet

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for Twhere T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.