#hex-color #color #hex #ansi #ansi-term #terminal

ansi-hex-color

Color the text on the terminal with ANSI and hex-code

2 releases

0.1.1 Apr 30, 2021
0.1.0 Apr 29, 2021

#1065 in Command-line interface

49 downloads per month
Used in 2 crates

MIT license

7KB
82 lines

ansi-hex-color

anti-hex-color is a Rust library which color (ANSI 256-color) the given text in terminal.
Since you can specify the color with hex code, you can easily color it like CSS.

Install

in Cargo.toml

[dependencies]
ansi-hex-color = "0.1.1"

Usage

use ansi_hex_color;

fn main () {
	let foreground = "#FF0000";
	let background = "#004082";
	let txt = "Hello world";
	
	let colored_txt = ansi_hex_color::colored(
		foreground, background, txt);
	
	println!("{}", colored_txt);
}

Default style

If you put "" or a string other than hex code in the first and second arguments, the text will be default style(white text, no background).

let colored_txt = ansi_hex_color::colored("", "", "This is a default style.");

lib.rs:

A library which color text from hex code.

Usage

   use ansi_hex_color;

fn main() {
	let foreground = "#FF0000";
   	let background = "#004082";
	let txt = "Hello world";
	let colored_txt = ansi_hex_color::colored(
		foreground, background, txt);

	println!("{}", colored_txt);
}

Dependencies

~8MB
~138K SLoC