#terminal-colors #ansi-term #terminal #color #cli #env-var

no-std owo-colors

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

28 releases (stable)

5.0.0 Sep 10, 2024
4.1.0 Sep 10, 2024
4.0.0 Dec 20, 2023
4.0.0-rc.1 Oct 13, 2023
0.0.0 Aug 25, 2020

#8 in Command-line interface

Download history 442459/week @ 2024-09-20 435545/week @ 2024-09-27 463702/week @ 2024-10-04 454673/week @ 2024-10-11 454212/week @ 2024-10-18 440868/week @ 2024-10-25 430519/week @ 2024-11-01 453483/week @ 2024-11-08 463828/week @ 2024-11-15 455292/week @ 2024-11-22 483410/week @ 2024-11-29 514794/week @ 2024-12-06 488626/week @ 2024-12-13 323009/week @ 2024-12-20 307415/week @ 2024-12-27 471199/week @ 2025-01-03

1,678,761 downloads per month
Used in 1,809 crates (440 directly)

MIT license

125KB
2.5K SLoC

Colors

Current Crates.io Version docs-rs MSRV 1.56+ Downloads

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
    • Overridable programmatically via set_override
  • 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 or dependencies required because embedded systems deserve to be pretty too uwu.

To add to your Cargo.toml:

owo-colors = "3"

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

~0–6.5MB
~39K SLoC