pub struct Termio { /* private fields */ }
Implementations§
Source§impl Termio
impl Termio
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Termio with an empty style map.
Examples found in repository?
examples/basic.rs (line 4)
3fn main() {
4 let mut tcss = Termio::new();
5
6 let tcss_content = r#"
7 @element "header" {
8 color: blue;
9 background: i-blue;
10 decoration: bold;
11 }
12
13 @element "warning" {
14 color: yellow;
15 background: i-yellow;
16 decoration: bold italic;
17 }
18
19 @element "info" {
20 color: cyan;
21 background: i-cyan;
22 decoration: underline;
23 }
24 "#;
25
26 tcss.parse(tcss_content).unwrap();
27
28 println!("{}", "Welcome to Terminal CSS!".style("header", &tcss));
29 println!("{}", "This is a warning message".style("warning", &tcss));
30 println!("{}", "And this is an info message".style("info", &tcss));
31}
More examples
examples/colors.rs (line 4)
3fn main() {
4 let mut tcss = Termio::new();
5
6 let tcss_content = r#"
7 @element "basic" {
8 color: red;
9 background: black;
10 }
11
12 @element "intense" {
13 color: i-red;
14 background: i-black;
15 }
16
17 @element "rgb" {
18 color: rgb(255, 0, 0);
19 background: rgb(0, 0, 0);
20 }
21
22 @element "code" {
23 color: 196;
24 background: 0;
25 border: solid rgb(6, 180, 49);
26 }
27 "#;
28
29 tcss.parse(tcss_content).unwrap();
30
31 println!("Basic colors:");
32 println!("{}", "Red text on black background".style("basic", &tcss));
33
34 println!("\nIntense colors:");
35 println!("{}", "Intense red text on intense black background".style("intense", &tcss));
36
37 println!("\nRGB colors:");
38 println!("{}", "RGB red text on RGB black background".style("rgb", &tcss));
39
40 println!("\nColor codes:");
41 println!("{}", "Color code 196 (red) on code 0 (black)".style("code", &tcss));
42}
examples/advanced.rs (line 4)
3fn main() {
4 let mut tcss = Termio::new();
5
6 let tcss_content = r#"
7 @element "card" {
8 color: white;
9 background: i-black;
10 decoration: bold;
11 border: rounded i-blue;
12 padding: 1;
13 }
14
15 @element "title" {
16 color: i-blue;
17 decoration: bold underline;
18 }
19
20 @element "button" {
21 color: black;
22 background: i-green;
23 decoration: bold;
24 border: rounded i-green;
25 }
26
27 @element "error" {
28 color: white;
29 background: i-red;
30 decoration: bold;
31 border: solid i-red;
32 }
33 "#;
34
35 tcss.parse(tcss_content).unwrap();
36
37 // Create a card with a header and buttons
38 println!("{}", "User Profile".style("title", &tcss));
39 println!("{}", "Name: John Doe\nEmail: john@example.com".style("card", &tcss));
40 println!("{}", "Edit Profile".style("button", &tcss));
41 println!("{}", "Delete Account".style("button", &tcss));
42 println!("{}", "Failed to connect to server".style("error", &tcss));
43}
examples/borders.rs (line 5)
4fn main() {
5 let mut parser = Termio::new();
6
7 let tcss = r#"
8 @element "solid-red" {
9 border-style: solid;
10 border-color: red;
11 padding: 1;
12 }
13
14 @element "dashed-green" {
15 border-style: dashed;
16 border-color: green;
17 padding: 1;
18 }
19
20 @element "rounded-blue" {
21 border-style: rounded;
22 border-color: blue;
23 padding: 1;
24 }
25
26 @element "fancy-yellow" {
27 border-style: solid;
28 border-color: yellow;
29 color: yellow;
30 background: black;
31 decoration: bold;
32 padding: 1 2;
33 }
34
35 @element "rainbow" {
36 border-style: rounded;
37 border-color: i-magenta;
38 color: cyan;
39 background: black;
40 decoration: bold italic;
41 padding: 2;
42 margin: 1;
43 }
44
45 @element "outer" {
46 border-style: dashed;
47 border-color: red;
48 color: white;
49 background: black;
50 padding: 2;
51 margin: 1;
52 }
53
54 @element "inner" {
55 border-style: solid;
56 border-color: cyan;
57 color: i-green;
58 background: rgb(44, 202, 0);
59 padding: 1;
60 margin: 0;
61 }
62 "#;
63
64 parser.parse(tcss).unwrap();
65
66 // Basic border styles
67 println!("{}", "Simple solid red border".style("solid-red", &parser));
68 println!("{}", "Dashed green border".style("dashed-green", &parser));
69 println!("{}", "Rounded blue border".style("rounded-blue", &parser));
70
71 println!("\nStyled content with borders:");
72 println!("{}", "Fancy Yellow Box".style("fancy-yellow", &parser));
73 println!("{}", "Rainbow Box with Margins".style("rainbow", &parser));
74
75 println!("\nNested borders:");
76 let outer_start = "Outer box containing:".style("outer", &parser);
77 let inner_box = "This is an inner box\nwith multiple lines\nof styled content".style("inner", &parser);
78 println!("{}\n{}", outer_start, inner_box);
79}
examples/decorations.rs (line 4)
3fn main() {
4 let mut parser = Termio::new();
5
6 let tcss = r#"
7 @element "bold" {
8 decoration: bold;
9 color: green;
10 }
11 @element "italic" {
12 decoration: italic;
13 color: blue;
14 }
15 @element "underline" {
16 decoration: underline;
17 color: cyan;
18 }
19 @element "multiple" {
20 decoration: bold italic underline;
21 color: magenta;
22 }
23 @element "fancy" {
24 decoration: bold italic underline overline;
25 color: yellow;
26 }
27 @element "reverse" {
28 decoration: reverse;
29 color: red;
30 }
31 @element "conceal" {
32 decoration: conceal;
33 color: white;
34 }
35 @element "strikethrough" {
36 decoration: strikethrough;
37 color: i-red;
38 }
39 @element "framed" {
40 decoration: framed;
41 color: i-green;
42 }
43 @element "encircled" {
44 decoration: encircled;
45 color: i-blue;
46 }
47 @element "all" {
48 decoration: bold italic underline overline blink rapid-blink reverse strikethrough framed encircled;
49 color: i-magenta;
50 background: black;
51 }
52 "#;
53
54 parser.parse(tcss).unwrap();
55
56 println!("Basic decorations:");
57 println!("{}", "Bold Text".style("bold", &parser));
58 println!("{}", "Italic Text".style("italic", &parser));
59 println!("{}", "Underlined Text".style("underline", &parser));
60
61 println!("\nMultiple decorations:");
62 println!("{}", "Multiple Decorations".style("multiple", &parser));
63 println!("{}", "Fancy Text".style("fancy", &parser));
64
65 println!("\nSpecial decorations:");
66 println!("{}", "Reversed Text".style("reverse", &parser));
67 println!("{}", "Concealed Text".style("conceal", &parser));
68 println!("{}", "Strikethrough Text".style("strikethrough", &parser));
69 println!("{}", "Framed Text".style("framed", &parser));
70 println!("{}", "Encircled Text".style("encircled", &parser));
71 println!("\nAll decorations combined:");
72 println!("{}", "All Decorations".style("all", &parser));
73}
examples/multiple_sources.rs (line 8)
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}
Sourcepub fn from_file(path: &str) -> Result<Self, ParseError>
pub fn from_file(path: &str) -> Result<Self, ParseError>
Examples found in repository?
examples/from_file.rs (line 8)
6fn main() {
7 // Create a new Termio instance
8 let tcss = match Termio::from_file("examples/styles.tcss") {
9 Ok(tcss) => tcss,
10 Err(e) => {
11 eprintln!("Error loading styles: {}", e);
12 return;
13 }
14 };
15
16 // Apply styles to text
17 println!("Examples of using styles from file:");
18 println!("{}", "Page Header".style("header", &tcss));
19 println!("{}", "Important Message".style("warning", &tcss));
20 println!("{}", "Information Message".style("info", &tcss));
21 println!("{}", "Successful Action".style("success", &tcss));
22 println!("{}", "Operation Error".style("error", &tcss));
23}
Sourcepub fn get_style(&self, name: &str) -> Option<Style>
pub fn get_style(&self, name: &str) -> Option<Style>
Retrieves a style by name, returning None if not found.
Sourcepub fn parse(&mut self, content: &str) -> Result<(), ParseError>
pub fn parse(&mut self, content: &str) -> Result<(), ParseError>
Parses TCSS content and populates the style map.
Examples found in repository?
examples/basic.rs (line 26)
3fn main() {
4 let mut tcss = Termio::new();
5
6 let tcss_content = r#"
7 @element "header" {
8 color: blue;
9 background: i-blue;
10 decoration: bold;
11 }
12
13 @element "warning" {
14 color: yellow;
15 background: i-yellow;
16 decoration: bold italic;
17 }
18
19 @element "info" {
20 color: cyan;
21 background: i-cyan;
22 decoration: underline;
23 }
24 "#;
25
26 tcss.parse(tcss_content).unwrap();
27
28 println!("{}", "Welcome to Terminal CSS!".style("header", &tcss));
29 println!("{}", "This is a warning message".style("warning", &tcss));
30 println!("{}", "And this is an info message".style("info", &tcss));
31}
More examples
examples/colors.rs (line 29)
3fn main() {
4 let mut tcss = Termio::new();
5
6 let tcss_content = r#"
7 @element "basic" {
8 color: red;
9 background: black;
10 }
11
12 @element "intense" {
13 color: i-red;
14 background: i-black;
15 }
16
17 @element "rgb" {
18 color: rgb(255, 0, 0);
19 background: rgb(0, 0, 0);
20 }
21
22 @element "code" {
23 color: 196;
24 background: 0;
25 border: solid rgb(6, 180, 49);
26 }
27 "#;
28
29 tcss.parse(tcss_content).unwrap();
30
31 println!("Basic colors:");
32 println!("{}", "Red text on black background".style("basic", &tcss));
33
34 println!("\nIntense colors:");
35 println!("{}", "Intense red text on intense black background".style("intense", &tcss));
36
37 println!("\nRGB colors:");
38 println!("{}", "RGB red text on RGB black background".style("rgb", &tcss));
39
40 println!("\nColor codes:");
41 println!("{}", "Color code 196 (red) on code 0 (black)".style("code", &tcss));
42}
examples/advanced.rs (line 35)
3fn main() {
4 let mut tcss = Termio::new();
5
6 let tcss_content = r#"
7 @element "card" {
8 color: white;
9 background: i-black;
10 decoration: bold;
11 border: rounded i-blue;
12 padding: 1;
13 }
14
15 @element "title" {
16 color: i-blue;
17 decoration: bold underline;
18 }
19
20 @element "button" {
21 color: black;
22 background: i-green;
23 decoration: bold;
24 border: rounded i-green;
25 }
26
27 @element "error" {
28 color: white;
29 background: i-red;
30 decoration: bold;
31 border: solid i-red;
32 }
33 "#;
34
35 tcss.parse(tcss_content).unwrap();
36
37 // Create a card with a header and buttons
38 println!("{}", "User Profile".style("title", &tcss));
39 println!("{}", "Name: John Doe\nEmail: john@example.com".style("card", &tcss));
40 println!("{}", "Edit Profile".style("button", &tcss));
41 println!("{}", "Delete Account".style("button", &tcss));
42 println!("{}", "Failed to connect to server".style("error", &tcss));
43}
examples/borders.rs (line 64)
4fn main() {
5 let mut parser = Termio::new();
6
7 let tcss = r#"
8 @element "solid-red" {
9 border-style: solid;
10 border-color: red;
11 padding: 1;
12 }
13
14 @element "dashed-green" {
15 border-style: dashed;
16 border-color: green;
17 padding: 1;
18 }
19
20 @element "rounded-blue" {
21 border-style: rounded;
22 border-color: blue;
23 padding: 1;
24 }
25
26 @element "fancy-yellow" {
27 border-style: solid;
28 border-color: yellow;
29 color: yellow;
30 background: black;
31 decoration: bold;
32 padding: 1 2;
33 }
34
35 @element "rainbow" {
36 border-style: rounded;
37 border-color: i-magenta;
38 color: cyan;
39 background: black;
40 decoration: bold italic;
41 padding: 2;
42 margin: 1;
43 }
44
45 @element "outer" {
46 border-style: dashed;
47 border-color: red;
48 color: white;
49 background: black;
50 padding: 2;
51 margin: 1;
52 }
53
54 @element "inner" {
55 border-style: solid;
56 border-color: cyan;
57 color: i-green;
58 background: rgb(44, 202, 0);
59 padding: 1;
60 margin: 0;
61 }
62 "#;
63
64 parser.parse(tcss).unwrap();
65
66 // Basic border styles
67 println!("{}", "Simple solid red border".style("solid-red", &parser));
68 println!("{}", "Dashed green border".style("dashed-green", &parser));
69 println!("{}", "Rounded blue border".style("rounded-blue", &parser));
70
71 println!("\nStyled content with borders:");
72 println!("{}", "Fancy Yellow Box".style("fancy-yellow", &parser));
73 println!("{}", "Rainbow Box with Margins".style("rainbow", &parser));
74
75 println!("\nNested borders:");
76 let outer_start = "Outer box containing:".style("outer", &parser);
77 let inner_box = "This is an inner box\nwith multiple lines\nof styled content".style("inner", &parser);
78 println!("{}\n{}", outer_start, inner_box);
79}
examples/decorations.rs (line 54)
3fn main() {
4 let mut parser = Termio::new();
5
6 let tcss = r#"
7 @element "bold" {
8 decoration: bold;
9 color: green;
10 }
11 @element "italic" {
12 decoration: italic;
13 color: blue;
14 }
15 @element "underline" {
16 decoration: underline;
17 color: cyan;
18 }
19 @element "multiple" {
20 decoration: bold italic underline;
21 color: magenta;
22 }
23 @element "fancy" {
24 decoration: bold italic underline overline;
25 color: yellow;
26 }
27 @element "reverse" {
28 decoration: reverse;
29 color: red;
30 }
31 @element "conceal" {
32 decoration: conceal;
33 color: white;
34 }
35 @element "strikethrough" {
36 decoration: strikethrough;
37 color: i-red;
38 }
39 @element "framed" {
40 decoration: framed;
41 color: i-green;
42 }
43 @element "encircled" {
44 decoration: encircled;
45 color: i-blue;
46 }
47 @element "all" {
48 decoration: bold italic underline overline blink rapid-blink reverse strikethrough framed encircled;
49 color: i-magenta;
50 background: black;
51 }
52 "#;
53
54 parser.parse(tcss).unwrap();
55
56 println!("Basic decorations:");
57 println!("{}", "Bold Text".style("bold", &parser));
58 println!("{}", "Italic Text".style("italic", &parser));
59 println!("{}", "Underlined Text".style("underline", &parser));
60
61 println!("\nMultiple decorations:");
62 println!("{}", "Multiple Decorations".style("multiple", &parser));
63 println!("{}", "Fancy Text".style("fancy", &parser));
64
65 println!("\nSpecial decorations:");
66 println!("{}", "Reversed Text".style("reverse", &parser));
67 println!("{}", "Concealed Text".style("conceal", &parser));
68 println!("{}", "Strikethrough Text".style("strikethrough", &parser));
69 println!("{}", "Framed Text".style("framed", &parser));
70 println!("{}", "Encircled Text".style("encircled", &parser));
71 println!("\nAll decorations combined:");
72 println!("{}", "All Decorations".style("all", &parser));
73}
examples/multiple_sources.rs (line 27)
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}
Sourcepub fn add_style(&mut self, name: &str, style: Style)
pub fn add_style(&mut self, name: &str, style: Style)
Examples found in repository?
examples/multiple_sources.rs (line 72)
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}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Termio
impl RefUnwindSafe for Termio
impl Send for Termio
impl Sync for Termio
impl Unpin for Termio
impl UnwindSafe for Termio
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