Clyle Procedural Macros
Compile-time styling for terminal output using HTML-like syntax.
This crate provides the [clyle!] procedural macro, which processes styling
markup at compile time, resulting in zero runtime overhead compared to
manually writing ANSI escape sequences.
The clyle! Macro
The primary export is the [clyle!] macro, which takes a string literal
containing HTML-style markup and returns a &'static str with the processed
ANSI escape sequences.
Usage
use clyle;
Why Use clyle! Over try_clyle()?
- Zero Runtime Overhead: Styling is processed at compile time
- Early Error Detection: Invalid markup fails at compile time, not runtime
- Optimized Output: The compiler can optimize static strings
- Simpler API: No need for error handling in most cases
Syntax Guide
Color Syntax
-
Standard ANSI colors (16 colors):
- Lowercase:
black,red,green,yellow,blue,magenta,cyan,white - Short form:
k,r,g,y,b,m,c,w - Bright variants (uppercase):
Black,Red,Green,Yellow,Blue,Magenta,Cyan,White - Bright variants short form:
K,R,G,Y,B,M,C,W
- Lowercase:
-
256-Color Palette:
palette(0)throughpalette(255) -
True RGB Colors:
- Hex format:
#FF00FF(magenta) - RGB format:
rgb(255,0,255)(magenta)
- Hex format:
Use the
fg=attribute for background colors and thebg=attribute for background colors.
Example
use clyle;
Text Effects
boldorb— Bold textdimord— Dimmed/faint textitalicori— Italic textunderoru— Underlined textstrikeors— Strikethrough textblinkork— Blinking textreverseorr— Inverted foreground and backgroundhiddenorh— Hidden text (not visible)
Effects can be combined in a single tag:
use clyle;
Tag Nesting and Closing
Tags are closed with </> or </TAG-NAME> which removes all active styling. You can nest tags:
use clyle;
Examples
Status Messages
use clyle;
Nested Styling
use clyle;
Compile-Time vs Runtime
Use this macro when:
- You have fixed styling strings (literals)
- You want zero runtime overhead
- You prefer early error detection
Use [
clyle_core::try_clyle] when: - You need to style dynamically generated strings
- You need to handle styling errors at runtime
- You're processing user input or external data
Integration with clyle Crate
The clyle crate re-exports this macro for convenient use:
use clyle;
Alternatively, import directly from this crate:
use clyle;
Terminal Support
Clyle works on any terminal supporting ANSI escape sequences:
- ✅ Most modern terminals (bash, zsh, PowerShell 7+, etc.)
- ✅ Windows 10+ (with ANSI support enabled or Windows Terminal)
- ✅ macOS Terminal and iTerm2
- ℹ️ Always test on your target platform to ensure color support
License
Clyle is dual-licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
Choose whichever license works best for your use case.