2 releases (1 stable)

1.0.0 Mar 2, 2024
0.1.0 May 8, 2023

#611 in Command-line interface

Download history 14/week @ 2024-01-08 39/week @ 2024-02-19 186/week @ 2024-02-26 30/week @ 2024-03-04 27/week @ 2024-03-11 5/week @ 2024-03-18 21/week @ 2024-03-25 48/week @ 2024-04-01 34/week @ 2024-04-15 21/week @ 2024-04-22

105 downloads per month
Used in logly

MIT license

10KB
104 lines

colorama

A simple way to colorize the output of your cli application.

This crate contains a single trait Colored that is implemented for the String type. Calling .color("red"), .background("green") or .style("bold") will wrap your string with the corresponding ANSI escape sequence.

Different styles can be concatenated together:

use colorama::Colored;

let mut s = String::from("colorama");

s.color("red").background("green").style("bold");

println!("{}", s);

Unknown color / style names are silently ignored.

Note: This package does not check if the program is running inside a terminal or if it is called via pipes. If you want this functionality, check out termcolor, colored and / or atty.


lib.rs:

colorama

A simple way to colorize the output of your cli application.

This crate contains a single trait Colored that is implemented for the String type. Calling .color("red"), .background("green") or .style("bold") will wrap your string with the corresponding ANSI escape sequence.

Different styles can be concatenated together:

use colorama::Colored;

let mut s = String::from("colorama");

s.color("red").background("green").style("bold");

println!("{}", s);
assert_eq!(s, "\x1b[1m\x1b[42m\x1b[31mcolorama\x1b[0m\x1b[0m\x1b[0m");

Unknown color / style names are silently ignored.

Note: This package does not check if the program is running inside a terminal or if it is called via pipes. If you want this functionality, check out termcolor, colored and / or atty.

No runtime deps