#api #terminal-colors #graphics #terminal-graphics #cli

ansi-colors

an ansi-coloring sceme crate that allows you to format and color your output

4 releases (2 breaking)

0.3.0 Sep 30, 2019
0.2.0 Sep 10, 2019
0.1.1 Sep 7, 2019
0.1.0 Sep 7, 2019

#322 in GUI

Download history 18/week @ 2024-03-11 13/week @ 2024-03-18 19/week @ 2024-03-25 27/week @ 2024-04-01 12/week @ 2024-04-08 13/week @ 2024-04-15 16/week @ 2024-04-22 47/week @ 2024-04-29 36/week @ 2024-05-06 43/week @ 2024-05-13 24/week @ 2024-05-20 7/week @ 2024-05-27 31/week @ 2024-06-03 22/week @ 2024-06-10 10/week @ 2024-06-17 25/week @ 2024-06-24

88 downloads per month
Used in 2 crates

MIT license

35KB
351 lines

ansi-colors

CircleCI crates.io License: MIT doc.rs

What is it and what is it for?

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.

How to install it?

you can use cargo(the preferable and much easier and safe way):

:~$ cargo install ansi-colors

or you can clone this repository:

:~$ git clone https://github.com/l-tools/ansi-colors ansi-colors
:~$ cd ansi-colors
:~$ cargo build

Usage

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!

If you want to checkout the crate further that you should take a look in the examples folder.

Currently being developed:

  1. the ability to use them in the same row(str1.blue().bold() for example).
  2. more high level formatting options(json parsin, XML parsing and such).
  3. integrating with termi-graphics(my other crate), and creating some higher level api for the terminal graphics.

License

This crate is primarily distributed under the terms of the MIT license See LICENSE-MIT for details.

No runtime deps