Style

Struct Style 

Source
pub struct Style {
    pub foreground: Option<u8>,
    pub background: Option<u8>,
    pub bold: Option<bool>,
    pub italic: Option<bool>,
    pub invert: Option<bool>,
}
Expand description

A text style, encompassing the color and other style options.

Fields§

§foreground: Option<u8>

The foreground color.

§background: Option<u8>

The background color.

§bold: Option<bool>

Whether the text should be bold.

§italic: Option<bool>

Whether the text should be italicized.

§invert: Option<bool>

Whether the text should have its colors inverted.

Implementations§

Source§

impl Style

Source

pub const EMPTY: Style

The empty style, with nothing specified. Equivalent to Style::default().

Source

pub const BOLD: Style

Bold text.

Source

pub const ITALIC: Style

Italicized text.

Source

pub const INVERT: Style

Inverted colors.

Source

pub fn fg(value: u8) -> Style

Creates a style with only the foreground specified.

Examples found in repository?
examples/tic_tac_toe.rs (line 136)
134fn render_player(player: Option<Player>) -> impl Element {
135    match player {
136        None => "-".with_style(Style::fg(245)),
137        Some(Player::X) => "X".with_style(Style::BOLD + Style::fg(33)),
138        Some(Player::O) => "O".with_style(Style::BOLD + Style::fg(203)),
139    }
140}
Source

pub fn bg(value: u8) -> Style

Creates a style with only the background specified.

Examples found in repository?
examples/input.rs (line 27)
13fn main() -> std::io::Result<()> {
14    let stdout = std::io::stdout().into_raw_mode()?;
15    let mut r = Renderer::new(stdout);
16
17    let mut name = String::new();
18
19    let mut events = std::io::stdin().events();
20    loop {
21        r.reset()?
22            .render((
23                "Enter your name: ".into_element(),
24                (name.into_element(), Cursor, Gap(1))
25                    .fixed_width(20)
26                    .truncated(Direction::Left)
27                    .with_style(Style::bg(240)),
28            ))?
29            .finish()?;
30
31        let Some(event) = events.next().transpose()? else {
32            break;
33        };
34        match event {
35            Event::Key(Key::Char(ch)) if !ch.is_ascii_control() => name.push(ch),
36            Event::Key(Key::Char('\n' | '\r')) => break,
37            Event::Key(Key::Backspace) => {
38                name.pop();
39            }
40            _ => {}
41        }
42    }
43
44    r.clear()?;
45    drop(r);
46    println!("Your name is {name:?}");
47    Ok(())
48}
Source

pub fn with(self, other: Style) -> Style

Merges two styles, with other taking precedence.

Source

pub fn or(self, other: Style) -> Style

Merges two styles, with self taking precedence.

Trait Implementations§

Source§

impl Add for Style

Source§

type Output = Style

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign for Style

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for Style

Source§

fn clone(&self) -> Style

Returns a duplicate 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 Style

Source§

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

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

impl Default for Style

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Style

Source§

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

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

impl PartialEq for Style

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Style

Source§

impl Eq for Style

Source§

impl StructuralPartialEq for Style

Auto Trait Implementations§

§

impl Freeze for Style

§

impl RefUnwindSafe for Style

§

impl Send for Style

§

impl Sync for Style

§

impl Unpin for Style

§

impl UnwindSafe for Style

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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 T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.