code / tomo-colorful

Lines259 Tomo191 Markdown65 INI3
(71 lines)

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 Library
3 This is a library for [Tomo](https://tomo.bruce-hill.com) that lets you write
4 colorful text for the terminal without having to stress about managing state
5 for color highlighting.
7 ## Grammar
9 The grammar looks like this:
11 ```
12 colorful <- ("@(at)" / "@(lparen)" / "@(rparen)" # Escapes
13 / "@(" attributes ":" colorful ")" # Colorful text
14 / .)* # Plain text
16 attributes <- (attribute ("," attribute)*)?
18 attribute <- color # Color defaults to foreground
19 / "fg=" color # Foreground color
20 / "bg=" color # Background color
21 / "ul=" color # Underline color
22 / "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-0xFFFFFF
41 / "#" 3 hex # Values 0x000-0xFFF
42 / 1-3 digit # Values 0-255
43 ```
45 ## Command Line Usage
47 You can run `colorful` as a standalone executable to render colorful text with
48 ANSI escape sequences so it looks nice on a terminal.
50 ```
51 colorful [--help] [texts...] [--by-line] [--files ...]
52 ```
54 ## Library Usage
56 `colorful` can also be used as a Tomo library:
58 ```ini
59 # modules.ini
60 [colorful]
61 version=v1.0
62 ```
64 ```tomo
65 use colorful
67 $Colorful"
68 @(blue:Welcome to the @(bold:party)!)
69 We have @(green,bold:colors)!
70 ".print()
71 ```