20 releases

✓ Uses Rust 2018 edition

0.9.1 Nov 3, 2019
0.8.0 Aug 23, 2019
0.7.7 Jun 20, 2019
0.7.5 Jan 17, 2019
0.5.0 Jun 28, 2017

#10 in Command-line interface

Download history 15648/week @ 2019-07-21 17117/week @ 2019-07-28 18802/week @ 2019-08-04 18336/week @ 2019-08-11 21743/week @ 2019-08-18 23361/week @ 2019-08-25 23750/week @ 2019-09-01 23677/week @ 2019-09-08 22708/week @ 2019-09-15 25791/week @ 2019-09-22 25375/week @ 2019-09-29 26625/week @ 2019-10-06 27459/week @ 2019-10-13 25585/week @ 2019-10-20 31479/week @ 2019-10-27

104,111 downloads per month
Used in 251 crates (86 directly)

MIT license

60KB
1.5K SLoC

console

console is a library for Rust that provides access to various terminal features so you can build nicer looking command line interfaces. It comes with various tools and utilities for working with Terminals and formatting text.

Best paired with other libraries in the family:

Terminal Access

The terminal is abstracted through the console::Term type. It can either directly provide access to the connected terminal or by buffering up commands. A buffered terminal will however not be completely buffered on windows where cursor movements are currently directly passed through.

Example usage:

use std::thread;
use std::time::Duration;

use console::Term;

let term = Term::stdout();
term.write_line("Hello World!")?;
thread::sleep(Duration::from_millis(2000));
term.clear_line()?;

Colors and Styles

console uses clicolors-control to control colors. It also provides higher level wrappers for styling text and other things that can be displayed with the style function and utility types.

Example usage:

use console::style;

println!("This is {} neat", style("quite").cyan());

You can also store styles and apply them to text later:

use console::Style;

let cyan = Style::new().cyan();
println!("This is {} neat", cyan.apply_to("quite"));

Working with ANSI Codes

The crate provids the function strip_ansi_codes to remove ANSI codes from a string as well as measure_text_width to calculate the width of a string as it would be displayed by the terminal. Both of those together are useful for more complex formatting.

Unicode Width Support

By default this crate depends on the unicode-width crate to calculate the width of terminal characters. If you do not need this you can disable the unicode-width feature which will cut down on dependencies.

License: MIT

Dependencies

~1.5MB
~44K SLoC