- move color functions from debug.nas to string.nas
- multikey.nas: add exit/no-exit markers to help output
This commit is contained in:
parent
4f7c928cb6
commit
e6e1f8ae20
3 changed files with 51 additions and 42 deletions
|
@ -46,34 +46,25 @@
|
||||||
# installed. If the color codes aren't interpreted correctly, then
|
# installed. If the color codes aren't interpreted correctly, then
|
||||||
# set property /sim/startup/terminal-ansi-colors=0
|
# set property /sim/startup/terminal-ansi-colors=0
|
||||||
#
|
#
|
||||||
var _c = func nil;
|
|
||||||
|
|
||||||
var color = func(enabled) {
|
|
||||||
if (enabled and getprop("/sim/startup/stderr-to-terminal"))
|
|
||||||
_c = func(color, s) { "\x1b[" ~ color ~ "m" ~ s ~ "\x1b[m" }
|
|
||||||
else
|
|
||||||
_c = func(dummy, s) { s }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# for color codes see $ man console_codes
|
# for color codes see $ man console_codes
|
||||||
#
|
#
|
||||||
var _title = func(s) _c("33;42;1", s); # backtrace header
|
var _title = func(s) globals.string.color("33;42;1", s); # backtrace header
|
||||||
var _section = func(s) _c("37;41;1", s); # backtrace frame
|
var _section = func(s) globals.string.color("37;41;1", s); # backtrace frame
|
||||||
var _error = func(s) _c("31;1", s); # internal errors
|
var _error = func(s) globals.string.color("31;1", s); # internal errors
|
||||||
var _bench = func(s) _c("37;45;1", s); # benchmark info
|
var _bench = func(s) globals.string.color("37;45;1", s); # benchmark info
|
||||||
|
|
||||||
var _nil = func(s) _c("32", s); # nil
|
var _nil = func(s) globals.string.color("32", s); # nil
|
||||||
var _string = func(s) _c("31", s); # "foo"
|
var _string = func(s) globals.string.color("31", s); # "foo"
|
||||||
var _num = func(s) _c("31", s); # 0.0
|
var _num = func(s) globals.string.color("31", s); # 0.0
|
||||||
var _bracket = func(s) _c("", s); # [ ]
|
var _bracket = func(s) globals.string.color("", s); # [ ]
|
||||||
var _brace = func(s) _c("", s); # { }
|
var _brace = func(s) globals.string.color("", s); # { }
|
||||||
var _angle = func(s) _c("", s); # < >
|
var _angle = func(s) globals.string.color("", s); # < >
|
||||||
var _vartype = func(s) _c("33", s); # func ghost
|
var _vartype = func(s) globals.string.color("33", s); # func ghost
|
||||||
var _proptype = func(s) _c("34", s); # BOOL INT LONG DOUBLE ...
|
var _proptype = func(s) globals.string.color("34", s); # BOOL INT LONG DOUBLE ...
|
||||||
var _path = func(s) _c("36", s); # /some/property/path
|
var _path = func(s) globals.string.color("36", s); # /some/property/path
|
||||||
var _internal = func(s) _c("35", s); # me parents
|
var _internal = func(s) globals.string.color("35", s); # me parents
|
||||||
var _varname = func(s) s; # variable_name
|
var _varname = func(s) s; # variable_name
|
||||||
|
|
||||||
var ghosttypes = {};
|
var ghosttypes = {};
|
||||||
|
|
||||||
|
@ -243,7 +234,7 @@ var dump = func(vars...) {
|
||||||
if (size(vars) == 1)
|
if (size(vars) == 1)
|
||||||
return print(debug.string(vars[0]));
|
return print(debug.string(vars[0]));
|
||||||
forindex (var i; vars)
|
forindex (var i; vars)
|
||||||
print(_c("33;40;1", "#" ~ i) ~ " ", debug.string(vars[i]));
|
print(globals.string.color("33;40;1", "#" ~ i) ~ " ", debug.string(vars[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -329,18 +320,9 @@ var printerror = func(err) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (getprop("/sim/logging/priority") != "alert") {
|
|
||||||
_setlistener("/sim/signals/nasal-dir-initialized", func print(_c("32", "** NASAL initialized **")));
|
|
||||||
_setlistener("/sim/signals/fdm-initialized", func print(_c("36", "** FDM initialized **")));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||||
ghosttypes[ghosttype(props._globals())] = "PropertyNode";
|
ghosttypes[ghosttype(props._globals())] = "PropertyNode";
|
||||||
ghosttypes[ghosttype(io.stderr)] = "FileHandle";
|
ghosttypes[ghosttype(io.stderr)] = "FileHandle";
|
||||||
|
|
||||||
setlistener("/sim/startup/terminal-ansi-colors", func(n) color(n.getBoolValue()), 1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,7 @@ var help = func {
|
||||||
for (var i = 0; i < size(str); i += 1) {
|
for (var i = 0; i < size(str); i += 1) {
|
||||||
var c = str[i];
|
var c = str[i];
|
||||||
if (c == `<` or c == `>` or c == `^` or c == `_`) {
|
if (c == `<` or c == `>` or c == `^` or c == `_`) {
|
||||||
s ~= debug._c("35", chr(c));
|
s ~= string.color("35", chr(c));
|
||||||
} elsif (c == `%`) {
|
} elsif (c == `%`) {
|
||||||
if ((i += 1) < size(str) and str[i] == `%`) {
|
if ((i += 1) < size(str) and str[i] == `%`) {
|
||||||
s ~= '%';
|
s ~= '%';
|
||||||
|
@ -163,13 +163,13 @@ var help = func {
|
||||||
for (; i < size(str) and (c = str[i]) != nil and string.isdigit(c); i += 1)
|
for (; i < size(str) and (c = str[i]) != nil and string.isdigit(c); i += 1)
|
||||||
f ~= chr(c);
|
f ~= chr(c);
|
||||||
if (c == `d`)
|
if (c == `d`)
|
||||||
s ~= debug._c("31", f ~ 'd');
|
s ~= string.color("31", f ~ 'd');
|
||||||
elsif (c == `u`)
|
elsif (c == `u`)
|
||||||
s ~= debug._c("32", f ~ 'u');
|
s ~= string.color("32", f ~ 'u');
|
||||||
elsif (c == `f`)
|
elsif (c == `f`)
|
||||||
s ~= debug._c("36", f ~ 'f');
|
s ~= string.color("36", f ~ 'f');
|
||||||
elsif (c == `s`)
|
elsif (c == `s`)
|
||||||
s ~= debug._c("34", f ~ 's');
|
s ~= string.color("34", f ~ 's');
|
||||||
} else {
|
} else {
|
||||||
s ~= chr(c);
|
s ~= chr(c);
|
||||||
}
|
}
|
||||||
|
@ -198,12 +198,15 @@ var help = func {
|
||||||
if (string.isalnum(k[0][0]) and k[0][0] != curr) {
|
if (string.isalnum(k[0][0]) and k[0][0] != curr) {
|
||||||
curr = k[0][0];
|
curr = k[0][0];
|
||||||
var line = "---------------------------------------------------";
|
var line = "---------------------------------------------------";
|
||||||
print(debug._c("33", sprintf("\n-- %s %s", title, substr(line, size(title) + 2))));
|
print(string.color("33", sprintf("\n-- %s %s", title, substr(line, size(title) + 2))));
|
||||||
}
|
}
|
||||||
|
if (k[1].getNode("no-exit") != nil)
|
||||||
|
desc ~= string.color("32", " +");
|
||||||
|
elsif (k[1].getNode("exit") != nil)
|
||||||
|
desc ~= string.color("31", " $");
|
||||||
printf("%s\t%s", colorize(k[0]), desc);
|
printf("%s\t%s", colorize(k[0]), desc);
|
||||||
}
|
}
|
||||||
print(debug._c("33", "\n-- Legend -------------------------------------------"));
|
print(string.color("33", "\n-- Legend -------------------------------------------"));
|
||||||
printf("\t%s ... unsigned number", colorize("%u"));
|
printf("\t%s ... unsigned number", colorize("%u"));
|
||||||
printf("\t%s ... signed number", colorize("%d"));
|
printf("\t%s ... signed number", colorize("%d"));
|
||||||
printf("\t%s ... floating point number", colorize("%f"));
|
printf("\t%s ... floating point number", colorize("%f"));
|
||||||
|
@ -212,6 +215,8 @@ var help = func {
|
||||||
printf("\t%s ... > or cursor right", colorize(">"));
|
printf("\t%s ... > or cursor right", colorize(">"));
|
||||||
printf("\t%s ... ^ or cursor up", colorize("^"));
|
printf("\t%s ... ^ or cursor up", colorize("^"));
|
||||||
printf("\t%s ... _ or cursor down", colorize("_"));
|
printf("\t%s ... _ or cursor down", colorize("_"));
|
||||||
|
printf("\t%s ... repeatable action", string.color("32", "+"));
|
||||||
|
printf("\t%s ... immediate action", string.color("31", "$"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -356,3 +356,25 @@ var scanf = func(test, format, result) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# ANSI colors (see $ man console_codes)
|
||||||
|
#
|
||||||
|
var setcolors = func(enabled) {
|
||||||
|
if (enabled and getprop("/sim/startup/stderr-to-terminal"))
|
||||||
|
color = func(color, s) { "\x1b[" ~ color ~ "m" ~ s ~ "\x1b[m" }
|
||||||
|
else
|
||||||
|
color = func(dummy, s) { s }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# Add ANSI color codes to string, if terminal-ansi-colors are enabled and
|
||||||
|
# stderr prints to a terminal. Example:
|
||||||
|
#
|
||||||
|
# print(string.color("31", "this is red"));
|
||||||
|
#
|
||||||
|
var color = func nil;
|
||||||
|
setcolors(getprop("/sim/startup/terminal-ansi-colors"));
|
||||||
|
setlistener("/sim/startup/terminal-ansi-colors", func(n) setcolors(n.getBoolValue()));
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue