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:
| |
|:--:|
| Running on Linux Tilix |
| |
|:--:|
| Running on Windows Terminal |
| |
|:--:|
| Running on macOS Terminal app (note ANSI 256 runtime detection) |
| |
|:--:|
| Running on macOS iTerm app (note Truecolor runtime detection) |
The main struct that we have to consider is AnsiStyledText
. It has two fields:
text
- the text to print.style
- a list of styles to apply to the text.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.
🌠In order for these to work you have to install the Rust toolchain and the following
crates cargo-cache
, cargo-watch
, flamegraph
, and nu
using these instructions:
rustup
by following the instructions
here.cargo-cache
using cargo install cargo-cache
.cargo-watch
using cargo install cargo-watch
.flamegraph
using cargo install flamegraph
.nu
using cargo install nu
.The script to run is run.nu
. Make sure to mark it executable. It works on Linux, macOS, and
Windows. Please make sure that the pre-requisites are installed.
./run.nu build
./run.nu clean
./run.nu run
./run.nu run-release
./run.nu run-flamegraph
./run.nu test
./run.nu clippy
./run.nu docs
./run.nu serve-docs
. This is only useful if you SSH into a remote machine via
VSCode (where you build and serve the docs) and want to view the docs in a browser on
your local machine../run.nu upgrade-deps
./run.nu rustfmt
The following commands will watch for changes in the source folder and re-run:
./run.nu watch-run
./run.nu watch-all-tests
./run.nu watch-one-test <test_name>
./run.nu watch-clippy
./run.nu watch-macro-expansion-one-test <test_name>
Here are some links: