1
0
Fork 0

move improved help screen generator multikey.{xml -> nas}

This commit is contained in:
mfranz 2008-10-01 16:30:25 +00:00
parent 772112df89
commit 32c5cde2f0
2 changed files with 39 additions and 34 deletions

View file

@ -46,40 +46,7 @@
<exit/>
<binding>
<command>nasal</command>
<script>
var (curr, title) = (0, "");
foreach (var k; sort(multikey.data, func(a, b) cmp(a[0], b[0]))) {
var bndg = k[1].getChildren("binding");
var desc = k[1].getNode("desc", 1).getValue() or "??";
if (size(k[0]) == 1 or k[0][0] == `%`)
title = desc;
if (!size(bndg) or size(bndg) == 1
and bndg[0].getNode("command", 1).getValue() == "null")
continue;
if (k[0][0] != curr) {
curr = k[0][0];
var line = "--------------------------------------------";
printf("-- %s %s", title, substr(line, size(title) + 2));
}
var cmd = k[0];
cmd = string.replace(cmd, "%u", debug._c("32", "%u"));
cmd = string.replace(cmd, "%d", debug._c("31", "%d"));
cmd = string.replace(cmd, "%f", debug._c("36", "%f"));
cmd = string.replace(cmd, "&lt;", debug._c("35", "&lt;"));
cmd = string.replace(cmd, "&gt;", debug._c("35", "&gt;"));
cmd = string.replace(cmd, "^", debug._c("35", "^"));
cmd = string.replace(cmd, "_", debug._c("35", "_"));
printf("%s\t%s", cmd, desc);
}
print("------------------------------------------\n\tLegend:\n");
printf("\t%s ... unsigned number", debug._c("32", "%u"));
printf("\t%s ... signed number", debug._c("31", "%d"));
printf("\t%s ... floation point number", debug._c("36", "%f"));
printf("\t%s ... cursor left", debug._c("35", "&lt;"));
printf("\t%s ... cursor right", debug._c("35", ">"));
printf("\t%s ... cursor up", debug._c("35", "^"));
printf("\t%s ... cursor down", debug._c("35", "_"));
</script>
<script>multikey.help()</script>
</binding>
</key>

View file

@ -33,6 +33,8 @@ var handle_key = func(key) {
return 1;
} elsif (key == 8) {
cmd = substr(cmd, 0, size(cmd) - 1);
} elsif (key == 9) {
#
} elsif (key == `\n` or key == `\r`) {
mode = 2;
} elsif (contains(translate, key)) {
@ -89,6 +91,42 @@ var popup = func(cmd, title = nil) {
}
var help = func {
var (curr, title) = (0, "");
foreach (var k; sort(data, func(a, b) cmp(a[0], b[0]))) {
var bndg = k[1].getChildren("binding");
var desc = k[1].getNode("desc", 1).getValue() or "??";
if (size(k[0]) == 1 or k[0][0] == `%`)
title = desc;
if (!size(bndg) or size(bndg) == 1
and bndg[0].getNode("command", 1).getValue() == "null")
continue;
if (string.isalnum(k[0][0]) and k[0][0] != curr) {
curr = k[0][0];
var line = "--------------------------------------------";
print(debug._c("33", sprintf("\n-- %s %s", title, substr(line, size(title) + 2))));
}
var cmd = k[0];
cmd = string.replace(cmd, "%u", debug._c("32", "%u"));
cmd = string.replace(cmd, "%d", debug._c("31", "%d"));
cmd = string.replace(cmd, "%f", debug._c("36", "%f"));
cmd = string.replace(cmd, "&lt;", debug._c("35", "&lt;"));
cmd = string.replace(cmd, "&gt;", debug._c("35", "&gt;"));
cmd = string.replace(cmd, "^", debug._c("35", "^"));
cmd = string.replace(cmd, "_", debug._c("35", "_"));
printf("%s\t%s", cmd, desc);
}
print(debug._c("33", "\n-- Legend ------------------------------------"));
printf("\t%s ... unsigned number", debug._c("32", "%u"));
printf("\t%s ... signed number", debug._c("31", "%d"));
printf("\t%s ... floation point number", debug._c("36", "%f"));
printf("\t%s ... cursor left", debug._c("35", "&lt;"));
printf("\t%s ... cursor right", debug._c("35", ">"));
printf("\t%s ... cursor up", debug._c("35", "^"));
printf("\t%s ... cursor down", debug._c("35", "_"));
}
var init = func {
globals["__multikey"] = { _: };
var tree = props.globals.getNode("/input/keyboard/multikey", 1);