Download

tomo-colorful

A Tomo library for adding terminal colors

  • Tomo
Docs 216 wordsMarkdown 216
NameModifiedLinesSize
.gitignore 2 lines<1% of this folder's lines 15 B<1% of this folder's bytes
CHANGES.md 17 lines5% of this folder's lines 231 B2% of this folder's bytes
README.md 71 lines22% of this folder's lines 1.9 KiB17% of this folder's bytes
colorful.tm 220 lines68% of this folder's lines 8.7 KiB76% of this folder's bytes
packages.ini 3 lines<1% of this folder's lines 178 B2% of this folder's bytes
test.colors 9 lines3% of this folder's lines 364 B3% of this folder's bytes

README.md

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()