1 //! console is a library for Rust that provides access to various terminal
2 //! features so you can build nicer looking command line interfaces. It
3 //! comes with various tools and utilities for working with Terminals and
6 //! Best paired with other libraries in the family:
8 //! * [dialoguer](https://docs.rs/dialoguer)
9 //! * [indicatif](https://docs.rs/indicatif)
13 //! The terminal is abstracted through the `console::Term` type. It can
14 //! either directly provide access to the connected terminal or by buffering
15 //! up commands. A buffered terminal will however not be completely buffered
16 //! on windows where cursor movements are currently directly passed through.
21 //! # fn test() -> Result<(), Box<dyn std::error::Error>> {
23 //! use std::time::Duration;
25 //! use console::Term;
27 //! let term = Term::stdout();
28 //! term.write_line("Hello World!")?;
29 //! thread::sleep(Duration::from_millis(2000));
30 //! term.clear_line()?;
31 //! # Ok(()) } test().unwrap();
34 //! # Colors and Styles
36 //! `console` uses `clicolors-control` to control colors. It also
37 //! provides higher level wrappers for styling text and other things
38 //! that can be displayed with the `style` function and utility types.
43 //! use console::style;
45 //! println!("This is {} neat", style("quite").cyan());
48 //! You can also store styles and apply them to text later:
51 //! use console::Style;
53 //! let cyan = Style::new().cyan();
54 //! println!("This is {} neat", cyan.apply_to("quite"));
57 //! # Working with ANSI Codes
59 //! The crate provids the function `strip_ansi_codes` to remove ANSI codes
60 //! from a string as well as `measure_text_width` to calculate the width of a
61 //! string as it would be displayed by the terminal. Both of those together
62 //! are useful for more complex formatting.
64 //! # Unicode Width Support
66 //! By default this crate depends on the `unicode-width` crate to calculate
67 //! the width of terminal characters. If you do not need this you can disable
68 //! the `unicode-width` feature which will cut down on dependencies.
72 //! By default all features are enabled. The following features exist:
74 //! * `unicode-width`: adds support for unicode width calculations
75 //! * `ansi-parsing`: adds support for parsing ansi codes (this adds support
76 //! for stripping and taking ansi escape codes into account for length
79 pub use crate::kb
::Key
;
80 pub use crate::term
::{user_attended, Term, TermFamily, TermFeatures, TermTarget}
;
81 pub use crate::utils
::{
82 colors_enabled
, colors_enabled_stderr
, measure_text_width
, pad_str
, set_colors_enabled
,
83 set_colors_enabled_stderr
, style
, truncate_str
, Alignment
, Attribute
, Color
, Emoji
, Style
,
87 #[cfg(feature = "ansi-parsing")]
88 pub use crate::ansi
::{strip_ansi_codes, AnsiCodeIterator}
;
96 #[cfg(target_arch = "wasm32")]
101 #[cfg(feature = "ansi-parsing")]