Crates.io | recolored |
lib.rs | recolored |
version | 1.9.3 |
source | src |
created_at | 2020-04-16 05:43:29.283957 |
updated_at | 2020-04-16 05:43:29.283957 |
description | A fork of colored: the most simple way to add colors in your terminal |
homepage | https://github.com/tforgione/colored |
repository | https://github.com/tforgione/colored |
max_upload_size | |
id | 230686 |
size | 89,987 |
This is a fork of colored. It is named recolored in order to be usable on crates.io.
The following is the original README, if you want to use this fork, you will
need to replace colored
by recolored
.
Coloring terminal so simple, you already know how to do it!
"this is blue".blue();
"this is red".red();
"this is red on blue".red().on_blue();
"this is also red on blue".on_blue().red();
"bright colors are welcome as well".on_bright_blue().bright_red();
"or any rgb color".true_color(171, 205, 239);
"or any hexadecimal color".hex_color(0xabcdef);
"or use colors from the palette".palette(36);
"you can also make bold comments".bold();
println!("{} {} {}", "or use".cyan(), "any".italic().yellow(), "string type".cyan());
"or change advice. This is red".yellow().blue().red();
"or clear things up. This is default color and style".red().bold().clear();
"purple and magenta are the same".purple().magenta();
"and so are normal and clear".normal().clear();
"you can specify color by string".color("blue").on_color("red");
String::from("this also works!").green().bold();
format!("{:30}", "format works as expected. This will be padded".blue());
format!("{:.3}", "and this will be green but truncated to 3 chars".green());
Add this in your Cargo.toml
:
[dependencies]
colored = "1.9"
and add this to your lib.rs
or main.rs
:
extern crate recolored; // not needed in Rust 2018
use recolored::*;
// test the example with `cargo run --example most_simple`
fn main() {
// TADAA!
println!("{} {} !", "it".green(), "works".blue().bold());
}
CLICOLOR
/CLICOLOR_FORCE
behavior (see the specs)NO_COLOR
behavior (see the specs)Bright colors: prepend the color by bright_
. So easy.
Background colors: prepend the color by on_
. Simple as that.
Bright Background colors: prepend the color by on_bright_
. Not hard at all.
Any 8-bit palette color: use palette(u8)
. Super simple.
Any RGB color: use true_color(u8, u8, u8)
. Really easy.
Any hexadecimal color: use hex_color(0xABCDEF)
. Far from difficult.
You can clear color and style anytime by using normal()
or clear()
As Color
implements FromStr
, From<&str>
, and From<String>
, you can easily cast a string into a color like that:
// the easy way
"blue string yo".color("blue");
// this will default to white
"white string".color("zorglub");
// the safer way via a Result
let color_res : Result<Color, ()> = "zorglub".parse();
"red string".color(color_res.unwrap_or(Color::Red));
If you want to disable any coloring at compile time, you can simply do so by
using the no-color
feature.
For example, you can do this in your Cargo.toml
to disable color in tests:
[features]
# this effectively enable the feature `no-color` of colored when testing with
# `cargo test --feature dumb_terminal`
dumb_terminal = ["colored/no-color"]
You can use have even finer control by using the
colored::control::set_override
method.
Use the install instructions located here
docker build -t colored_image .
docker run --rm -it -v "$PWD":/src -u `id -u`:`id -g` colored_image /bin/bash -c "cargo build"
docker run --rm -it -v "$PWD":/src -u `id -u`:`id -g` colored_image /bin/bash -c "cargo test"
This library wouldn't have been the same without the marvelous ruby gem colored.
Thanks for the ansi_term crate for providing a reference implementation, which greatly helped making this crate output correct strings.
Mozilla Public License 2.0. See the LICENSE file at the root of the repository.
In non legal terms it means that: