aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/text.nom32
-rw-r--r--lib/utils.nom24
2 files changed, 32 insertions, 24 deletions
diff --git a/lib/text.nom b/lib/text.nom
new file mode 100644
index 0000000..f7e4b00
--- /dev/null
+++ b/lib/text.nom
@@ -0,0 +1,32 @@
+use "lib/metaprogramming.nom"
+use "lib/control_flow.nom"
+use "lib/collections.nom"
+
+lua> "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));
diff --git a/lib/utils.nom b/lib/utils.nom
index 8ed196d..2b72080 100644
--- a/lib/utils.nom
+++ b/lib/utils.nom
@@ -93,27 +93,3 @@ compile [sort %items by %key_expr] to: ".."
return \(%key_expr as lua);
end)
-# Text 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> ".."
- 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:define_compile_action(name, \(__line_no__), function() return escape end, "");
- end
- end
-