-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfonttest.js
150 lines (141 loc) · 3.37 KB
/
fonttest.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
// $Id: fonttest.js,v 1.1 2018/02/02 13:04:12 rswindell Exp $
var cterm = load({}, 'cterm_lib.js');
var ansiterm = load({}, 'ansiterm_lib.js');
load('sbbsdefs.js');
var verbose = true;
function printable(ch)
{
switch(ascii(ch)) {
case '\x00':
case '\x07':
case '\b':
case '\t':
case '\r':
case '\n':
case '\f':
case '\x1b':
return '.';
}
return ch;
}
function demo_font(slot, blink)
{
print('Enabled modes ' + cterm.query_mode());
var activated = cterm.activate_font(cterm.font_styles.blink, slot);
print("Activate font result: " + activated);
if(activated !== true)
return;
ansiterm.send('ext_mode', blink ? 'clear':'set', 'no_blink');
console.attributes = LIGHTGRAY|BLINK;
for(var ch = 0; ch < 255; ch++) {
if(verbose)
console.write(format("%02x%c ", ch, printable(ch)));
else
console.write(format("%c", printable(ch)));
}
console.crlf();
printf("\xc9\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xbb\r\n");
printf("\xba Hello, World! This is font %-3u \xba\r\n", slot);
printf("\xc8\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xbc\r\n");
printf("\1nNormal High Blink High-blink\r\n");
printf("\1nExample \1hExample \1n\1iExample \1hExample\r\n");
console.crlf();
console.attributes = LIGHTGRAY;
}
function demo_files()
{
var files = directory(argv[0]);
var filenum = 0;
var blink = false;
while(files.length && bbs.online) {
console.clear(WHITE);
printf("Font file: %s\1n\r\n\r\n", files[filenum]);
var f = new File(files[filenum]);
if(!f.open("rb")) {
alert("FAILURE opening " + f.name);
break;
}
var data = f.read();
f.close();
cterm.load_font(cterm.font_slot_last, data, /* force: */true);
demo_font(cterm.font_slot_last, blink);
console.mnemonics("Which, ~+, ~-, ~Blink-toggle, ~Verbosity-toggle, ~Delete, or ~Quit: ");
var which = console.getkeys('-+BQDV', files.length - 1);
switch(which) {
case 'Q':
exit();
case 'V':
verbose = !verbose;
break;
case 'B':
blink = !blink;
break;
case '+':
filenum++;
if(filenum >= files.length)
filenum = 0;
break;
case 'D':
file_remove(files[filenum]);
files.splice(filenum, 1);
// fall-through
case '-':
filenum--;
if(filenum < 0)
filenum = files.length - 1;
break;
default:
filenum = parseInt(which);
if(!filenum)
filenum = 0;
break;
}
}
}
function demo_slots()
{
var slot = 0;
var blink = false;
while(bbs.online) {
console.clear(WHITE);
printf("Slot %d\1n\r\n\r\n", slot);
demo_font(slot, blink);
console.mnemonics("Which, ~+, ~-, ~Blink-toggle, ~Verbosity-toggle, or ~Quit: ");
var which = console.getkeys('-+QVB', cterm.font_slot_last);
switch(which) {
case 'Q':
exit();
case 'V':
verbose = !verbose;
break;
case 'B':
blink = !blink;
break;
case '+':
slot++;
if(slot > cterm.font_slot_last)
slot = 0;
break;
case '-':
slot--;
if(slot < 0)
slot = cterm.font_slot_last;
break;
default:
slot = parseInt(which);
if(!slot)
slot = 0;
break;
}
}
}
function main()
{
ansiterm.send('ext_mode', 'save_all');
js.on_exit("ansiterm.send('ext_mode', 'restore_all')");
if(argc)
demo_files();
else
demo_slots();
}
main();