comparison webtty.js @ 9:826a7ced69f8

Make the emulator screen resizable.
author John "Elwin" Edwards <elwin@sdf.org>
date Wed, 09 May 2012 13:38:05 -0700
parents d1b3c3af34d6
children d051aad3e95f
comparison
equal deleted inserted replaced
8:ad0a31e52007 9:826a7ced69f8
12 var env_dontuse = {"TMUX": true, "TMUX_PANE": true}; 12 var env_dontuse = {"TMUX": true, "TMUX_PANE": true};
13 13
14 /* Constructor for TermSessions. Note that it opens the terminal and 14 /* Constructor for TermSessions. Note that it opens the terminal and
15 * adds itself to the sessions dict. 15 * adds itself to the sessions dict.
16 */ 16 */
17 function TermSession(sessid) { 17 function TermSession(sessid, h, w) {
18 /* Set up the sizes. */
19 w = Math.floor(Number(w));
20 if (!(w > 0 && w < 256))
21 w = 80;
22 this.w = w;
23 h = Math.floor(Number(h));
24 if (!(h > 0 && h < 256))
25 h = 25;
26 this.h = h;
27 /* Customize the environment. */
18 var childenv = {}; 28 var childenv = {};
19 for (var key in process.env) { 29 for (var key in process.env) {
20 if (!(key in env_dontuse)) 30 if (!(key in env_dontuse))
21 childenv[key] = process.env[key]; 31 childenv[key] = process.env[key];
22 } 32 }
23 childenv["PTYHELPER"] = "25x80"; 33 childenv["PTYHELPER"] = String(this.h) + "x" + String(this.w);
24 // Should setsid get set? 34 // Should setsid get set?
25 var spawnopts = {"env": childenv, "cwd": process.env["HOME"]}; 35 var spawnopts = {"env": childenv, "cwd": process.env["HOME"]};
26 this.child = child_process.spawn(ptyhelp, ["bash"], spawnopts); 36 this.child = child_process.spawn(ptyhelp, ["bash"], spawnopts);
27 var ss = this; 37 var ss = this;
28 /* Eventually we'll need to make sure the sessid isn't in use yet. */ 38 /* Eventually we'll need to make sure the sessid isn't in use yet. */
152 } 162 }
153 163
154 function login(req, res, formdata) { 164 function login(req, res, formdata) {
155 var resheaders = {'Content-Type': 'text/plain'}; 165 var resheaders = {'Content-Type': 'text/plain'};
156 var sessid = randkey(); 166 var sessid = randkey();
157 var nsession = new TermSession(sessid); 167 /* The TermSession constructor will check these thoroughly too, but
168 * you can't be too suspicious of client-supplied data. */
169 var w = 80;
170 var h = 25;
171 var t;
172 if ("w" in formdata) {
173 t = Math.floor(Number(formdata["w"]));
174 if (t > 0 && t < 256)
175 w = t;
176 }
177 if ("h" in formdata) {
178 t = Math.floor(Number(formdata["h"]));
179 if (t > 0 && t < 256)
180 h = t;
181 }
182 var nsession = new TermSession(sessid, h, w);
158 resheaders["Set-Cookie"] = "ID=" + sessid; 183 resheaders["Set-Cookie"] = "ID=" + sessid;
159 res.writeHead(200, resheaders); 184 res.writeHead(200, resheaders);
160 res.write("l1\n" + sessid + "\n"); 185 res.write("l1\n" + sessid + "\n" + String(h) + "x" + String(w) + "\n");
161 res.end(); 186 res.end();
162 console.log("Started new session with key " + sessid + ", pid " + nsession.child.pid); 187 console.log("Started new session with key " + sessid + ", pid " + nsession.child.pid);
163 return; 188 return;
164 } 189 }
165 190