| Crates.io | sty |
| lib.rs | sty |
| version | 0.3.1 |
| created_at | 2024-03-19 20:48:40.7252+00 |
| updated_at | 2024-03-21 09:05:02.919676+00 |
| description | Color terminal outputs in a minimal, macro-based, and dead simple way. |
| homepage | |
| repository | https://github.com/leecade/sty |
| max_upload_size | |
| id | 1179678 |
| size | 35,258 |
| Code | Backgroud | Bright | Bright background | |
|---|---|---|---|---|
| $\mathbb{\color{black}{■}}$ | black |
bg_black |
||
| $\mathbb{\color{gray}{■}}$ | gray |
bg_gray |
||
| $\mathbb{\color{white}{■}}$ | white |
bg_white |
white_bright |
bg_white_bright |
| $\mathbb{\color{red}{■}}$ | red |
bg_red |
red_bright |
bg_red_bright |
| $\mathbb{\color{green}{■}}$ | green |
bg_green |
green_bright |
bg_green_bright |
| $\mathbb{\color{yellow}{■}}$ | yellow |
bg_yellow |
yello_bright |
bg_yellow_bright |
| $\mathbb{\color{blue}{■}}$ | blue |
bg_blue |
blue_bright |
bg_blue_bright |
| $\mathbb{\color{magenta}{■}}$ | magenta |
bg_magenta |
magenta_bright |
bg_magenta_bright |
| $\mathbb{\color{cyan}{■}}$ | cyan |
bg_cyan |
cyan_bright |
bg_cyan_bright |
bolditalicunderlinestrikethroughoverlinediminversehiddenreset
[red, bold, underline].std::fmt::Display trait are supported, offering wide-ranging adaptability.tty detection: Avoids styling when the tty lacks color support, Use set_color_enabled for manual enable control.This crate works with Cargo. Add the following to your Cargo.toml dependencies section:
[dependencies]
sty = "0.3"
use sty::{
sty,
style::{red, underline},
};
// or
// use sty::{ sty, red, underline };
println!("{}", sty!("Hello world!", [red]));
// Use `sty!` macro for combination of multiple styles
println!("{}", sty!("Hello world!", [red, underline]));
// Use `sty!` macro for multiple input types
println!("{}", sty!(123, [red, underline]));
// Use style function is simple for `&str` input
println!("{}", red("Hello world!"));
println!("{}", underline(&red("Hello world!")));
[!TIP] In style combinations, the styles that are specified later take precedence, For example:
use sty::{ sty, style::* };
sty!("str", [red, green, blue]); // blue
sty!("str", [red, underline, reset]); // reset
[!TIP] If
ttyenvironment does not support color, default output will be printed without any styling, Useset_color_enabledfor manual enable control, For example:
use sty::{ set_color_enabled, is_color_enabled, sty, style::* };
let enabled = is_color_enabled();
set_color_enabled(false);
sty!("123", [red]); // no color
set_color_enabled(true);
sty!("123", [red]); // red
set_color_enabled(enabled);
sty! MacroThe sty! macro is a powerful utility conveniently used to apply a collection of style manipulations to your input. This macro allows you to seamlessly incorporate text properties with an intuitive syntax.
use sty::{ sty, style::{red, underline} };
println!("{}", sty!("Hello world!", [red, underline]));
In this example, red and underline are both style transformations, and the sty! macro returns a newly styled text instance with all these styling elements applied. Multiple styles can be applied simultaneously, and the output will be a combination of all.
For any type that has implemented the std::fmt::Display trait, like:
&strStringnumbers(usize, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, f32, f64)boolEach style function can be combine with sty! macro or used separately, for example:
use sty::{
sty,
style::{red, underline},
};
// or
// use sty::{ sty, red, underline };
sty!("Hello world!", [red, underline]);
// or
red("Hello world!");
[!TIP] The standalone style function only supports
&strinput type.
All style functions are as follows:
Modifiers
resetbolddimitalicunderlineoverlineinversehiddenstrikethroughForeground colors
blackredgreenyellowbluemagentacyanwhitegrayBackground colors
bg_blackbg_redbg_greenbg_yellowbg_bluebg_magentabg_cyanbg_whitebg_grayBright foreground colors
red_brightgreen_brightyellow_brightblue_brightmagenta_brightcyan_brightwhite_brightBright background colors
bg_red_brightbg_green_brightbg_yellow_brightbg_blue_brightbg_magenta_brightbg_cyan_brightbg_white_bright