https://github.com/harehare/ansi.mq
ANSI terminal escape code utilities implemented as an mq module.
https://github.com/harehare/ansi.mq
color markdown mq
Last synced: 29 days ago
JSON representation
ANSI terminal escape code utilities implemented as an mq module.
- Host: GitHub
- URL: https://github.com/harehare/ansi.mq
- Owner: harehare
- License: mit
- Created: 2026-06-13T03:31:00.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2026-06-13T07:57:37.000Z (about 1 month ago)
- Last Synced: 2026-06-13T09:26:28.909Z (about 1 month ago)
- Topics: color, markdown, mq
- Homepage: https://mqlang.org
- Size: 3.91 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ansi.mq
ANSI terminal escape code utilities implemented as an [mq](https://github.com/harehare/mq) module.
## Features
- Text styles: bold, dim, italic, underline, strikethrough
- Standard foreground colors (8 colors + bright variants)
- Background colors (8 colors)
- 24-bit RGB foreground and background colors
- Strip ANSI codes from strings
- Compute visible length (excluding escape codes)
## Installation
Copy `ansi.mq` to your mq module directory:
```sh
cp ansi.mq ~/.mq/
```
### HTTP Import (no local installation needed)
If `mq` was built with the `http-import` feature, you can import directly from GitHub without any local setup:
```sh
mq -I raw 'import "github.com/harehare/ansi.mq" | ansi::ansi_green("✓ OK")' input.md
```
Pin to a specific release with `@vX.Y.Z`:
```sh
mq -I raw 'import "github.com/harehare/ansi.mq@v1.0.0" | ansi::ansi_green("✓ OK")' input.md
```
## Usage
```sh
mq -I raw 'import "ansi" | ansi::ansi_green("✓ OK")' input.md
```
## API
### Styles
| Function | Effect |
|---|---|
| `ansi_bold(s)` | **Bold** |
| `ansi_dim(s)` | Dim / faint |
| `ansi_italic(s)` | *Italic* |
| `ansi_underline(s)` | Underline |
| `ansi_strikethrough(s)` | ~~Strikethrough~~ |
### Foreground Colors
| Function | Color |
|---|---|
| `ansi_red(s)` | Red |
| `ansi_green(s)` | Green |
| `ansi_yellow(s)` | Yellow |
| `ansi_blue(s)` | Blue |
| `ansi_magenta(s)` | Magenta |
| `ansi_cyan(s)` | Cyan |
| `ansi_white(s)` | White |
| `ansi_bright_red(s)` | Bright red |
| `ansi_bright_green(s)` | Bright green |
| `ansi_bright_yellow(s)` | Bright yellow |
| `ansi_bright_blue(s)` | Bright blue |
| `ansi_bright_magenta(s)` | Bright magenta |
| `ansi_bright_cyan(s)` | Bright cyan |
| `ansi_bright_white(s)` | Bright white |
### Background Colors
| Function | Color |
|---|---|
| `ansi_bg_red(s)` | Red background |
| `ansi_bg_green(s)` | Green background |
| `ansi_bg_yellow(s)` | Yellow background |
| `ansi_bg_blue(s)` | Blue background |
| `ansi_bg_magenta(s)` | Magenta background |
| `ansi_bg_cyan(s)` | Cyan background |
| `ansi_bg_white(s)` | White background |
### 24-bit Color
| Function | Description |
|---|---|
| `ansi_rgb(s, r, g, b)` | 24-bit foreground (0–255 per channel) |
| `ansi_bg_rgb(s, r, g, b)` | 24-bit background (0–255 per channel) |
### Utilities
| Function | Description |
|---|---|
| `ansi_strip(s)` | Remove all ANSI escape codes |
| `ansi_len(s)` | Visible length (after stripping codes) |
## Example
```sh
# Colorize mq test output labels
mq '
import "ansi"
| if (contains(., "PASS")):
ansi::ansi_green(.)
else:
ansi::ansi_red(.)
' results.md
# Print a header with bold cyan text
mq -I raw '"Report" | import "ansi" | ansi::ansi_bold(ansi::ansi_cyan(.))' /dev/null
```
## Compatibility
Requires [mq](https://github.com/harehare/mq) v0.5 or later.
Terminal support depends on the environment; most modern terminals support ANSI codes.
## License
MIT