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:
colorful <- ("@(at)" / "@(lparen)" / "@(rparen)" # Escapes
/ "@(" attributes ":" colorful ")" # Colorful text
/ .)* # Plain text
attributes <- (attribute ("," attribute)*)?
attribute <- color # Color defaults to foreground
/ "fg=" color # Foreground color
/ "bg=" color # Background color
/ "ul=" color # Underline color
/ "b" / "bold"
/ "d" / "dim"
/ "u" / "underline"
/ "i" / "italic"
/ "B" / "blink"
/ "r" / "reverse"
# These are rarely supported by terminals:
/ "fraktur"
/ "frame"
/ "encircle"
/ "overline"
/ "super" / "superscript"
/ "sub" / "subscript"
color <- "black" / "red" / "green" / "yellow" / "blue" / "magenta" / "cyan" / "white"
# All caps colors are "bright" colors (not always supported):
/ "BLACK" / "RED" / "GREEN" / "YELLOW" / "BLUE" / "MAGENTA" / "CYAN" / "WHITE"
/ "default"
/ "#" 6 hex # Values 0x000000-0xFFFFFF
/ "#" 3 hex # Values 0x000-0xFFF
/ 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.
colorful [--help] [texts...] [--by-line] [--files ...]
Library Usage
colorful can also be used as a Tomo library:
# modules.ini
[colorful]
version=v1.0
use colorful
$Colorful"
@(blue:Welcome to the @(bold:party)!)
We have @(green,bold:colors)!
".print()
1 # Colorful Tomo Library4 colorful text for the terminal without having to stress about managing state5 for color highlighting.7 ## Grammar9 The grammar looks like this:11 ```12 colorful <- ("@(at)" / "@(lparen)" / "@(rparen)" # Escapes13 / "@(" attributes ":" colorful ")" # Colorful text14 / .)* # Plain text16 attributes <- (attribute ("," attribute)*)?18 attribute <- color # Color defaults to foreground19 / "fg=" color # Foreground color20 / "bg=" color # Background color21 / "ul=" color # Underline color22 / "b" / "bold"23 / "d" / "dim"24 / "u" / "underline"25 / "i" / "italic"26 / "B" / "blink"27 / "r" / "reverse"28 # These are rarely supported by terminals:29 / "fraktur"30 / "frame"31 / "encircle"32 / "overline"33 / "super" / "superscript"34 / "sub" / "subscript"36 color <- "black" / "red" / "green" / "yellow" / "blue" / "magenta" / "cyan" / "white"37 # All caps colors are "bright" colors (not always supported):38 / "BLACK" / "RED" / "GREEN" / "YELLOW" / "BLUE" / "MAGENTA" / "CYAN" / "WHITE"39 / "default"40 / "#" 6 hex # Values 0x000000-0xFFFFFF41 / "#" 3 hex # Values 0x000-0xFFF42 / 1-3 digit # Values 0-25543 ```45 ## Command Line Usage48 ANSI escape sequences so it looks nice on a terminal.50 ```51 colorful [--help] [texts...] [--by-line] [--files ...]52 ```54 ## Library Usage59 # modules.ini60 [colorful]61 version=v1.062 ```65 use colorful67 $Colorful"68 @(blue:Welcome to the @(bold:party)!)69 We have @(green,bold:colors)!70 ".print()71 ```