7 releases (2 stable)

Uses old Rust 2015

1.0.1 Aug 23, 2019
1.0.0 Dec 23, 2018
0.3.2 Dec 23, 2018
0.3.0 Nov 22, 2018
0.1.0 Apr 25, 2017

#358 in Command-line interface

Download history 3694/week @ 2023-11-18 3847/week @ 2023-11-25 3181/week @ 2023-12-02 3514/week @ 2023-12-09 3334/week @ 2023-12-16 2623/week @ 2023-12-23 2288/week @ 2023-12-30 2955/week @ 2024-01-06 3580/week @ 2024-01-13 3292/week @ 2024-01-20 3573/week @ 2024-01-27 3459/week @ 2024-02-03 3581/week @ 2024-02-10 4478/week @ 2024-02-17 3012/week @ 2024-02-24 4033/week @ 2024-03-02

15,660 downloads per month
Used in 157 crates (2 directly)

MIT license

10KB
161 lines

clicolors-control

A utility library for Rust that acts as a common place to control the colorization for CLI tools.


lib.rs:

This library implements basic clicolor control for other rust libraries. The idea is that other crates can depend on this to have a central source of truth for the colorization of command line applications.

it follows the cli color specification:

  • CLICOLOR != 0: ANSI colors are supported and should be used when the program isn't piped.
  • CLICOLOR == 0: Don't output ANSI color escape codes.
  • CLICOLOR_FORCE != 0: ANSI colors should be enabled no matter what.

Example Usage

extern crate clicolors_control;

pub fn main() {
    if clicolors_control::colors_enabled() {
        println!("\x1b[36mThis is colored text.\x1b[0m");
    } else {
        println!("Someone turned off the colors :()")
    }
}

Controlling Colors

Colors can be turned on and off for the current process with set_colors_enabled.

Windows 10 Console

The default behavior of this crate is to reconfigure the windows console to enable the VT100 emulation when available the first time colors are requested. This will only work on recent Windows 10 versions. This feature can be disabled by removing the default terminal_autoconfig feature.

The terminal can be manually configured for colors by calling configure_terminal()

Dependencies

~240KB