-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.js
126 lines (102 loc) · 2.7 KB
/
menu.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// menu.js
// $Id: menu.js,v 1.5 2005/11/19 05:46:44 rswindell Exp $
// Execute a Synchronet menu (.menu) file
load("sbbsdefs.js");
load("menulib.js");
var menu_stack = new Array();
var pop_count = 0;
exec_menu(argv[0]);
function isdigit(ch)
{
var val = ascii(ch.toUpperCase());
return(val>=ascii('0') && val<=ascii('9'));
}
function exec_menu(fname)
{
if(!fname) {
alert(log(LOG_WARNING,"!No menu file specified"));
return(false);
}
if(!file_getext(fname))
fname += ".menu";
// Is menu already running (on stack)? If so, pop contexts to return to it
for(var i in menu_stack)
if(menu_stack[i].toUpperCase()==fname.toUpperCase()) {
pop_count=menu_stack.length-(i+1);
return;
}
log("Reading menu file" + fname);
var menu;
if((menu=read_menu(fname))==undefined)
return(false);
menu_stack.push(fname);
var done = false;
while(bbs.online && !done) {
if(pop_count) {
pop_count--;
break;
}
var cmd_keys="";
var cmd_list=new Array();
if(menu.hotkey_ext)
cmd_keys+=menu.hotkey_ext;
for(i in menu.command) {
if(menu.command[i].ars && !user.compare_ars(menu.command[i].ars))
continue;
cmd_keys+=menu.command[i].key;
cmd_list.push(menu.command[i]);
}
log("menu.show: " + menu.show);
if(menu.show || !menu.expert || !(user.settings&USER_EXPERT)) {
if(menu.file) /* static menu */
bbs.menu(menu.file);
else { /* dynamic menu */
var column=0;
for(var i in cmd_list) {
if(cmd_list[i].description) {
if(column+menu.colwidth>=console.screen_columns)
console.crlf(), column=0;
var str=format(menu.fmt
,menu.reverse ? cmd_list[i].description : cmd_list[i].key.toUpperCase()
,menu.reverse ? cmd_list[i].key.toUpperCase() : cmd_list[i].description);
console.putmsg(str);
console.right(menu.colwidth-console.strlen(str));
if(console.strlen(str)>menu.colwidth)
column+=console.strlen(str);
else
column+=menu.colwidth;
}
}
}
menu.show = false;
}
bbs.nodesync();
console.aborted=false;
if(menu.exec)
eval(menu.exec);
if(menu.prompt)
console.putmsg(eval(menu.prompt));
var cmd;
if(menu.hotkeys)
console.write(cmd=console.getkey(K_UPPER));
else
cmd=console.getstr(K_UPPER);
if(cmd==undefined)
continue;
log("menu.num_exec = " + menu.num_exec);
log("menu.maxnum = " + menu.maxnum);
if(isdigit(cmd) && menu.num_exec) {
if(parseInt(cmd)*10 <= menu.maxnum)
eval(menu.num_exec);
continue;
}
if(menu.hotkeys && cmd.toUpperCase()==menu.hotkey_ext)
cmd+=console.getkey();
print();
for(var i in cmd_list)
if(cmd_list[i].key.toUpperCase() == String(cmd).toUpperCase())
eval(cmd_list[i].exec);
}
menu_stack.pop();
}
log("exiting");