aboutsummaryrefslogtreecommitdiff
path: root/lib/text.nom
blob: 7fa1a2ccffd7b56198e1ee138e4468bb4a07dd49 (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
use "lib/metaprogramming.nom"
use "lib/control_flow.nom"
use "lib/collections.nom"

local [%ansi, %colors]
set %ansi = {..}
    nl="\\n", newline="\\n", tab="\\t", bell="\\a", cr="\\r", "carriage return"="\\r"
    backspace="\\b", "form feed"="\\f", formfeed="\\f", "vertical tab"="\\v"

set %colors = {..}
    "reset color"="\\27[0m", bright="\\27[1m", dim="\\27[2m", underscore="\\27[4m"
    blink="\\27[5m", inverse="\\27[7m", hidden="\\27[8m"

    black="\\27[30m", red="\\27[31m", green="\\27[32m", yellow="\\27[33m", blue="\\27[34m"
    magenta="\\27[35m", cyan="\\27[36m", white="\\27[37m"

    "on black"="\\27[40m", "on red"="\\27[41m", "on green"="\\27[42m", "on yellow"="\\27[43m"
    "on blue"="\\27[44m", "on magenta"="\\27[45m", "on cyan"="\\27[46m", "on white"="\\27[47m"

for %name=%str in %ansi:
    lua> ".."
        local e = "'"..\%str.."'";
        nomsu:define_compile_action(\%name, \(__line_no__), function(nomsu) return {expr=e}; end, \(__src__ 1));

for %name=%str in %colors:
    lua> ".."
        local e = "'"..\%str.."'";
        local reset = "'"..\(%colors->"reset color").."'";
        nomsu:define_compile_action(\%name, \(__line_no__), function(nomsu) return {expr=e}; end, \(__src__ 1));
        nomsu:define_compile_action(\%name.." %", \(__line_no__), function(nomsu, _)
            return {expr=e..".."..nomsu:tree_to_lua(_).expr..".."..reset};
        end, \(__src__ 1));