LabelStyle

Struct LabelStyle 

Source
pub struct LabelStyle { /* private fields */ }
Expand description

Style for the common part of all prompts: the prompt itself.

Implementations§

Source§

impl LabelStyle

Source

pub fn prefix<S: Into<String>>(self, p: S) -> Self

Sets the string that is displayed before the user’s input

Examples found in repository?
examples/styling.rs (line 19)
17fn main() -> Result<()> {
18    let label_style = LabelStyle::default()
19        .prefix("*")
20        .prefix_formatting(Formatting::default().foreground_color(Color::Cyan))
21        .prompt_formatting(
22            Formatting::default()
23                .bold()
24                .underline()
25                .foreground_color(Color::Magenta),
26        );
27    let input_formatting = Formatting::default().foreground_color(Color::Cyan);
28    let submitted_formatting = Formatting::default().foreground_color(Color::DarkCyan);
29
30    let name = Input::new("Enter your name", name_validation)
31        .style(
32            InputStyle::default()
33                .label_style(label_style.clone())
34                .input_formatting(input_formatting.clone())
35                .submitted_formatting(submitted_formatting.clone()),
36        )
37        .display();
38    let coffee = Confirmation::new("Do you want a cup of coffee")
39        .style(
40            ConfirmationStyle::default()
41                .label_style(label_style.clone())
42                .input_formatting(input_formatting.clone())
43                .submitted_formatting(submitted_formatting.clone()),
44        )
45        .display();
46
47    println!("Name: {:?}", name);
48    println!("Coffee: {:?}", coffee);
49
50    Ok(())
51}
Source

pub fn prefix_formatting(self, f: Formatting) -> Self

Sets formatting for the prefix string

Examples found in repository?
examples/styling.rs (line 20)
17fn main() -> Result<()> {
18    let label_style = LabelStyle::default()
19        .prefix("*")
20        .prefix_formatting(Formatting::default().foreground_color(Color::Cyan))
21        .prompt_formatting(
22            Formatting::default()
23                .bold()
24                .underline()
25                .foreground_color(Color::Magenta),
26        );
27    let input_formatting = Formatting::default().foreground_color(Color::Cyan);
28    let submitted_formatting = Formatting::default().foreground_color(Color::DarkCyan);
29
30    let name = Input::new("Enter your name", name_validation)
31        .style(
32            InputStyle::default()
33                .label_style(label_style.clone())
34                .input_formatting(input_formatting.clone())
35                .submitted_formatting(submitted_formatting.clone()),
36        )
37        .display();
38    let coffee = Confirmation::new("Do you want a cup of coffee")
39        .style(
40            ConfirmationStyle::default()
41                .label_style(label_style.clone())
42                .input_formatting(input_formatting.clone())
43                .submitted_formatting(submitted_formatting.clone()),
44        )
45        .display();
46
47    println!("Name: {:?}", name);
48    println!("Coffee: {:?}", coffee);
49
50    Ok(())
51}
Source

pub fn prompt_formatting(self, f: Formatting) -> Self

Sets formatting for the user input string

Examples found in repository?
examples/styling.rs (lines 21-26)
17fn main() -> Result<()> {
18    let label_style = LabelStyle::default()
19        .prefix("*")
20        .prefix_formatting(Formatting::default().foreground_color(Color::Cyan))
21        .prompt_formatting(
22            Formatting::default()
23                .bold()
24                .underline()
25                .foreground_color(Color::Magenta),
26        );
27    let input_formatting = Formatting::default().foreground_color(Color::Cyan);
28    let submitted_formatting = Formatting::default().foreground_color(Color::DarkCyan);
29
30    let name = Input::new("Enter your name", name_validation)
31        .style(
32            InputStyle::default()
33                .label_style(label_style.clone())
34                .input_formatting(input_formatting.clone())
35                .submitted_formatting(submitted_formatting.clone()),
36        )
37        .display();
38    let coffee = Confirmation::new("Do you want a cup of coffee")
39        .style(
40            ConfirmationStyle::default()
41                .label_style(label_style.clone())
42                .input_formatting(input_formatting.clone())
43                .submitted_formatting(submitted_formatting.clone()),
44        )
45        .display();
46
47    println!("Name: {:?}", name);
48    println!("Coffee: {:?}", coffee);
49
50    Ok(())
51}
Source

pub fn print( &self, text: impl Into<String>, cmd_buffer: &mut impl CommandBuffer, )

Prints the formatted prefix and the input text to the provided command buffer

Trait Implementations§

Source§

impl Clone for LabelStyle

Source§

fn clone(&self) -> LabelStyle

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 Default for LabelStyle

Source§

fn default() -> Self

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

Auto Trait Implementations§

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, 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.