aboutsummaryrefslogtreecommitdiff
path: root/examples/colorful/README.md
blob: 04a221e3c831f82991d78a2e14097fa84c095d71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Colorful Lang

Colorful is a `lang` 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:

```tomo
use colorful_v1.0

$Colorful"
    @(blue:Welcome to the @(bold:party)!)
    We have @(green,bold:colors)!
".print()
```