Mercurial > hg > rlgwebd
annotate shterm.js @ 142:c4304f08e35b
RLGWebD: inprogress dirs have moved
author | John "Elwin" Edwards |
---|---|
date | Sun, 20 Oct 2013 19:26:39 -0700 |
parents | 789c094675f4 |
children | c4a32007d2dc |
rev | line source |
---|---|
1 | 1 /* shterm.js: browser-side JavaScript to handle I/O for termemu.js when it |
2 * is running a shell via the webtty.js server. | |
3 */ | |
4 | |
58
7a50b4412fea
Move credentials into the drivers.
John "Elwin" Edwards <elwin@sdf.org>
parents:
14
diff
changeset
|
5 var isalive = false; // Whether the session is currently active. |
14
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
6 var nsend = 0; // The number of the next packet to send. |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
7 var nrecv = 0; // The next packet expected. |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
8 var msgQ = []; // Queue for out-of-order messages. |
140 | 9 var conn = null; // WebSocket |
13
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
10 |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
11 // A state machine that keeps track of polling the server. |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
12 var ajaxstate = { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
13 state: 0, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
14 timerID: null, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
15 clear: function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
16 if (this.timerID != null) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
17 window.clearTimeout(this.timerID); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
18 this.timerID = null; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
19 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
20 }, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
21 set: function (ms) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
22 this.clear(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
23 this.timerID = window.setTimeout(getData, ms); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
24 }, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
25 gotdata: function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
26 this.set(100); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
27 this.state = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
28 }, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
29 gotnothing: function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
30 if (this.state == 0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
31 this.set(100); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
32 this.state = 1; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
33 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
34 else if (this.state == 1) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
35 this.set(300); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
36 this.state = 2; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
37 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
38 else if (this.state == 2) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
39 this.set(1000); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
40 this.state = 3; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
41 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
42 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
43 this.set(5000); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
44 this.state = 3; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
45 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
46 }, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
47 posted: function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
48 this.set(100); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
49 this.state = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
50 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
51 }; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
52 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
53 function writeData(hexstr) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
54 var codenum; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
55 var codes = []; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
56 var nc; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
57 var u8wait = 0; /* Stores bits from previous bytes of multibyte sequences. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
58 var expect = 0; /* The number of 10------ bytes expected. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
59 /* UTF-8 translation. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
60 for (var i = 0; i < hexstr.length; i += 2) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
61 nc = Number("0x" + hexstr.substr(i, 2)); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
62 if (nc < 0x7F) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
63 /* 0------- */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
64 codes.push(nc); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
65 /* Any incomplete sequence will be discarded. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
66 u8wait = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
67 expect = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
68 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
69 else if (nc < 0xC0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
70 /* 10------ : part of a multibyte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
71 if (expect > 0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
72 u8wait <<= 6; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
73 u8wait += (nc & 0x3F); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
74 expect--; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
75 if (expect == 0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
76 codes.push(u8wait); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
77 u8wait = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
78 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
79 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
80 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
81 /* Assume an initial byte was missed. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
82 u8wait = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
83 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
84 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
85 /* These will all discard any incomplete sequence. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
86 else if (nc < 0xE0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
87 /* 110----- : introduces 2-byte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
88 u8wait = (nc & 0x1F); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
89 expect = 1; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
90 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
91 else if (nc < 0xF0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
92 /* 1110---- : introduces 3-byte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
93 u8wait = (nc & 0x0F); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
94 expect = 2; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
95 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
96 else if (nc < 0xF8) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
97 /* 11110--- : introduces 4-byte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
98 u8wait = (nc & 0x07); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
99 expect = 3; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
100 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
101 else if (nc < 0xFC) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
102 /* 111110-- : introduces 5-byte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
103 u8wait = (nc & 0x03); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
104 expect = 4; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
105 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
106 else if (nc < 0xFE) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
107 /* 1111110- : introduces 6-byte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
108 u8wait = (nc & 0x01); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
109 expect = 5; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
110 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
111 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
112 /* 1111111- : should never appear */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
113 u8wait = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
114 expect = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
115 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
116 /* Supporting all 31 bits is probably overkill... */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
117 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
118 termemu.write(codes); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
119 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
120 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
121 |
14
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
122 function processMsg(response) { |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
123 if (response.t != "d" || typeof(response.d) != "string") |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
124 return; |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
125 if (response.n === nrecv) { |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
126 writeData(response.d); |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
127 nrecv++; |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
128 var next; |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
129 /* msgQ must be shifted every time nrecv is incremented, but the process |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
130 * stops whenever an empty space, corresponding to an unarrived message, |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
131 * is encountered. |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
132 */ |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
133 while ((next = msgQ.shift()) !== undefined) { |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
134 writeData(next.d); |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
135 nrecv++; |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
136 } |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
137 } |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
138 else if (response.n > nrecv) { |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
139 /* The current message comes after one still missing. Queue this one |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
140 * for later use. |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
141 */ |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
142 debug(1, "Got packet " + response.n + ", expected " + nrecv); |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
143 msgQ[response.n - nrecv - 1] = response; |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
144 } |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
145 else { |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
146 /* This message's number was encountered previously. */ |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
147 debug(1, "Discarding packet " + response.n + ", expected " + nrecv); |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
148 } |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
149 } |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
150 |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
151 function getData() { |
58
7a50b4412fea
Move credentials into the drivers.
John "Elwin" Edwards <elwin@sdf.org>
parents:
14
diff
changeset
|
152 if (!isalive) |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
153 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
154 var datareq = new XMLHttpRequest(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
155 datareq.onreadystatechange = function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
156 if (datareq.readyState == 4 && datareq.status == 200) { |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
157 var response = JSON.parse(this.responseText); |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
158 if (!response.t) |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
159 return; |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
160 else if (response.t == "E") { |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
161 if (response.c == 1) { |
58
7a50b4412fea
Move credentials into the drivers.
John "Elwin" Edwards <elwin@sdf.org>
parents:
14
diff
changeset
|
162 isalive = false; |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
163 debug(1, "Server error: " + response.s); |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
164 } |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
165 } |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
166 else if (response.t == "n") |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
167 ajaxstate.gotnothing(); |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
168 else if (response.t == "d") { |
14
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
169 processMsg(response); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
170 ajaxstate.gotdata(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
171 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
172 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
173 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
174 }; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
175 datareq.open('GET', '/feed', true); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
176 datareq.send(null); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
177 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
178 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
179 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
180 function postResponseHandler() { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
181 if (this.readyState == 4 && this.status == 200) { |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
182 var response = JSON.parse(this.responseText); |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
183 if (!response.t || response.t == "n") |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
184 return; |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
185 else if (response.t == "E") { |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
186 if (response.c == 1) { |
58
7a50b4412fea
Move credentials into the drivers.
John "Elwin" Edwards <elwin@sdf.org>
parents:
14
diff
changeset
|
187 isalive = false; |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
188 debug(1, "Server error: " + response.s); |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
189 } |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
190 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
191 } |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
192 else if (response.t != "d") |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
193 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
194 /* It is a data message */ |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
195 if (response.d) { |
14
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
196 processMsg(response); |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
197 //debug(1, "Got packet " + response.n); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
198 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
199 ajaxstate.posted(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
200 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
201 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
202 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
203 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
204 function sendback(str) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
205 /* For responding to terminal queries. */ |
140 | 206 if (conn) { |
207 var msgObj = {"t": "d", "d": str}; | |
208 conn.send(JSON.stringify(msgObj)); | |
209 } | |
210 else { | |
211 var formdata = {"t": "d", "n": nsend++, "d": str}; | |
212 var datareq = new XMLHttpRequest(); | |
213 datareq.onreadystatechange = postResponseHandler; | |
214 datareq.open('POST', '/feed', true); | |
215 datareq.send(JSON.stringify(formdata)); | |
216 } | |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
217 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
218 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
219 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
220 function sendkey(ev) { |
140 | 221 if (!isalive) |
222 return; | |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
223 var keynum = ev.keyCode; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
224 var code; |
70
d7eb63cd7a16
Try to get some compatibility for keys.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
225 if (keynum >= 65 && keynum <= 90) { |
d7eb63cd7a16
Try to get some compatibility for keys.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
226 /* Letters. */ |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
227 if (ev.ctrlKey) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
228 keynum -= 64; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
229 else if (!ev.shiftKey) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
230 keynum += 32; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
231 code = keynum.toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
232 if (code.length < 2) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
233 code = "0" + code; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
234 } |
70
d7eb63cd7a16
Try to get some compatibility for keys.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
235 else if (keynum >= 48 && keynum <= 57) { |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
236 /* The number row. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
237 if (ev.shiftKey) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
238 code = numShifts[keynum - 48].toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
239 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
240 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
241 code = keynum.toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
242 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
243 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
244 else if (keynum in keyHexCodes) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
245 if (ev.shiftKey) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
246 code = keyHexCodes[keynum][1]; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
247 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
248 code = keyHexCodes[keynum][0]; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
249 } |
70
d7eb63cd7a16
Try to get some compatibility for keys.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
250 else if (keynum >= 16 && keynum <= 20) { |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
251 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
252 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
253 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
254 debug(1, "Ignoring keycode " + keynum); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
255 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
256 } |
140 | 257 ev.preventDefault(); |
258 if (conn) { | |
259 var msgObj = {"t": "d", "d": code}; | |
260 conn.send(JSON.stringify(msgObj)); | |
261 } | |
262 else { | |
263 var formdata = {"t": "d", "n": nsend++, "d": code}; | |
264 var datareq = new XMLHttpRequest(); | |
265 datareq.onreadystatechange = postResponseHandler; | |
266 datareq.open('POST', '/feed', true); | |
267 datareq.send(JSON.stringify(formdata)); | |
268 } | |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
269 //dkey(code); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
270 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
271 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
272 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
273 var charshifts = { '-': "5f", '=': "2b", '[': "7b", ']': "7d", '\\': "7c", |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
274 ';': "3a", '\'': "22", ',': "3c", '.': "3e", '/': "3f", '`': "7e" |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
275 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
276 |
76
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
277 var kpkeys = { "KP1": "1b4f46", "KP2": "1b4f42", "KP3": "1b5b367e", |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
278 "KP4": "1b4f44", "KP5": "1b5b45", "KP6": "1b4f43", |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
279 "KP7": "1b4f48", "KP8": "1b4f41", "KP9": "1b5b357e" }; |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
280 |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
281 function vkey(c) { |
140 | 282 if (!isalive) |
283 return; | |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
284 var keystr; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
285 if (c.match(/^[a-z]$/)) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
286 if (termemu.ctrlp()) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
287 var n = c.charCodeAt(0) - 96; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
288 keystr = n.toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
289 if (keystr.length < 2) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
290 keystr = "0" + keystr; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
291 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
292 else if (termemu.shiftp()) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
293 keystr = c.toUpperCase().charCodeAt(0).toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
294 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
295 keystr = c.charCodeAt(0).toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
296 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
297 else if (c.match(/^[0-9]$/)) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
298 if (termemu.shiftp()) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
299 keystr = numShifts[c.charCodeAt(0) - 48].toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
300 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
301 keystr = c.charCodeAt(0).toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
302 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
303 else if (c == '\n') |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
304 keystr = "0a"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
305 else if (c == '\t') |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
306 keystr = "09"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
307 else if (c == '\b') |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
308 keystr = "08"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
309 else if (c == ' ') |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
310 keystr = "20"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
311 else if (c in charshifts) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
312 if (termemu.shiftp()) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
313 keystr = charshifts[c]; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
314 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
315 keystr = c.charCodeAt(0).toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
316 } |
76
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
317 else if (c in kpkeys) { |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
318 keystr = kpkeys[c]; |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
319 } |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
320 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
321 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
322 //writeData("Sending " + keystr); |
140 | 323 if (conn) { |
324 var msgObj = {"t": "d", "d": keystr}; | |
325 conn.send(JSON.stringify(msgObj)); | |
326 } | |
327 else { | |
328 var formdata = {"t": "d", "n": nsend++, "d": keystr}; | |
329 var datareq = new XMLHttpRequest(); | |
330 datareq.onreadystatechange = postResponseHandler; | |
331 datareq.open('POST', '/feed', true); | |
332 datareq.send(JSON.stringify(formdata)); | |
333 } | |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
334 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
335 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
336 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
337 function setup() { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
338 keyHexCodes.init(); |
9
826a7ced69f8
Make the emulator screen resizable.
John "Elwin" Edwards <elwin@sdf.org>
parents:
7
diff
changeset
|
339 termemu.init("termwrap", 24, 80); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
340 setTitle("Not connected."); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
341 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
342 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
343 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
344 function toggleshift() { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
345 termemu.toggleshift(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
346 keydiv = document.getElementById("shiftkey"); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
347 if (termemu.shiftp()) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
348 keydiv.className = "keysel"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
349 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
350 keydiv.className = "key"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
351 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
352 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
353 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
354 function togglectrl() { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
355 termemu.togglectrl(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
356 keydiv = document.getElementById("ctrlkey"); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
357 if (termemu.ctrlp()) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
358 keydiv.className = "keysel"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
359 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
360 keydiv.className = "key"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
361 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
362 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
363 |
140 | 364 function loginWS(h, w) { |
365 if (conn) | |
366 return; | |
367 var sockurl = "ws://" + window.location.host + "/sock?w=" + w + "&h=" + h; | |
368 conn = new WebSocket(sockurl); | |
369 conn.onopen = function (event) { | |
370 isalive = true; | |
371 setTitle("Logged in"); | |
372 debug(1, "Logged in via WebSocket"); | |
373 } | |
374 conn.onmessage = function (event) { | |
375 var msgObj = JSON.parse(event.data); | |
376 if (msgObj.t == 'l') { | |
377 termemu.resize(msgObj.h, msgObj.w); | |
378 } | |
379 else if (msgObj.t == 'd') { | |
380 debug(0, msgObj.d); | |
381 writeData(msgObj.d); | |
382 } | |
383 else if (msgObj.t == 'q') { | |
384 debug(0, "Quit message!"); | |
385 conn.close(); | |
386 } | |
387 } | |
388 conn.onclose = function (event) { | |
389 conn = null; | |
390 isalive = false; | |
391 debug(1, "WebSocket connection closed."); | |
392 setTitle("Not connected."); | |
393 } | |
394 } | |
395 | |
9
826a7ced69f8
Make the emulator screen resizable.
John "Elwin" Edwards <elwin@sdf.org>
parents:
7
diff
changeset
|
396 function login(h, w) { |
58
7a50b4412fea
Move credentials into the drivers.
John "Elwin" Edwards <elwin@sdf.org>
parents:
14
diff
changeset
|
397 if (isalive) |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
398 return; |
140 | 399 if (window.WebSocket) { |
400 loginWS(h, w); | |
401 return; | |
402 } | |
13
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
403 params = {"login": true, "h": h, "w": w}; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
404 var req = new XMLHttpRequest(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
405 req.onreadystatechange = function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
406 if (req.readyState == 4 && req.status == 200) { |
10
d051aad3e95f
webtty: begin experimenting with JSON protocol.
John "Elwin" Edwards <elwin@sdf.org>
parents:
9
diff
changeset
|
407 var logindict = JSON.parse(req.responseText); |
d051aad3e95f
webtty: begin experimenting with JSON protocol.
John "Elwin" Edwards <elwin@sdf.org>
parents:
9
diff
changeset
|
408 if (logindict.login) { |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
409 /* Success */ |
10
d051aad3e95f
webtty: begin experimenting with JSON protocol.
John "Elwin" Edwards <elwin@sdf.org>
parents:
9
diff
changeset
|
410 termemu.resize(logindict.h, logindict.w); |
58
7a50b4412fea
Move credentials into the drivers.
John "Elwin" Edwards <elwin@sdf.org>
parents:
14
diff
changeset
|
411 isalive = true; |
13
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
412 nsend = 0; |
14
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
413 nrecv = 0; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
414 setTitle("Logged in"); |
10
d051aad3e95f
webtty: begin experimenting with JSON protocol.
John "Elwin" Edwards <elwin@sdf.org>
parents:
9
diff
changeset
|
415 debug(1, "Logged in with id " + logindict.id); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
416 getData(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
417 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
418 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
419 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
420 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
421 }; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
422 req.open('POST', '/login', true); |
13
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
423 req.send(JSON.stringify(params)); |
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
424 //req.send("login=login&h=" + String(h) + "&w=" + String(w)); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
425 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
426 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
427 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
428 function stop() { |
140 | 429 if (conn) { |
430 conn.close(); | |
431 return; | |
432 } | |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
433 var req = new XMLHttpRequest(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
434 req.onreadystatechange = function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
435 if (req.readyState == 4 && req.status == 200) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
436 /* Figure out whether or not it worked. */ |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
437 /* FIXME the server might respond with output. */ |
58
7a50b4412fea
Move credentials into the drivers.
John "Elwin" Edwards <elwin@sdf.org>
parents:
14
diff
changeset
|
438 isalive = false; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
439 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
440 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
441 }; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
442 req.open('POST', '/feed', true); |
13
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
443 req.send(JSON.stringify({"t": "q", "n": nsend++})); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
444 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
445 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
446 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
447 function setTitle(tstr) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
448 var titlespan = document.getElementById("ttitle"); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
449 var tnode = document.createTextNode(tstr); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
450 if (titlespan.childNodes.length == 0) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
451 titlespan.appendChild(tnode); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
452 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
453 titlespan.replaceChild(tnode, titlespan.childNodes[0]); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
454 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
455 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
456 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
457 function debug(level, msg) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
458 if (level < debugSuppress) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
459 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
460 var msgdiv = document.createElement("div"); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
461 var msgtext = document.createTextNode(msg); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
462 msgdiv.appendChild(msgtext); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
463 document.getElementById("debug").appendChild(msgdiv); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
464 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
465 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
466 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
467 /* This should be a termemu method. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
468 function textsize(larger) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
469 var cssSize = document.getElementById("term").style.fontSize; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
470 if (!cssSize) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
471 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
472 var match = cssSize.match(/\d*/); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
473 if (!match) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
474 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
475 var csize = Number(match[0]); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
476 var nsize; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
477 if (larger) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
478 if (csize >= 48) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
479 nsize = 48; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
480 else if (csize >= 20) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
481 nsize = csize + 4; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
482 else if (csize >= 12) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
483 nsize = csize + 2; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
484 else if (csize >= 8) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
485 nsize = csize + 1; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
486 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
487 nsize = 8; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
488 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
489 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
490 if (csize <= 8) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
491 nsize = 8; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
492 else if (csize <= 12) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
493 nsize = csize - 1; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
494 else if (csize <= 20) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
495 nsize = csize - 2; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
496 else if (csize <= 48) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
497 nsize = csize - 4; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
498 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
499 nsize = 48; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
500 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
501 document.getElementById("term").style.fontSize = nsize.toString() + "px"; |
9
826a7ced69f8
Make the emulator screen resizable.
John "Elwin" Edwards <elwin@sdf.org>
parents:
7
diff
changeset
|
502 termemu.fixsize(); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
503 debug(1, "Changing font size to " + nsize.toString()); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
504 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
505 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
506 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
507 function bell(on) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
508 var imgnode = document.getElementById("bell"); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
509 if (on) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
510 imgnode.style.visibility = "visible"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
511 window.setTimeout(bell, 1500, false); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
512 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
513 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
514 imgnode.style.visibility = "hidden"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
515 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
516 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
517 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
518 function dkey(codestr) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
519 var dstr = "Keystring: "; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
520 for (var i = 0; i < codestr.length; i += 2) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
521 code = Number("0x" + codestr.substr(i, 2)); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
522 if (code < 32 || (code >= 127 && code < 160)) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
523 dstr += "\\x" + code.toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
524 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
525 dstr += String.fromCharCode(code); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
526 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
527 debug(1, dstr); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
528 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
529 } |