Crates.io | tempera |
lib.rs | tempera |
version | 0.1.1 |
source | src |
created_at | 2021-10-05 08:14:21.706495 |
updated_at | 2021-10-05 08:22:17.815907 |
description | Template based terminal coloring made really easy. |
homepage | https://sw.cowtech.it/tempera |
repository | https://github.com/ShogunPanda/tempera |
max_upload_size | |
id | 460486 |
size | 25,088 |
Template based terminal coloring made really easy.
Tempera allows to add coloring to terminal in a really easy way.
To colorize strings, simply use the colorize function, passing a vector of styles you want to apply. The list of supported color names correspondes to the keys of CODES variable.
use tempera::*;
fn main() {
println!("{}", colorize("Colorized", &["red"]));
println!("{}", colorize("Colorized", &["red bgBlue"]));
}
To colorize a template using a tagged template syntax, simply use the colorize_template function.
use tempera::*;
fn main() {
println!("{}", colorize_template("{red}This is in red, {green underline}this in green underlined{-}, this in red again.");
}
The template recognizes styles between curly braces (use a single or double opening brace to escape them) and the token {-}
as universal closing tag (which also restores the previous style).
The closing tag at the end of the string can be omitted, since tempera will append the global reset style (\u{1b}[0m
) if any style was set.
If you want to discard styles to be restored, use the {reset}
token.
If you want to define custom styles, use the add_style function.
use tempera::*;
fn main() {
println!("{}", add_style("custom", &["yellow", "bgRed"]).is_ok());
}
tempera supports 256 ANSI codes and 16m RGB colors. Just give it a try:
use tempera::*;
fn main() {
println!("{}", colorize("Colorized", &["ansi:100"]));
println!("{}", colorize("Colorized", &["bgANSI:3,4,5"]));
println!("{}", colorize("Colorized", &["rgb:255,0,0"]));
println!("{}", colorize("Colorized", &["bgRGB:0,255,0"]));
println!("{}", colorize("Colorized", &["hex:#FF0000"]));
println!("{}", colorize("Colorized", &["bgHEX:00FF00"]));
}
ANSI, RGB, and HEX can be used in style definitions and templates as well.
The API documentation can be found here.
Copyright (C) 2021 and above Shogun (shogun@cowtech.it).
Licensed under the ISC license, which can be found at https://choosealicense.com/licenses/isc.