#cli #color #no-std #terminal #ansi-term

no-std owo-colors

Zero-allocation terminal colors that’ll make people go owo

18 releases (stable)

3.0.1 Oct 12, 2021
2.1.0 Sep 22, 2021
2.0.0 Mar 28, 2021
1.4.2 Mar 25, 2021
0.0.0 Aug 25, 2020

#15 in Command-line interface

Download history 17944/week @ 2021-07-07 15536/week @ 2021-07-14 17147/week @ 2021-07-21 20372/week @ 2021-07-28 24074/week @ 2021-08-04 18472/week @ 2021-08-11 21801/week @ 2021-08-18 24716/week @ 2021-08-25 22571/week @ 2021-09-01 25150/week @ 2021-09-08 27830/week @ 2021-09-15 30736/week @ 2021-09-22 31060/week @ 2021-09-29 30552/week @ 2021-10-06 31226/week @ 2021-10-13 25223/week @ 2021-10-20

101,981 downloads per month
Used in 179 crates (27 directly)

MIT license

110KB
2.5K SLoC

Colors

Current Crates.io Version docs-rs MSRV 1.51+

A zero-allocation no_std-compatible zero-cost way to add color to your Rust terminal to make people go owo.

Supports:

  • All std/core formatters
  • Optional checking for if a terminal supports colors
    • Enabled for CI
    • Disabled by default for non-terminal outputs
    • Overridable by NO_COLOR/FORCE_COLOR environment variables
  • Dependency-less by default
  • Hand picked names for all ANSI (4-bit) and Xterm (8-bit) colors
  • Support for RGB colors
  • Set colors at compile time by generics or at runtime by value
  • All ANSI colors
    • Basic support (normal and bright variants)
    • Xterm support (high compatibility and 256 colors)
    • Truecolor support (modern, 48-bit color)
  • Styling (underline, strikethrough, etc)

owo-colors is also more-or-less a drop-in replacement for colored, allowing colored to work in a no_std environment. No allocations, unsafe, or dependencies required because embedded systems deserve to be pretty too uwu.

To add to your Cargo.toml:

owo-colors = "3.0.0"

Example

use owo_colors::OwoColorize;
 
fn main() {
    // Foreground colors
    println!("My number is {:#x}!", 10.green());
    // Background colors
    println!("My number is not {}!", 4.on_red());
}

Generic colors

use owo_colors::OwoColorize;
use owo_colors::colors::*;

fn main() {
    // Generically color
    println!("My number might be {}!", 4.fg::<Black>().bg::<Yellow>());
}

Stylize

use owo_colors::OwoColorize;

println!("{}", "strikethrough".strikethrough());

Only Style on Supported Terminals

use owo_colors::{OwoColorize, Stream::Stdout};

println!(
    "{}",
    "colored blue if a supported terminal"
        .if_supports_color(Stdout, |text| text.bright_blue())
);

Supports NO_COLOR/FORCE_COLOR environment variables, checks if it's a tty, checks if it's running in CI (and thus likely supports color), and checks which terminal is being used. (Note: requires supports-colors feature)

Dependencies

~30KB