-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsbbsedit.js
284 lines (247 loc) · 5.22 KB
/
sbbsedit.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
// sbbsedit.js
// Full-screen message editor for Synchronet v3.10m+
// $Id: sbbsedit.js,v 1.4 2003/07/08 10:33:38 rswindell Exp $
const REVISION = "$Revision: 1.4 $".split(' ')[1];
const debug=true;
// Message header display format
var hdr_fmt = "\1b\1h%-4s\1n\1b: \1h\1c%.60s\1>\r\n";
var stat_fmt = "\1h\1w\0014 SBBSedit v" + REVISION + " - Type \1y/?\1w for help";
if(debug)
stat_fmt += "\1y row=%d l=%d offset=%d";
stat_fmt+="\1>\1n";
var tab_size = 4;
load("sbbsdefs.js");
if(!argc) {
alert("No filename specified");
exit();
}
var subj,to,from;
var row = 0;
var rows = console.screen_rows;
var fname = argv[0];
var line = new Array();
var ctrlkey_passthru=console.ctrlkey_passthru;
console.ctrlkey_passthru|=(1<<3); // Ctrl-C
console.ctrlkey_passthru|=(1<<11); // Ctrl-K
console.ctrlkey_passthru|=(1<<16); // Ctrl-P
console.ctrlkey_passthru|=(1<<20); // Ctrl-T
console.ctrlkey_passthru|=(1<<21); // Ctrl-U
f = new File(fname);
if(f.open("r")) {
line = f.readAll();
f.close();
print("Read " + line.length + " lines");
}
console.attributes = LIGHTGRAY;
console.clear();
drop_file = new File(system.node_dir + "editor.inf");
if(drop_file.exists && drop_file.open("r")) {
info = drop_file.readAll();
delete drop_file;
subj=info[0];
to=info[1];
from=info[3];
}
show_header();
show_tabline();
home = console.getxy();
row = home.y;
var l=0;
if(line.length)
show_text(0);
update_status();
var offset;
while(bbs.online) {
update_status();
console.clearline();
console.write("\r"); /* make sure we're at column 0, always */
str=line[l];
if(str==undefined)
str="";
if(offset==undefined || offset>str.length)
offset=str.length;
console.write(str);
if(offset!=str.length) {
if(offset==0)
console.write('\r');
else
console.left(str.length-offset);
}
var done=false;
while(bbs.online && !done) {
ch=console.getkey();
switch(ch) {
case '\r':
done=true;
continue;
case '\b':
if(offset) {
str=str.slice(0,offset-1)+str.slice(offset);
offset--;
console.print("\b");
console.cleartoeol();
console.print(str.slice(offset));
}
continue;
}
console.write(ch);
str=str.slice(0,offset)+ch+str.slice(offset);
offset++;
}
log(str);
/* Allow "inline" cursor up/down movement using getstr_offset */
if(str.length && offset==str.length)
delete offset;
/* Commands */
switch(str.toLowerCase()) {
case "/s": /* SAVE */
if(!f.open("w"))
alert("Error " + errno + " opening " + f.name);
else {
f.writeAll(line);
f.close();
}
/* fall-through */
case "/abt": /* ABORT */
bail();
break;
case "/clr": /* CLEAR */
line = new Array();
console.gotoxy(home);
show_text(0);
continue;
case "/?": /* HELP */
case "/help":
console.clear();
bbs.menu("editor");
redraw(l);
continue;
case "/attr": /* ATTRIBUTES */
console.clear();
bbs.menu("attr");
redraw(l);
continue;
case "/l":
redraw(l);
continue;
case "/d": /* Delete current line */
line.splice(l,1);
show_text(0);
continue;
}
line[l]=str;
if(console.status&(CON_UPARROW|CON_BACKSPACE|CON_LEFTARROW|CON_DELETELINE)) {
if(console.status&CON_DELETELINE) {
/* Delete line */
line.splice(l,1);
show_text(0); /* should be optimized */
continue;
}
if(console.status&CON_BACKSPACE && str.length==0) {
/* Delete line */
line.splice(l,1);
if(l) l--;
if(row>home.y) {
console.up();
row--;
}
show_text(0);
continue;
}
if(l) {
l--;
if(row>home.y) {
console.up();
row--;
} else
show_text(l);
}
console.write("\r");
} else {
if(console.status&CON_DOWNARROW && l+1>=line.length)
continue; /* Down allow arrow down past EOF */
l++;
if(console.status&CON_INSERT && !(console.status&CON_DOWNARROW)) {
line.splice(l,0,""); /* Insert a blank line */
show_text(0);
}
if(row+1>=rows)
l=show_text(first_line(l,row));
else {
console.crlf();
row++;
}
}
}
bail();
function bail()
{
console.clear();
console.ctrlkey_passthru=ctrlkey_passthru;
exit();
}
function show_text(begin)
{
var save_row=row;
console.pushxy();
console.gotoxy(home);
row=home.y;
for(var l=begin; row<rows; l++,row++) {
console.clearline();
if(l < line.length)
console.putmsg(line[l]);
if(row<rows-1)
console.crlf();
}
console.popxy();
row=save_row;
return(l-1);
}
function update_status()
{
console.pushxy();
console.gotoxy(1,rows);
printf(stat_fmt,row,l,offset);
console.popxy();
}
function show_header()
{
if(subj!=undefined)
printf(hdr_fmt, "Subj", subj);
if(to!=undefined)
printf(hdr_fmt, "To", to);
if(from!=undefined)
printf(hdr_fmt, "From", from);
}
function show_tabline()
{
/* Display tab line */
for(i=0;i<(console.screen_columns-1);i++)
if(i && (i%tab_size)==0) {
if((i%(tab_size*2))==0) {
console.attributes=CYAN|HIGH;
console.print('|');
} else
console.print(ascii(254));
} else {
console.attributes=YELLOW|HIGH;
console.print(ascii(250));
}
console.crlf();
}
function redraw(l)
{
save_row=row;
console.attributes=LIGHTGRAY;
console.clear();
show_header();
show_tabline();
console.attributes=LIGHTGRAY;
show_text(first_line(l,row));
console.gotoxy(1,row=save_row);
}
function first_line(l,row)
{
return(l-(row-home.y));
}
/* End of edit.js */