3 个版本
0.1.3 | 2023 年 9 月 17 日 |
---|---|
0.1.2 | 2023 年 9 月 16 日 |
0.1.1 | 2023 年 9 月 16 日 |
0.1.0 |
|
在 过程宏 中排名第 1092
每月下载 65 次
被 5 crate 使用
15KB
234 行
comat
小型终端着色库,使用过程宏。有关更多信息,请参阅 lib.rs。
用法
use comat::cprintln;
cprintln!("{red}C{yellow}O{green}L{blue}O{magenta}R{reset}!");
lib.rs
:
智能终端着色 crate。
使用宏而不是方法。
用法
以下是它是如何工作的
cprintln!("the traffic light is {bold_red}red.{reset}");
cprintln!("the traffic light will be {green}green{reset} at {:?}.", Instant::now() + Duration::from_secs(40));
为什么你应该使用 comat 而不是 {yansi
, owo_colors
, colored
, ..}
- 无方法污染,你的智能感应仍然良好
- 紧凑:甚至比原始 ansi 短。见
对比cprint!("{thing:red}.");
对比print!("\x1b[0;34;31m{thing}\x1b[0m.");
print!("{}.", thing.red());
- 直观:你不必
而是,只需println!("{} {} {}", thing1.red().on_blue(), thing2.red().on_blue(), thing3.italic().yellow());
cprintln!("{red}{on_blue}{thing1} {thing2} {thing3:italic,yellow}");
语法
{{
给你一个 {
,要得到 {{
使用 {{{{
。
{color}
将该效果/颜色添加到字符串。之后不会重置。
如果 {}
中找不到颜色,则不会触摸该块,以便方便。
{thing:color}
将重置块之前的一切,着色它,并重置该颜色。类似于 thing.color()
在其他库中。它也可以包含多种颜色:{thing:yelow,italic,on_red}
颜色
black
red
green
yellow
blue
magenta
cyan
white
default
bold_black
bold_red
bold_green
bold_yellow
bold_blue
bold_magenta
bold_cyan
bold_white
bold_default
on_black_bold
on_red_bold
on_green_bold
on_yellow_bold
on_blue_bold
on_magenta_bold
on_cyan_bold
on_white_bold
on_default_bold
on_black
on_red
on_green
on_yellow
on_blue
on_magenta
on_cyan
on_white
on_default
reset
dim
italic
underline
blinking
hide
strike
bold
依赖项
~295–750KB
~18K SLoC