code / tomo-colorful

Lines259 Tomo191 Markdown65 INI3

Colorful Tomo Library

This is a library for Tomo that lets you write colorful text for the terminal without having to stress about managing state for color highlighting.

Grammar

The grammar looks like this:

1 colorful <- ("@(at)" / "@(lparen)" / "@(rparen)" # Escapes
2 / "@(" attributes ":" colorful ")" # Colorful text
3 / .)* # Plain text
5 attributes <- (attribute ("," attribute)*)?
7 attribute <- color # Color defaults to foreground
8 / "fg=" color # Foreground color
9 / "bg=" color # Background color
10 / "ul=" color # Underline color
11 / "b" / "bold"
12 / "d" / "dim"
13 / "u" / "underline"
14 / "i" / "italic"
15 / "B" / "blink"
16 / "r" / "reverse"
17 # These are rarely supported by terminals:
18 / "fraktur"
19 / "frame"
20 / "encircle"
21 / "overline"
22 / "super" / "superscript"
23 / "sub" / "subscript"
25 color <- "black" / "red" / "green" / "yellow" / "blue" / "magenta" / "cyan" / "white"
26 # All caps colors are "bright" colors (not always supported):
27 / "BLACK" / "RED" / "GREEN" / "YELLOW" / "BLUE" / "MAGENTA" / "CYAN" / "WHITE"
28 / "default"
29 / "#" 6 hex # Values 0x000000-0xFFFFFF
30 / "#" 3 hex # Values 0x000-0xFFF
31 / 1-3 digit # Values 0-255

Command Line Usage

You can run colorful as a standalone executable to render colorful text with ANSI escape sequences so it looks nice on a terminal.

1 colorful [--help] [texts...] [--by-line] [--files ...]

Library Usage

colorful can also be used as a Tomo library:

1 use colorful
3 $Colorful"
4 @(blue:Welcome to the @(bold:party)!)
5 We have @(green,bold:colors)!
6 ".print()