40 releases

0.15.8 Jan 9, 2024
0.15.7 May 21, 2023
0.15.5 Jan 14, 2023
0.15.3 Dec 27, 2022
0.5.0 Jun 28, 2017

#10 in Command-line interface

Download history 468576/week @ 2023-11-28 465220/week @ 2023-12-05 438436/week @ 2023-12-12 367850/week @ 2023-12-19 247656/week @ 2023-12-26 431160/week @ 2024-01-02 486298/week @ 2024-01-09 552404/week @ 2024-01-16 525555/week @ 2024-01-23 535745/week @ 2024-01-30 552483/week @ 2024-02-06 522409/week @ 2024-02-13 547656/week @ 2024-02-20 570022/week @ 2024-02-27 579447/week @ 2024-03-05 161402/week @ 2024-03-12

1,942,940 downloads per month
Used in 3,614 crates (802 directly)

MIT license

115KB
3K SLoC

console

Build Status Crates.io License rustc 1.56.0 Documentation

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 automaticaly detects when to use colors based on the tty flag. 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 provides 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

~0–11MB
~81K SLoC