no-std kxxt-owo-colors

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

2 releases (1 stable)

4.0.0 Feb 14, 2024
4.0.0-rc.1 Oct 24, 2023

#277 in Command-line interface

Download history 20/week @ 2024-07-20 13/week @ 2024-07-27 35/week @ 2024-08-03 19/week @ 2024-08-10 18/week @ 2024-08-17 42/week @ 2024-08-24 15/week @ 2024-08-31 2/week @ 2024-09-07 79/week @ 2024-09-14 79/week @ 2024-09-21 13/week @ 2024-09-28 60/week @ 2024-10-05 82/week @ 2024-10-12 34/week @ 2024-10-19 31/week @ 2024-10-26 8/week @ 2024-11-02

157 downloads per month
Used in tracexec

MIT license

130KB
2.5K SLoC

This is a fork of https://github.com/jam1garner/owo-colors with some personal changes

You should go to https://github.com/jam1garner/owo-colors instead

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–6MB
~34K SLoC