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
impl Style
Sourcepub const EMPTY: Style
pub const EMPTY: Style
The empty style, with nothing specified. Equivalent to Style::default().
Sourcepub fn bg(value: u8) -> Style
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}Trait Implementations§
impl Copy for Style
impl Eq for Style
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> 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