colored-macro

Crates.iocolored-macro
lib.rscolored-macro
version0.2.0
sourcesrc
created_at2023-04-19 12:03:13.022188
updated_at2023-05-15 10:00:16.493291
descriptionA macro to make colored text in the terminal using XML-like syntax
homepage
repositoryhttps://github.com/Jamalam360/colored-macro
max_upload_size
id843494
size6,871
Jamalam (Jamalam360)

documentation

README

Colored Macro

Colored macro is a Rust crate for creating colored and formatted strings using ANSI codes in a readable way. It uses XML-like syntax:

<red>red text</red> <bold>bold text</bold> <green>{fmt_expr}</green>

The Problem

With current crates, messages quickly become hard to quickly understand at a glance. This is best explained with an example:

println!("[{}] ({}): {}", level.green(), timestamp.blue(), message.bold());

You can see that even with a simple message, the format string becomes hard to quickly understand, compared to the equivalent using this crate:

println!("{}", colored!("[<green>{level}</green>] (<blue>{timestamp}</blue>): <bold>{message}</bold>"));

Documentation

The following styles are available:

  • Any CSS named color, as long as their alpha is 1.
  • Any RGB color in the regular CSS format, as long as its alpha is 1 (e.g. rgb(10, 12, 200), #0012G4).
  • reset (resets current styles)
  • bold
  • dim
  • italic
  • underline
  • blink
  • reverse
  • hidden
  • strikethrough

Styles can also be nested:

colored_macro::colored!("<red>all red <yellow>yellow <blue>now to blue</blue> back to yellow</yellow> back to red</red>")

NO_COLOR Support

The NO_COLOR environment variable is supported if the no-color feature is enabled.

Output of above code

Commit count: 17

cargo fmt