r3blansicolor crate

What does it do?

Rust crate to generate formatted ANSI 256 (8-bit) and truecolor (24-bit) color output to stdout. On macOS, the default Terminal.app does not support truecolor, so ANSI 256 colors are used instead.

This crate performs its own detection of terminal color capability heuristically. And does not use other crates to perform this function.

Here's a screenshot of running the main example on various operating systems:

| Linux screenshot | |:--:| | Running on Linux Tilix |

| Windows screenshot | |:--:| | Running on Windows Terminal |

| macOS screenshot Terminal app | |:--:| | Running on macOS terminal app (note ANSI 256 runtime detection) |

| macOS screenshot iTerm app | |:--:| | Running on macOS terminal app (note Truecolor runtime detection) |

How to use it?

The main struct that we have to consider is AnsiStyledText. It has two fields:

Here's an example.

rust AnsiStyledText { text: "Print a formatted (bold, italic, underline) string w/ ANSI color codes.", style: &[ Style::Bold, Style::Italic, Style::Underline, Style::Foreground(Color::Rgb(50, 50, 50)), Style::Background(Color::Rgb(100, 200, 1)), ], } .println();

Please a look at the main example to get a better idea of how to use this crate.

Build, run, test tasks

Fish scripts are provided to facilitate the above tasks. Here is a list of them.

References

Why make a new crate for this?

Here are some links:

  1. https://github.com/rust-cli/concolor/issues/47
  2. https://docs.rs/anstream/latest/anstream/
  3. https://docs.rs/colorchoice/latest/colorchoice/
  4. https://docs.rs/colorchoice-clap/latest/colorchoice_clap/
  5. https://docs.rs/anstyle-query/latest/anstyle_query/fn.term_supports_ansi_color.html
  6. https://crates.io/crates/anstyle-query
  7. https://docs.rs/supports-color/2.0.0/supports_color/
  8. https://crates.io/crates/ansi_colours
  9. https://crates.io/crates/colored