pub struct Formatting {
pub foreground_color: Option<Color>,
pub background_color: Option<Color>,
pub text_formatting: Vec<FormattingOption>,
}Expand description
Represent the text formatting which includes
- Color of the text
- Color of the background
- Text formatting options
Fields§
§foreground_color: Option<Color>Text color
background_color: Option<Color>Background color
text_formatting: Vec<FormattingOption>List of formatting options
Implementations§
Source§impl Formatting
impl Formatting
Sourcepub fn foreground_color(self, color: Color) -> Self
pub fn foreground_color(self, color: Color) -> Self
Set the text color
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}Sourcepub fn background_color(self, color: Color) -> Self
pub fn background_color(self, color: Color) -> Self
Set the background color
Sourcepub fn bold(self) -> Self
pub fn bold(self) -> Self
Make the text bold
Examples found in repository?
examples/styling.rs (line 23)
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}Sourcepub fn underline(self) -> Self
pub fn underline(self) -> Self
Underline the text
Examples found in repository?
examples/styling.rs (line 24)
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}Sourcepub fn crossed_out(self) -> Self
pub fn crossed_out(self) -> Self
Cross the text out
Sourcepub fn print(
&self,
text: impl Into<String>,
cmd_buffer: &mut impl CommandBuffer,
)
pub fn print( &self, text: impl Into<String>, cmd_buffer: &mut impl CommandBuffer, )
Print the given text using the current formatting to the provided command buffer
Trait Implementations§
Source§impl Clone for Formatting
impl Clone for Formatting
Source§fn clone(&self) -> Formatting
fn clone(&self) -> Formatting
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for Formatting
impl RefUnwindSafe for Formatting
impl Send for Formatting
impl Sync for Formatting
impl Unpin for Formatting
impl UnwindSafe for Formatting
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more