ANSI terminal styling: colors & text styles (truecolor).

pub fn example_usage() -> Unit {
// 构造一个带样式的文本片段并打印到标准输出
let s = styl("hello style_print").color(Color::Red).bg_color(Color::Blue).italic().bold();
styl_print(s)
}pub fn example_rgb() -> Unit {
// 使用 rgb(r,g,b) 构造 Color::RGB
let orange = rgb(255U, 165U, 0U);
let s = styl("orange text").color(orange).bold();
styl_print(s)
}// 前景色、背景色、加粗、斜体、下划线、反转
pub fn usage_all_styles() -> Unit {
let s = styl("mixed styles").color(Color::Yellow).bg_color(Color::Magenta).bold().italic().underline().reverse();
styl_print(s)
}
// 只设置前景色
pub fn usage_fg_only() -> Unit {
styl_print(styl("foreground only").color(Color::Cyan))
}
// 只设置背景色
pub fn usage_bg_only() -> Unit {
styl_print(styl("background only").bg_color(Color::BrightBlack))
}
// 链式组合与下一段拼接(next)
pub fn usage_chain() -> Unit {
let a = styl("one").color(Color::Red)
let b = styl(" two").color(Color::Green).bold()
let c = styl(" three").bg_color(Color::Blue).italic()
styl_print(a)
styl_print(b)
styl_print(c)
}
// 使用真彩色 RGB
pub fn usage_rgb_truecolor() -> Unit {
let c = rgb(12U, 34U, 56U)
styl_print(styl("truecolor").color(c))
}
// 获取不可解释的 ANSI 可见形式
pub fn usage_show_escapes() -> Unit {
let s = styl("visible esc").color(Color::Red)
println(s.to_ansi_not_styl())
}pub(all) enum Color {
Black
Red
Green
Yellow
Blue
Magenta
Cyan
White
BrightBlack
BrightRed
BrightGreen
BrightYellow
BrightBlue
BrightMagenta
BrightCyan
BrightWhite
RGB(RGB)
}ANSI terminal styling: colors & text styles (truecolor).