Crates.io | ansi-colors |
lib.rs | ansi-colors |
version | 0.3.0 |
source | src |
created_at | 2019-09-07 13:00:19.669696 |
updated_at | 2019-09-30 10:25:17.109356 |
description | an ansi-coloring sceme crate that allows you to format and color your output |
homepage | |
repository | http://github.com/l-tools/ansi-colors |
max_upload_size | |
id | 162963 |
size | 49,408 |
ansi-colors is a rust crate(library) that should be used to format terminal string outputs. ansi-colors offers the ansi string coloring pallet, and the string formatting pallet in order to help you color, format and beutify you output! ansi-colors works best(for now) with the ubuntu terminal coloring scheme, but it still may work on some windows and mac computers.
:~$ cargo install ansi-colors
:~$ git clone https://github.com/l-tools/ansi-colors ansi-colors
:~$ cd ansi-colors
:~$ cargo build
Add the following to your Cargo.toml:
[dependencies]
ansi-colors = "0.3.0"
First use import the crate:
extern crate ansi_colors;
use ansi_colors::*;
Then you create a new mutable coloured string using an &str primitive type
fn main(){
let mut str1 = ColouredStr("hello ansi");
Next comes the formatting:
str1.blue();
str1.bold();
str1.underline();
Finally you print:
println!("{}",str1);
}
Together it looks like that:
fn main(){
let mut str1 = ColouredStr("hello ansi");
str1.blue();
str1.bold();
str1.underline();
println!("{}",str1);
}
Or this:
fn main(){
let mut str1 = ColouredStr("ERROR!!!!!");
str1.red();
str1.bold();
str1.blink();
str1.underline();
println!("{}",str1);
}
You can use a preset design for special messages:
fn main(){
let mut str1 = ColouredStr("ERROR!!!!!");
str1.to_error();
println!("{}",str1);
}
and this will print it in error format!
This crate is primarily distributed under the terms of the MIT license See LICENSE-MIT for details.