Ansic
The most efficient and easy ansi styling crate ever!
Ansic is a crate which adds the ansi! proc macro, which allows for easy, simple and zero cost styling which happens at compiletime, in addition to other ansi utilities.
Features:
- Compiletime styling with proc macro
- Zero cost at runtime
- Encoded in static str's
Usage:
To make a red foreground, bold and underline ansi
ansi!
All color arguments can take these arguments:
- "br" - bright
- "bg" - background (rgb can only take bg)
You can chain them like this if we want a red background:
ansi!
Or if you want a red bright background you can do this:
ansi!
In addition we can add a foreground color now that we have a background one. Let's add green!
ansi!
Idiomatic ansic syntax is also storing styles in constants and using them to style in a much less verbose way:
const ERROR: &str = ansi!;
const RESET: &str = ansi!;
Ansic has alot more styles which you can find on our docs.rs page: Ansic on Docs.rs; Ansic also has util macros and functions for more convenient use (listed under Comparisons)
Comparisons
Feature | Ansic ✅ | owo-colors ⚠️/✅ | ansi_term ❌/⚠️ |
---|---|---|---|
FULLY Compile Time Generation | Yes ✅ | No ❌ | No ❌ |
Zero Runtime Cost | Yes ✅ | No ❌ | No ❌ |
Minimal Binary Size | Minimal ✅ | Low ⚠️ | Medium ⚠️ |
Supports RGB Styles | Yes ✅ | Yes ✅ | No ❌ |
No-Std support | Yes ✅ | Yes ✅ | Yes ✅ |
Reusable Style Constants | Yes ✅ | Awkward ⚠️ | Partial ⚠️ |
Simple Macro DSL | Yes ✅ | No ❌ | No ❌ |
ANSI Reset Handling | Automatic ✅ | Mostly ⚠️ | Manual ⚠️ |
Text Injection | Yes ✅ | Yes ✅ | Yes ✅ |
Extensibility / Custom DSL | Yes ✅ | No ❌ | No ❌ |
Windows Compatibility | Enable with other crate ✅ (via vt_mode) | Yes ✅ | Yes ✅ |
Well-maintained | New, active 🚧 | Yes ✅ | Mostly deprecated ⚠️ |