ansic 0.1.2

Ansic is a crate which does ansi parsing in a dynamic DSL and at compile time for efficient and zero cost ansi styling.
Documentation

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!(red bold underline)

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!(bg.red bold underline)

Or if you want a red bright background you can do this:

ansi!(bg.br.red bold underline)

In addition we can add a foreground color now that we have a background one. Let's add green!

ansi!(bg.br.red green bold underline)

Idiomatic ansic syntax is also storing styles in constants and using them to style in a much less verbose way:

const ERROR: &str = ansi!(br.red bold underline italic);
const RESET: &str = ansi!(reset);

fn main() {
    println!("{ERROR}[ERROR]: Hello, world!{RESET}");
}

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 ⚠️