Style

Struct Style 

Source
pub struct Style {
Show 15 fields pub fg: Option<Color>, pub bg: Option<Color>, pub decoration: Option<Vec<Decoration>>, pub padding: Option<u8>, pub padding_top: Option<u8>, pub padding_bottom: Option<u8>, pub padding_left: Option<u8>, pub padding_right: Option<u8>, pub margin: Option<u8>, pub margin_top: Option<u8>, pub margin_bottom: Option<u8>, pub margin_left: Option<u8>, pub margin_right: Option<u8>, pub border_color: Option<Color>, pub border_style: Option<BorderStyle>,
}

Fields§

§fg: Option<Color>§bg: Option<Color>§decoration: Option<Vec<Decoration>>§padding: Option<u8>§padding_top: Option<u8>§padding_bottom: Option<u8>§padding_left: Option<u8>§padding_right: Option<u8>§margin: Option<u8>§margin_top: Option<u8>§margin_bottom: Option<u8>§margin_left: Option<u8>§margin_right: Option<u8>§border_color: Option<Color>§border_style: Option<BorderStyle>

Implementations§

Source§

impl Style

Source

pub fn new() -> Self

Creates a new default style.

Examples found in repository?
examples/multiple_sources.rs (line 63)
6fn main() {
7    // Create a new Termio instance
8    let mut tcss = Termio::new();
9
10    // Load basic styles from string
11    let base_styles = r#"
12        @element "base" {
13            color: white;
14            background: black;
15            decoration: bold;
16            padding: 1;
17        }
18
19        @element "subtle" {
20            color: i-black;
21            background: black;
22            decoration: italic;
23        }
24    "#;
25
26    // Parse basic styles
27    match tcss.parse(base_styles) {
28        Ok(_) => println!("Basic styles successfully loaded from string!"),
29        Err(e) => {
30            eprintln!("Error parsing basic styles: {}", e);
31            return;
32        }
33    }
34
35    // Load additional styles from file
36    let additional_styles_path = Path::new("examples/styles.tcss");
37    let mut additional_styles = String::new();
38
39    // Read the file
40    let mut file = match File::open(&additional_styles_path) {
41        Ok(file) => file,
42        Err(e) => {
43            eprintln!("Failed to open style file: {}", e);
44            return;
45        }
46    };
47
48    if let Err(e) = file.read_to_string(&mut additional_styles) {
49        eprintln!("Failed to read style file: {}", e);
50        return;
51    }
52
53    // Parse additional styles
54    match tcss.parse(&additional_styles) {
55        Ok(_) => println!("Additional styles successfully loaded from file!"),
56        Err(e) => {
57            eprintln!("Error parsing additional styles: {}", e);
58            return;
59        }
60    }
61
62    // Add another custom style via API
63    let mut custom_style = Style::new();
64    custom_style.fg = Some(Color::Magenta);
65    custom_style.decoration = Some(vec![Decoration::Bold, Decoration::Underline]);
66    custom_style.padding = Some(1);
67    custom_style.padding_left = Some(6);
68    custom_style.padding_right = Some(6);
69    custom_style.border_style = Some(BorderStyle::Rounded);
70
71    // Add style to the parser
72    tcss.add_style("custom", custom_style);
73    println!("Custom style successfully added via API!");
74
75    let style_from_macros = style! {
76        fg: Color::IntenseBlack,
77        bg: Color::Black,
78        decoration: vec![Decoration::Strikethrough],  
79        padding: 1,
80        border_style: BorderStyle::Dashed,
81    };
82    
83    tcss.add_style("macros", style_from_macros);
84    println!("Macros style successfully added via macros!");
85
86    // Display all styles
87    println!("Examples of using styles from different sources:");
88    println!("{}", "Base style from string".style("base", &tcss));
89    println!("{}", "Subtle style from string".style("subtle", &tcss));
90    println!("{}", "Header from file".style("header", &tcss));
91    println!("{}", "Warning from file".style("warning", &tcss));
92    println!("{}", "Custom style via API".style("custom", &tcss));
93    println!("{}", "Macros style".style("macros", &tcss));
94}
Source

pub fn fg(self, color: Color) -> Self

Sets the foreground color.

Source

pub fn bg(self, color: Color) -> Self

Sets the background color.

Source

pub fn decoration(self, deco: Vec<Decoration>) -> Self

Sets the text decoration.

Source

pub fn padding(self, pad: u8) -> Self

Sets the padding (spaces inside the border).

Source

pub fn padding_top(self, pad: u8) -> Self

Sets the top padding.

Source

pub fn padding_bottom(self, pad: u8) -> Self

Sets the bottom padding.

Source

pub fn padding_left(self, pad: u8) -> Self

Sets the left padding.

Source

pub fn padding_right(self, pad: u8) -> Self

Sets the right padding.

Source

pub fn margin(self, margin: u8) -> Self

Sets the margin (lines outside the border).

Source

pub fn margin_top(self, margin: u8) -> Self

Sets the top margin.

Source

pub fn margin_bottom(self, margin: u8) -> Self

Sets the bottom margin.

Source

pub fn margin_left(self, margin: u8) -> Self

Sets the left margin.

Source

pub fn margin_right(self, margin: u8) -> Self

Sets the right margin.

Source

pub fn border_color(self, color: Color) -> Self

Sets the border color.

Source

pub fn border_style(self, style: BorderStyle) -> Self

Sets the border style.

Trait Implementations§

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

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