3 个版本

0.1.3 2023 年 9 月 17 日
0.1.2 2023 年 9 月 16 日
0.1.1 2023 年 9 月 16 日
0.1.0 2023 年 9 月 16 日

过程宏 中排名第 1092

Download history 23/week @ 2024-03-11 19/week @ 2024-03-18 21/week @ 2024-03-25 32/week @ 2024-04-01 11/week @ 2024-04-08 13/week @ 2024-04-15 22/week @ 2024-04-22 14/week @ 2024-04-29 17/week @ 2024-05-06 12/week @ 2024-05-13 15/week @ 2024-05-20 15/week @ 2024-05-27 17/week @ 2024-06-03 15/week @ 2024-06-10 10/week @ 2024-06-17 22/week @ 2024-06-24

每月下载 65
5 crate 使用

MIT 许可证

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