Make the emulator screen resizable.

This commit is contained in:
John "Elwin" Edwards 2012-05-09 13:38:05 -07:00
parent 5b0be4c820
commit 02cc454ad1
4 changed files with 95 additions and 12 deletions

View file

@ -14,13 +14,23 @@ var env_dontuse = {"TMUX": true, "TMUX_PANE": true};
/* Constructor for TermSessions. Note that it opens the terminal and
* adds itself to the sessions dict.
*/
function TermSession(sessid) {
function TermSession(sessid, h, w) {
/* Set up the sizes. */
w = Math.floor(Number(w));
if (!(w > 0 && w < 256))
w = 80;
this.w = w;
h = Math.floor(Number(h));
if (!(h > 0 && h < 256))
h = 25;
this.h = h;
/* Customize the environment. */
var childenv = {};
for (var key in process.env) {
if (!(key in env_dontuse))
childenv[key] = process.env[key];
}
childenv["PTYHELPER"] = "25x80";
childenv["PTYHELPER"] = String(this.h) + "x" + String(this.w);
// Should setsid get set?
var spawnopts = {"env": childenv, "cwd": process.env["HOME"]};
this.child = child_process.spawn(ptyhelp, ["bash"], spawnopts);
@ -154,10 +164,25 @@ function getFormValues(formtext) {
function login(req, res, formdata) {
var resheaders = {'Content-Type': 'text/plain'};
var sessid = randkey();
var nsession = new TermSession(sessid);
/* The TermSession constructor will check these thoroughly too, but
* you can't be too suspicious of client-supplied data. */
var w = 80;
var h = 25;
var t;
if ("w" in formdata) {
t = Math.floor(Number(formdata["w"]));
if (t > 0 && t < 256)
w = t;
}
if ("h" in formdata) {
t = Math.floor(Number(formdata["h"]));
if (t > 0 && t < 256)
h = t;
}
var nsession = new TermSession(sessid, h, w);
resheaders["Set-Cookie"] = "ID=" + sessid;
res.writeHead(200, resheaders);
res.write("l1\n" + sessid + "\n");
res.write("l1\n" + sessid + "\n" + String(h) + "x" + String(w) + "\n");
res.end();
console.log("Started new session with key " + sessid + ", pid " + nsession.child.pid);
return;