#terminal-colors #ansi-term #terminal #env-var #no-alloc

no-std owo-colors

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

30 releases (stable)

5.0.0 Sep 10, 2024
4.2.0 Feb 23, 2025
4.1.0 Sep 10, 2024
4.0.0 Dec 20, 2023
0.0.0 Aug 25, 2020

#7 in Command-line interface

Download history 479636/week @ 2024-11-21 457784/week @ 2024-11-28 512255/week @ 2024-12-05 496703/week @ 2024-12-12 363628/week @ 2024-12-19 287059/week @ 2024-12-26 526516/week @ 2025-01-02 682127/week @ 2025-01-09 622553/week @ 2025-01-16 621932/week @ 2025-01-23 653006/week @ 2025-01-30 737858/week @ 2025-02-06 731720/week @ 2025-02-13 880411/week @ 2025-02-20 888642/week @ 2025-02-27 761120/week @ 2025-03-06

3,418,969 downloads per month
Used in 1,944 crates (454 directly)

MIT license

155KB
3K SLoC

Colors

Current Crates.io Version docs-rs MSRV 1.70+ 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
  • 100% safe code
  • Most functions are const
  • 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 = "4"

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)

Minimum supported Rust version (MSRV)

The MSRV of owo-colors is Rust 1.70.

This library has a conservative MSRV policy — Rust versions from the last 12 months will be supported (features available in newer versions will be gated by build.rs), the MSRV will only be bumped if required, and if the MSRV is bumped it will always occur with a new minor version.

Dependencies

~0–6.5MB
~31K SLoC