Farben is a color library that uses markup-like syntax. Color your terminal without typing whatever the heck \x1b[31m is.
- User Guide: https://razkar-studio.github.io/farben
- API Reference: https://docs.rs/farben
- Changelog: CHANGELOG.md
// Using default features
use farben::prelude::*;
style!("error", "[bold underline red]");
style!("warn", "[bold yellow]");
cprintln!("[error]error: [/]Something bad happened.");
cprintln!("[warn]warn: [/]This looks suspicious.");
cprintln!("[bg:blue fg:white]White on blue!");
let name = "Razkar";
cprintln!("[bold green]Hello, {}!", name);
cprintb!("[red]This bleeds ");
cprintln!("into this.");// Using the "compile" feature
use farben::prelude::*;
cprintln!("[bold underline red]error: [/]Something bad happened."); // compile-time validation
cprintln!("[bg:blue fg:white]White on blue!");
let name = "Razkar";
cprintln!("[bold green]Hello, {}!", name);
cprintb!("[red]This bleeds ");
cprintln!("into this.");- Markup-like Syntax: Easy to read, write, and powerful when used.
- Zero required runtime dependencies: Only
farben-coreas a path dependency, Farben introduces no complicated dependency tree. - Opt-in Compile-time Processing: Validate and process markup at compile time with no runtime overhead, via the
compilefeature flag. - Complete Toolkit: Named colors, ANSI256, RGB, emphasis styles, style chaining, foreground and background support.
- Drop-in Print Macros:
cprint!,cprintln!,cprintb!,cprintbln!work just likeprint!andprintln!but with markup support. Writer variantscwrite!,cwriteln!,cwriteb!,cwritebln!work with anyWriteimplementor. - Stderr Variants: All print macros have
evariants (ceprint!,ceprintln!, etc.) that target stderr. - Bleed Variants:
cprintb!,cprintbln!,colorb(), andcolorb!()skip the trailing reset, letting styles carry forward across multiple calls. - User-defined styles: Define your own tags with
style!()that expand to any combination of supported tags. - Custom style files: Drop in a
name.frb.tomlfile, write 1 line onbuild.rsand 2 onmain.rs, and all styles from that file is set.
- No
NO_COLOR,FORCE_COLOR, or TTY detection, incompile. Thecompilefeature processes markup at build time and bakes ANSI codes directly into the binary. As a result,NO_COLOR,FORCE_COLOR, and TTY detection are only respected at build time, not at end-user runtime. They are fundamentally different, and I cannot solve this. Use runtime macros if you need full environment awareness.
Note
Update, compile-time style thingy works now I guess. Check the docs for how they work.
Tags are written as [tag] and apply from that point forward. Multiple tags can be combined in a single bracket: [bold red].
Warning
Spaces inside ansi() and rgb() are not supported at the moment.
| Tag | Description |
|---|---|
[red], [blue], ... |
Named colors (black, red, green, yellow, blue, magenta, cyan, white) |
[fg:red], [bg:red] |
Explicit foreground/background color — works with all color formats |
[rgb(r,g,b)] |
24-bit RGB color |
[ansi(n)] |
256-color palette index |
[bold], [italic], [dim], [underline], [blink], [strikethrough] |
Emphasis styles |
[/] |
Reset all styles |
\\[ |
Escaped bracket, treated as literal [ |
[yourname] |
User-defined style via style!() |
color() panics on invalid markup. For graceful error handling, use try_color():
use farben::try_color;
match try_color("[invalid]oops") {
Ok(s) => println!("{s}"),
Err(e) => eprintln!("Error: {e}"),
}Contributions are welcome! Feel free to submit a Pull Request.
Licensed under either of MIT License or Apache License, Version 2.0 at your option.
Cheers, RazkarStudio.
© 2026 RazkarStudio. All rights reserved.
