clicolors_control/lib.rs
1//! This library implements basic [clicolor](http://bixense.com/clicolors/) control for
2//! other rust libraries. The idea is that other crates can depend on this to have a
3//! central source of truth for the colorization of command line applications.
4//!
5//! it follows the cli color specification:
6//!
7//! * `CLICOLOR != 0`: ANSI colors are supported and should be used when the program isn't piped.
8//! * `CLICOLOR == 0`: Don't output ANSI color escape codes.
9//! * `CLICOLOR_FORCE != 0`: ANSI colors should be enabled no matter what.
10//!
11//! ## Example Usage
12//!
13//! ```rust
14//! extern crate clicolors_control;
15//!
16//! pub fn main() {
17//! if clicolors_control::colors_enabled() {
18//! println!("\x1b[36mThis is colored text.\x1b[0m");
19//! } else {
20//! println!("Someone turned off the colors :()")
21//! }
22//! }
23//! ```
24//!
25//! ## Controlling Colors
26//!
27//! Colors can be turned on and off for the current process with `set_colors_enabled`.
28//!
29//! ## Windows 10 Console
30//!
31//! The default behavior of this crate is to reconfigure the windows console to enable the
32//! VT100 emulation when available the first time colors are requested. This will only work
33//! on recent Windows 10 versions. This feature can be disabled by removing the default
34//! `terminal_autoconfig` feature.
35//!
36//! The terminal can be manually configured for colors by calling `configure_terminal()`
37
38#[cfg(windows)]
39extern crate atty;
40#[cfg(unix)]
41extern crate libc;
42#[cfg(windows)]
43extern crate winapi;
44#[macro_use]
45extern crate lazy_static;
46
47mod common;
48pub mod terminfo;
49#[cfg(unix)]
50mod unix;
51#[cfg(windows)]
52mod windows;
53#[cfg(all(not(unix), not(windows)))]
54mod generic;
55
56pub use common::{colors_enabled, configure_terminal, set_colors_enabled};