| Crates.io | termio |
| lib.rs | termio |
| version | 0.1.0 |
| created_at | 2025-03-18 16:49:52.291167+00 |
| updated_at | 2025-03-18 16:49:52.291167+00 |
| description | A Rust library for styling terminal output with CSS-like syntax |
| homepage | |
| repository | https://github.com/KirillFurtikov/termio |
| max_upload_size | |
| id | 1596857 |
| size | 78,005 |
A Rust library for styling terminal output with CSS-like syntax. Termio allows you to create beautiful and consistent terminal output using familiar CSS-like syntax.
Add this to your Cargo.toml:
[dependencies]
termio = "0.1.0"
fn main() {
let mut termio = Termio::new();
// Parse CSS-like syntax from a string
let css = r#"
@element "header" {
color: blue;
background: black;
decoration: bold;
padding: 1;
}
"#;
termio.parse(css).unwrap();
// Style text using the parsed styles
println!("{}", "This is a header".style("header", &termio));
}
Termio provides convenient macro TCSS (Terminal CSS):
tcss! macrolet parser = tcss! {
"header" => {
fg: Color::Cyan,
bg: Color::Black,
decoration: vec![Decoration::Bold],
padding: 2,
border_color: Color::Cyan,
border_style: BorderStyle::Rounded
},
"warning" => {
fg: Color::Yellow,
bg: Color::Red,
decoration: vec![Decoration::Bold, Decoration::Italic],
border_style: BorderStyle::Dashed,
border_color: Color::Yellow,
padding: 1
}
};
println!("{}", "Welcome!".style("header", &parser));
println!("{}", "Warning!".style("warning", &parser));
style! macroFor single style definitions:
let style = style! {
fg: Color::Green,
bg: Color::Black,
decoration: vec![Decoration::Bold],
padding: 1,
margin: 1,
border_color: Color::Yellow,
border_style: BorderStyle::Rounded
};
@element "colored" {
color: i-red; // Intense red
background: black; // Black background
color: rgb(255, 0, 0); // RGB red
color: 196; // Color code 196 (red)
}
@element "decorated" {
decoration: bold italic underline;
}
@element "spaced" {
padding: 1;
margin: 1;
padding-top: 2;
margin-bottom: 2;
}
@element "bordered" {
border: rounded yellow;
border: dashed i-red;
border: solid green;
}
The crate includes several examples demonstrating different features:
basic - Basic styling examples
advanced - Advanced UI components like cards and buttons
colors - Different color formats and combinations
decorations - Text decoration options
fluent - Fluent interface for direct styling without TCSS
borders - Different border styles and customizations
emoji - Using emoji with styled text
...and other
Run examples with:
cargo run --example basic
Termio fully supports emoji characters in styled text. You can use emoji within any styled element:
use terminal_css::prelude::*;
// Basic emoji with color
println!("{}", "🚀 Rocket launch!".color(Color::Blue));
// Emoji with borders and padding
println!("{}", "🎉 Celebration 🎊"
.padding(1)
.border(BorderStyle::Rounded)
.border_color(Color::Green));
// Emoji list with styling
let items = vec![
"🍎 Apple",
"🍌 Banana",
"🍇 Grapes"
].join("\n");
println!("{}", items
.color(Color::Magenta)
.padding(1)
.border(BorderStyle::Dashed));
Run the emoji example with:
cargo run --example emoji
Termio supports multiple color formats:
red, green, blue, etc.i-red, i-green, i-blue, etc.rgb(255, 0, 0)196 (for 256-color terminals)Available text decorations:
bolditalicunderlineoverlineblinkreversehiddenThe library supports multiple value formats for padding and margin:
padding: 1;
margin: 1;
padding: 1 2;
margin: 1 2;
padding: 1 2 3 4;
margin: 1 2 3 4;
You can also set individual sides:
padding-top: 1;
padding-bottom: 2;
padding-left: 3;
padding-right: 4;
margin-top: 1;
margin-bottom: 2;
margin-left: 3;
margin-right: 4;
Termio provides two ways to style text:
// Define styles using CSS-like syntax
let mut tcss = Termio::new();
tcss.parse(r#"
@element "warning" {
color: yellow;
background: black;
decoration: bold;
padding: 1;
border: solid red;
}
"#).unwrap();
// Apply the style to text
let styled_text = "Warning message".style("warning", &tcss);
println!("{}", styled_text);
// Style text directly using method chaining
let styled_text = "Warning message"
.color(Color::Yellow)
.bg(Color::Black)
.decoration(Decoration::Bold)
.padding(1)
.border(BorderStyle::Solid)
.border_color(Color::Red);
println!("{}", styled_text);
Available styling methods:
color(Color) - Set the text colorbg(Color) - Set the background colordecoration(Decoration) - Add a text decorationpadding(u8) - Set padding on all sidespadding_trbl(u8, u8, u8, u8) - Set padding for top, right, bottom, leftmargin(u8) - Set margin on all sidesborder(BorderStyle) - Set the border styleborder_color(Color) - Set the border colorThis project is licensed under the MIT License.