Termio
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.
Features
- CSS-like syntax for styling terminal text
- Support for colors (basic, intense, RGB, and color codes)
- Text decorations (bold, italic, underline, etc.)
- Padding and margins with support for multiple values
- Border styles and colors
- Easy-to-use API with method chaining
- Zero dependencies
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
Macro Support
Termio provides convenient macro TCSS (Terminal CSS):
Using the tcss! macro
let parser = tcss! ;
println!;
println!;
Using the style! macro
For single style definitions:
let style = style! ;
Examples
Colors
@element "colored"
Decorations
@element "decorated"
Padding and Margins
@element "spaced"
Borders
@element "bordered"
Available Examples
The crate includes several examples demonstrating different features:
basic- Basic styling examplesadvanced- Advanced UI components like cards and buttonscolors- Different color formats and combinationsdecorations- Text decoration optionsfluent- Fluent interface for direct styling without TCSSborders- Different border styles and customizationsemoji- Using emoji with styled text- ...and other
Run examples with:
Emoji Support
Termio fully supports emoji characters in styled text. You can use emoji within any styled element:
use *;
// Basic emoji with color
println!;
// Emoji with borders and padding
println!;
// Emoji list with styling
let items = vec!.join;
println!;
Run the emoji example with:
Color Support
Termio supports multiple color formats:
- Basic colors:
red,green,blue, etc. - Intense colors:
i-red,i-green,i-blue, etc. - RGB colors:
rgb(255, 0, 0) - Color codes:
196(for 256-color terminals)
Text Decorations
Available text decorations:
bolditalicunderlineoverlineblinkreversehidden- And more...
Padding and Margin Support
The library supports multiple value formats for padding and margin:
- Single value (applies to all sides):
padding: 1;
margin: 1;
- Two values (first for vertical sides, second for horizontal):
padding: 1 2;
margin: 1 2;
- Four values (in order: top, right, bottom, left):
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;
Styling Methods
Termio provides two ways to style text:
1. Using predefined styles
// Define styles using CSS-like syntax
let mut tcss = new;
tcss.parse.unwrap;
// Apply the style to text
let styled_text = "Warning message".style;
println!;
2. Using the fluent interface
// Style text directly using method chaining
let styled_text = "Warning message"
.color
.bg
.decoration
.padding
.border
.border_color;
println!;
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 color
License
This project is licensed under the MIT License.