From 9f4aa6a2e009cfec07545e3f7062a092c92d7a5a Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 2 Oct 2017 19:23:56 -0700 Subject: Added some ansi color escapes. --- examples/sample_game.nom | 4 ++-- lib/utils.nom | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/examples/sample_game.nom b/examples/sample_game.nom index 95e5c26..5ce688c 100644 --- a/examples/sample_game.nom +++ b/examples/sample_game.nom @@ -95,7 +95,7 @@ with secrets: secret %approvals = [] say ".." |Proposal: - |\(%src) + |\(bright)\(blue)\(%src)\(reset color) parse [propose %action] as: propose source (..) @@ -253,7 +253,7 @@ as bill: approve as dave: join propose: - rule [declare war] =: say "WAR!!!" + rule [declare war] =: say "\(red)WAR!!!\(reset color)" with secrets: secret %president = (nil) rule [elect president from %candidates] =: diff --git a/lib/utils.nom b/lib/utils.nom index 608e72f..55503e1 100644 --- a/lib/utils.nom +++ b/lib/utils.nom @@ -84,3 +84,33 @@ compile [max of %items by %value_expr] to: | return \(%value_expr as lua) |end) +# String utilities +compile [nl, newline, line feed, linefeed, lf] to: ".." + |"\n" +compile [tab] to: ".." + |"\t" +compile [bell] to: ".." + |"\a" +compile [cr, carriage return] to: ".." + |"\r" +compile [backspace] to: ".." + |"\b" +compile [form feed, formfeed] to: ".." + |"\f" +compile [vertical tab] to: ".." + |"\v" + +lua code ".." + |do; + | local colors = { + | ["reset color"] = 0, bright = 1, dim = 2, underscore = 4, blink = 5, + | inverse = 7, hidden = 8, black = 30, red = 31, green = 32, yellow = 33, + | blue = 34, magenta = 35, cyan = 36, white = 37, ["on black"] = 40, + | ["on red"] = 41, ["on green"] = 42, ["on yellow"] = 43, ["on blue"] = 44, + | ["on magenta"] = 45, ["on cyan"] = 46, ["on white"] = 47, + | }; + | for name,code in pairs(colors) do; + | local escape = "\\"\\\\27["..tostring(code).."m\\"" + | nomsu:defmacro(name, function() return escape end, ""); + | end; + |end; -- cgit v1.2.3