Mercurial > hg > rlgwebd
annotate shterm.js @ 112:4f2b89e6fde2
RLG-Web: improvements to choices and status messaging.
Server-side, have gamemux 'end' events include the name and game, so
they can be sent to WebSockets connected to /status. This means a
WebSocket client only needs to update its choice list when it gets a
begin or end message with its own username. So it only needs to check
/pstatus/<name> at those times and can stop polling.
author | John "Elwin" Edwards <elwin@sdf.org> |
---|---|
date | Mon, 16 Jul 2012 08:23:51 -0700 |
parents | a497ecd116d9 |
children | 789c094675f4 |
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. |
13
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
9 |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
10 // 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
|
11 var ajaxstate = { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
12 state: 0, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
13 timerID: null, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
14 clear: function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
15 if (this.timerID != null) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
16 window.clearTimeout(this.timerID); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
17 this.timerID = null; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
18 } |
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 set: function (ms) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
21 this.clear(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
22 this.timerID = window.setTimeout(getData, ms); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
23 }, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
24 gotdata: function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
25 this.set(100); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
26 this.state = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
27 }, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
28 gotnothing: function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
29 if (this.state == 0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
30 this.set(100); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
31 this.state = 1; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
32 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
33 else if (this.state == 1) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
34 this.set(300); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
35 this.state = 2; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
36 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
37 else if (this.state == 2) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
38 this.set(1000); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
39 this.state = 3; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
40 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
41 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
42 this.set(5000); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
43 this.state = 3; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
44 } |
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 posted: function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
47 this.set(100); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
48 this.state = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
49 } |
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 function writeData(hexstr) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
53 var codenum; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
54 var codes = []; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
55 var nc; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
56 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
|
57 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
|
58 /* UTF-8 translation. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
59 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
|
60 nc = Number("0x" + hexstr.substr(i, 2)); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
61 if (nc < 0x7F) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
62 /* 0------- */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
63 codes.push(nc); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
64 /* Any incomplete sequence will be discarded. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
65 u8wait = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
66 expect = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
67 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
68 else if (nc < 0xC0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
69 /* 10------ : part of a multibyte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
70 if (expect > 0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
71 u8wait <<= 6; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
72 u8wait += (nc & 0x3F); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
73 expect--; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
74 if (expect == 0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
75 codes.push(u8wait); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
76 u8wait = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
77 } |
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 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
80 /* Assume an initial byte was missed. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
81 u8wait = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
82 } |
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 /* These will all discard any incomplete sequence. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
85 else if (nc < 0xE0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
86 /* 110----- : introduces 2-byte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
87 u8wait = (nc & 0x1F); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
88 expect = 1; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
89 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
90 else if (nc < 0xF0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
91 /* 1110---- : introduces 3-byte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
92 u8wait = (nc & 0x0F); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
93 expect = 2; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
94 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
95 else if (nc < 0xF8) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
96 /* 11110--- : introduces 4-byte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
97 u8wait = (nc & 0x07); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
98 expect = 3; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
99 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
100 else if (nc < 0xFC) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
101 /* 111110-- : introduces 5-byte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
102 u8wait = (nc & 0x03); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
103 expect = 4; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
104 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
105 else if (nc < 0xFE) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
106 /* 1111110- : introduces 6-byte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
107 u8wait = (nc & 0x01); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
108 expect = 5; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
109 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
110 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
111 /* 1111111- : should never appear */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
112 u8wait = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
113 expect = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
114 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
115 /* Supporting all 31 bits is probably overkill... */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
116 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
117 termemu.write(codes); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
118 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
119 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
120 |
14
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
121 function processMsg(response) { |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
122 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
|
123 return; |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
124 if (response.n === nrecv) { |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
125 writeData(response.d); |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
126 nrecv++; |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
127 var next; |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
128 /* 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
|
129 * 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
|
130 * is encountered. |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
131 */ |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
132 while ((next = msgQ.shift()) !== undefined) { |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
133 writeData(next.d); |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
134 nrecv++; |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
135 } |
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 else if (response.n > nrecv) { |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
138 /* 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
|
139 * for later use. |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
140 */ |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
141 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
|
142 msgQ[response.n - nrecv - 1] = response; |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
143 } |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
144 else { |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
145 /* This message's number was encountered previously. */ |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
146 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
|
147 } |
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 |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
150 function getData() { |
58
7a50b4412fea
Move credentials into the drivers.
John "Elwin" Edwards <elwin@sdf.org>
parents:
14
diff
changeset
|
151 if (!isalive) |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
152 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
153 var datareq = new XMLHttpRequest(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
154 datareq.onreadystatechange = function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
155 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
|
156 var response = JSON.parse(this.responseText); |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
157 if (!response.t) |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
158 return; |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
159 else if (response.t == "E") { |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
160 if (response.c == 1) { |
58
7a50b4412fea
Move credentials into the drivers.
John "Elwin" Edwards <elwin@sdf.org>
parents:
14
diff
changeset
|
161 isalive = false; |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
162 debug(1, "Server error: " + response.s); |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
163 } |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
164 } |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
165 else if (response.t == "n") |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
166 ajaxstate.gotnothing(); |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
167 else if (response.t == "d") { |
14
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
168 processMsg(response); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
169 ajaxstate.gotdata(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
170 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
171 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
172 } |
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 datareq.open('GET', '/feed', true); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
175 datareq.send(null); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
176 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
177 } |
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 function postResponseHandler() { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
180 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
|
181 var response = JSON.parse(this.responseText); |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
182 if (!response.t || response.t == "n") |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
183 return; |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
184 else if (response.t == "E") { |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
185 if (response.c == 1) { |
58
7a50b4412fea
Move credentials into the drivers.
John "Elwin" Edwards <elwin@sdf.org>
parents:
14
diff
changeset
|
186 isalive = false; |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
187 debug(1, "Server error: " + response.s); |
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
188 } |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
189 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
190 } |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
191 else if (response.t != "d") |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
192 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
193 /* It is a data message */ |
11
481dcee353c9
webtty: switch all server responses to JSON.
John "Elwin" Edwards <elwin@sdf.org>
parents:
10
diff
changeset
|
194 if (response.d) { |
14
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
195 processMsg(response); |
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
196 //debug(1, "Got packet " + response.n); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
197 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
198 ajaxstate.posted(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
199 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
200 } |
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 function sendback(str) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
204 /* For responding to terminal queries. */ |
13
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
205 var formdata = {"t": "d", "n": nsend++, "d": str}; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
206 var datareq = new XMLHttpRequest(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
207 datareq.onreadystatechange = postResponseHandler; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
208 datareq.open('POST', '/feed', true); |
13
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
209 datareq.send(JSON.stringify(formdata)); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
210 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
211 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
212 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
213 function sendkey(ev) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
214 var keynum = ev.keyCode; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
215 var code; |
70
d7eb63cd7a16
Try to get some compatibility for keys.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
216 if (keynum >= 65 && keynum <= 90) { |
d7eb63cd7a16
Try to get some compatibility for keys.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
217 /* Letters. */ |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
218 if (ev.ctrlKey) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
219 keynum -= 64; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
220 else if (!ev.shiftKey) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
221 keynum += 32; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
222 code = keynum.toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
223 if (code.length < 2) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
224 code = "0" + code; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
225 } |
70
d7eb63cd7a16
Try to get some compatibility for keys.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
226 else if (keynum >= 48 && keynum <= 57) { |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
227 /* The number row. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
228 if (ev.shiftKey) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
229 code = numShifts[keynum - 48].toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
230 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
231 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
232 code = keynum.toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
233 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
234 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
235 else if (keynum in keyHexCodes) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
236 if (ev.shiftKey) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
237 code = keyHexCodes[keynum][1]; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
238 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
239 code = keyHexCodes[keynum][0]; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
240 } |
70
d7eb63cd7a16
Try to get some compatibility for keys.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
241 else if (keynum >= 16 && keynum <= 20) { |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
242 return; |
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 { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
245 debug(1, "Ignoring keycode " + keynum); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
246 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
247 } |
58
7a50b4412fea
Move credentials into the drivers.
John "Elwin" Edwards <elwin@sdf.org>
parents:
14
diff
changeset
|
248 if (isalive) |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
249 ev.preventDefault(); |
13
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
250 var formdata = {"t": "d", "n": nsend++, "d": code}; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
251 var datareq = new XMLHttpRequest(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
252 datareq.onreadystatechange = postResponseHandler; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
253 datareq.open('POST', '/feed', true); |
13
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
254 datareq.send(JSON.stringify(formdata)); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
255 //dkey(code); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
256 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
257 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
258 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
259 var charshifts = { '-': "5f", '=': "2b", '[': "7b", ']': "7d", '\\': "7c", |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
260 ';': "3a", '\'': "22", ',': "3c", '.': "3e", '/': "3f", '`': "7e" |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
261 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
262 |
76
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
263 var kpkeys = { "KP1": "1b4f46", "KP2": "1b4f42", "KP3": "1b5b367e", |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
264 "KP4": "1b4f44", "KP5": "1b5b45", "KP6": "1b4f43", |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
265 "KP7": "1b4f48", "KP8": "1b4f41", "KP9": "1b5b357e" }; |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
266 |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
267 function vkey(c) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
268 var keystr; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
269 if (c.match(/^[a-z]$/)) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
270 if (termemu.ctrlp()) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
271 var n = c.charCodeAt(0) - 96; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
272 keystr = n.toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
273 if (keystr.length < 2) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
274 keystr = "0" + keystr; |
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 else if (termemu.shiftp()) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
277 keystr = c.toUpperCase().charCodeAt(0).toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
278 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
279 keystr = c.charCodeAt(0).toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
280 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
281 else if (c.match(/^[0-9]$/)) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
282 if (termemu.shiftp()) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
283 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
|
284 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
285 keystr = c.charCodeAt(0).toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
286 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
287 else if (c == '\n') |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
288 keystr = "0a"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
289 else if (c == '\t') |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
290 keystr = "09"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
291 else if (c == '\b') |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
292 keystr = "08"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
293 else if (c == ' ') |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
294 keystr = "20"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
295 else if (c in charshifts) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
296 if (termemu.shiftp()) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
297 keystr = charshifts[c]; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
298 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
299 keystr = c.charCodeAt(0).toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
300 } |
76
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
301 else if (c in kpkeys) { |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
302 keystr = kpkeys[c]; |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
303 } |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
304 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
305 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
306 //writeData("Sending " + keystr); |
70
d7eb63cd7a16
Try to get some compatibility for keys.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
307 var formdata = {"t": "d", "n": nsend++, "d": keystr}; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
308 var datareq = new XMLHttpRequest(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
309 datareq.onreadystatechange = postResponseHandler; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
310 datareq.open('POST', '/feed', true); |
13
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
311 datareq.send(JSON.stringify(formdata)); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
312 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
313 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
314 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
315 function setup() { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
316 keyHexCodes.init(); |
9
826a7ced69f8
Make the emulator screen resizable.
John "Elwin" Edwards <elwin@sdf.org>
parents:
7
diff
changeset
|
317 termemu.init("termwrap", 24, 80); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
318 setTitle("Not connected."); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
319 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
320 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
321 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
322 function toggleshift() { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
323 termemu.toggleshift(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
324 keydiv = document.getElementById("shiftkey"); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
325 if (termemu.shiftp()) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
326 keydiv.className = "keysel"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
327 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
328 keydiv.className = "key"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
329 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
330 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
331 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
332 function togglectrl() { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
333 termemu.togglectrl(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
334 keydiv = document.getElementById("ctrlkey"); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
335 if (termemu.ctrlp()) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
336 keydiv.className = "keysel"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
337 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
338 keydiv.className = "key"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
339 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
340 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
341 |
9
826a7ced69f8
Make the emulator screen resizable.
John "Elwin" Edwards <elwin@sdf.org>
parents:
7
diff
changeset
|
342 function login(h, w) { |
58
7a50b4412fea
Move credentials into the drivers.
John "Elwin" Edwards <elwin@sdf.org>
parents:
14
diff
changeset
|
343 if (isalive) |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
344 return; |
13
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
345 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
|
346 var req = new XMLHttpRequest(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
347 req.onreadystatechange = function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
348 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
|
349 var logindict = JSON.parse(req.responseText); |
d051aad3e95f
webtty: begin experimenting with JSON protocol.
John "Elwin" Edwards <elwin@sdf.org>
parents:
9
diff
changeset
|
350 if (logindict.login) { |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
351 /* Success */ |
10
d051aad3e95f
webtty: begin experimenting with JSON protocol.
John "Elwin" Edwards <elwin@sdf.org>
parents:
9
diff
changeset
|
352 termemu.resize(logindict.h, logindict.w); |
58
7a50b4412fea
Move credentials into the drivers.
John "Elwin" Edwards <elwin@sdf.org>
parents:
14
diff
changeset
|
353 isalive = true; |
13
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
354 nsend = 0; |
14
155f3c104759
shterm.js: Client-side message ordering
John "Elwin" Edwards <elwin@sdf.org>
parents:
13
diff
changeset
|
355 nrecv = 0; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
356 setTitle("Logged in"); |
10
d051aad3e95f
webtty: begin experimenting with JSON protocol.
John "Elwin" Edwards <elwin@sdf.org>
parents:
9
diff
changeset
|
357 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
|
358 getData(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
359 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
360 } |
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 }; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
364 req.open('POST', '/login', true); |
13
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
365 req.send(JSON.stringify(params)); |
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
366 //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
|
367 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
368 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
369 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
370 function stop() { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
371 var req = new XMLHttpRequest(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
372 req.onreadystatechange = function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
373 if (req.readyState == 4 && req.status == 200) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
374 /* 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
|
375 /* FIXME the server might respond with output. */ |
58
7a50b4412fea
Move credentials into the drivers.
John "Elwin" Edwards <elwin@sdf.org>
parents:
14
diff
changeset
|
376 isalive = false; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
377 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
378 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
379 }; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
380 req.open('POST', '/feed', true); |
13
bf7c26d0b66d
webtty: switch upward protocol to JSON
John "Elwin" Edwards <elwin@sdf.org>
parents:
12
diff
changeset
|
381 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
|
382 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
383 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
384 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
385 function setTitle(tstr) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
386 var titlespan = document.getElementById("ttitle"); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
387 var tnode = document.createTextNode(tstr); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
388 if (titlespan.childNodes.length == 0) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
389 titlespan.appendChild(tnode); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
390 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
391 titlespan.replaceChild(tnode, titlespan.childNodes[0]); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
392 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
393 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
394 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
395 function debug(level, msg) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
396 if (level < debugSuppress) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
397 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
398 var msgdiv = document.createElement("div"); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
399 var msgtext = document.createTextNode(msg); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
400 msgdiv.appendChild(msgtext); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
401 document.getElementById("debug").appendChild(msgdiv); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
402 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
403 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
404 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
405 /* This should be a termemu method. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
406 function textsize(larger) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
407 var cssSize = document.getElementById("term").style.fontSize; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
408 if (!cssSize) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
409 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
410 var match = cssSize.match(/\d*/); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
411 if (!match) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
412 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
413 var csize = Number(match[0]); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
414 var nsize; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
415 if (larger) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
416 if (csize >= 48) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
417 nsize = 48; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
418 else if (csize >= 20) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
419 nsize = csize + 4; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
420 else if (csize >= 12) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
421 nsize = csize + 2; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
422 else if (csize >= 8) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
423 nsize = csize + 1; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
424 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
425 nsize = 8; |
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 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
428 if (csize <= 8) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
429 nsize = 8; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
430 else if (csize <= 12) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
431 nsize = csize - 1; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
432 else if (csize <= 20) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
433 nsize = csize - 2; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
434 else if (csize <= 48) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
435 nsize = csize - 4; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
436 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
437 nsize = 48; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
438 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
439 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
|
440 termemu.fixsize(); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
441 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
|
442 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
443 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
444 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
445 function bell(on) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
446 var imgnode = document.getElementById("bell"); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
447 if (on) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
448 imgnode.style.visibility = "visible"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
449 window.setTimeout(bell, 1500, false); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
450 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
451 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
452 imgnode.style.visibility = "hidden"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
453 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
454 } |
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 function dkey(codestr) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
457 var dstr = "Keystring: "; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
458 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
|
459 code = Number("0x" + codestr.substr(i, 2)); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
460 if (code < 32 || (code >= 127 && code < 160)) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
461 dstr += "\\x" + code.toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
462 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
463 dstr += String.fromCharCode(code); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
464 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
465 debug(1, dstr); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
466 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
467 } |