3 releases

0.1.3 Sep 17, 2023
0.1.2 Sep 16, 2023
0.1.1 Sep 16, 2023
0.1.0 Sep 16, 2023

#14 in #coloring

Download history 12/week @ 2024-07-20 19/week @ 2024-07-27 12/week @ 2024-08-03 8/week @ 2024-08-10 4/week @ 2024-08-17 8/week @ 2024-08-24 11/week @ 2024-08-31 16/week @ 2024-09-07 10/week @ 2024-09-14 25/week @ 2024-09-21 15/week @ 2024-09-28 4/week @ 2024-10-05 19/week @ 2024-10-12 7/week @ 2024-10-19 5/week @ 2024-10-26 20/week @ 2024-11-02

51 downloads per month
Used in 5 crates

MIT license

15KB
234 lines

comat

Small terminal coloring library, using proc macros. See lib.rs for more information.

Usage

use comat::cprintln;
cprintln!("{red}C{yellow}O{green}L{blue}O{magenta}R{reset}!");

lib.rs:

smart crate for terminal coloring.

uses macros instead of methods.

usage

heres how it works:

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));

why you should use comat instead of {yansi, owo_colors, colored, ..}

  • no method pollution, your intellisense remains fine
  • compact: shorter than even raw ansi. see:
    cprint!("{thing:red}.");
    
    vs
    print!("\x1b[0;34;31m{thing}\x1b[0m.");
    
    vs
    print!("{}.", thing.red());
    
  • intuitive: you dont have to
    println!("{} {} {}", thing1.red().on_blue(), thing2.red().on_blue(), thing3.italic().yellow());
    
    instead, simply
    cprintln!("{red}{on_blue}{thing1} {thing2} {thing3:italic,yellow}");
    

syntax

{{ gives you a {, to get a {{ use {{{{.

{color} adds that effect/color to the string. it does not reset afterwards.

if the color inside a {} is not found, it doesnt touch the block, for convenience.

{thing:color} will reset everything before the block, color it, and reset that color. similar to thing.color() with other libs. it can also contain more than one color: {thing:yelow,italic,on_red}

colors

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

Dependencies

~240–690KB
~16K SLoC