finished naming functions insofar as I can without overspeculating on a few of the cryptic flow-control routines.

This commit is contained in:
Anselm Levskaya 2011-12-25 06:32:25 -08:00
parent d4984fa44c
commit 85304bd7cc
2 changed files with 295 additions and 255 deletions

File diff suppressed because it is too large Load Diff

126
term.js
View File

@ -1,4 +1,4 @@
/* /*
Javascript Terminal Javascript Terminal
Copyright (c) 2011 Fabrice Bellard Copyright (c) 2011 Fabrice Bellard
@ -185,7 +185,7 @@ Term.prototype.scroll_disp = function(n) {
} }
this.refresh(0, this.h - 1); this.refresh(0, this.h - 1);
}; };
Term.prototype.write = function(ua) { Term.prototype.write = function(char) {
function va(y) { function va(y) {
ka = Math.min(ka, y); ka = Math.min(ka, y);
la = Math.max(la, y); la = Math.max(la, y);
@ -230,8 +230,8 @@ Term.prototype.write = function(ua) {
ka = 0; ka = 0;
la = this.h - 1; la = this.h - 1;
} }
for (i = 0; i < ua.length; i++) { for (i = 0; i < char.length; i++) {
c = ua.charCodeAt(i); c = char.charCodeAt(i);
switch (this.state) { switch (this.state) {
case za: case za:
switch (c) { switch (c) {
@ -382,109 +382,109 @@ Term.prototype.write = function(ua) {
if (la >= ka) if (la >= ka)
this.refresh(ka, la); this.refresh(ka, la);
}; };
Term.prototype.writeln = function(ua) { Term.prototype.writeln = function(char) {
this.write(ua + '\r\n'); this.write(char + '\r\n');
}; };
Term.prototype.keyDownHandler = function(Da) { Term.prototype.keyDownHandler = function(event) {
var ua; var char;
ua = ""; char = "";
switch (Da.keyCode) { switch (event.keyCode) {
case 8: case 8:
ua = ""; char = "";
break; break;
case 9: case 9:
ua = "\t"; char = "\t";
break; break;
case 13: case 13:
ua = "\r"; char = "\r";
break; break;
case 27: case 27:
ua = "\x1b"; char = "\x1b";
break; break;
case 37: case 37:
ua = "\x1b[D"; char = "\x1b[D";
break; break;
case 39: case 39:
ua = "\x1b[C"; char = "\x1b[C";
break; break;
case 38: case 38:
if (Da.ctrlKey) { if (event.ctrlKey) {
this.scroll_disp(-1); this.scroll_disp(-1);
} else { } else {
ua = "\x1b[A"; char = "\x1b[A";
} }
break; break;
case 40: case 40:
if (Da.ctrlKey) { if (event.ctrlKey) {
this.scroll_disp(1); this.scroll_disp(1);
} else { } else {
ua = "\x1b[B"; char = "\x1b[B";
} }
break; break;
case 46: case 46:
ua = "\x1b[3~"; char = "\x1b[3~";
break; break;
case 45: case 45:
ua = "\x1b[2~"; char = "\x1b[2~";
break; break;
case 36: case 36:
ua = "\x1bOH"; char = "\x1bOH";
break; break;
case 35: case 35:
ua = "\x1bOF"; char = "\x1bOF";
break; break;
case 33: case 33:
if (Da.ctrlKey) { if (event.ctrlKey) {
this.scroll_disp(-(this.h - 1)); this.scroll_disp(-(this.h - 1));
} else { } else {
ua = "\x1b[5~"; char = "\x1b[5~";
} }
break; break;
case 34: case 34:
if (Da.ctrlKey) { if (event.ctrlKey) {
this.scroll_disp(this.h - 1); this.scroll_disp(this.h - 1);
} else { } else {
ua = "\x1b[6~"; char = "\x1b[6~";
} }
break; break;
default: default:
if (Da.ctrlKey) { if (event.ctrlKey) {
if (Da.keyCode >= 65 && Da.keyCode <= 90) { if (event.keyCode >= 65 && event.keyCode <= 90) {
ua = String.fromCharCode(Da.keyCode - 64); char = String.fromCharCode(event.keyCode - 64);
} else if (Da.keyCode == 32) { } else if (event.keyCode == 32) {
ua = String.fromCharCode(0); char = String.fromCharCode(0);
} }
} else if ((!this.is_mac && Da.altKey) || (this.is_mac && Da.metaKey)) { } else if ((!this.is_mac && event.altKey) || (this.is_mac && event.metaKey)) {
if (Da.keyCode >= 65 && Da.keyCode <= 90) { if (event.keyCode >= 65 && event.keyCode <= 90) {
ua = "\x1b" + String.fromCharCode(Da.keyCode + 32); char = "\x1b" + String.fromCharCode(event.keyCode + 32);
} }
} }
break; break;
} }
if (ua) { if (char) {
if (Da.stopPropagation) if (event.stopPropagation)
Da.stopPropagation(); event.stopPropagation();
if (Da.preventDefault) if (event.preventDefault)
Da.preventDefault(); event.preventDefault();
this.show_cursor(); this.show_cursor();
this.key_rep_state = 1; this.key_rep_state = 1;
this.key_rep_str = ua; this.key_rep_str = char;
this.handler(ua); this.handler(char);
return false; return false;
} else { } else {
this.key_rep_state = 0; this.key_rep_state = 0;
return true; return true;
} }
}; };
Term.prototype.keyPressHandler = function(Da) { Term.prototype.keyPressHandler = function(event) {
var ua, Ea; var char, charcode;
if (Da.stopPropagation) if (event.stopPropagation)
Da.stopPropagation(); event.stopPropagation();
if (Da.preventDefault) if (event.preventDefault)
Da.preventDefault(); event.preventDefault();
ua = ""; char = "";
if (!("charCode" in Da)) { if (!("charCode" in event)) {
Ea = Da.keyCode; charcode = event.keyCode;
if (this.key_rep_state == 1) { if (this.key_rep_state == 1) {
this.key_rep_state = 2; this.key_rep_state = 2;
return false; return false;
@ -494,23 +494,23 @@ Term.prototype.keyPressHandler = function(Da) {
return false; return false;
} }
} else { } else {
Ea = Da.charCode; charcode = event.charCode;
} }
if (Ea != 0) { if (charcode != 0) {
if (!Da.ctrlKey && ((!this.is_mac && !Da.altKey) || (this.is_mac && !Da.metaKey))) { if (!event.ctrlKey && ((!this.is_mac && !event.altKey) || (this.is_mac && !event.metaKey))) {
ua = String.fromCharCode(Ea); char = String.fromCharCode(charcode);
} }
} }
if (ua) { if (char) {
this.show_cursor(); this.show_cursor();
this.handler(ua); this.handler(char);
return false; return false;
} else { } else {
return true; return true;
} }
}; };
Term.prototype.queue_chars = function(ua) { Term.prototype.queue_chars = function(char) {
this.output_queue += ua; this.output_queue += char;
if (this.output_queue) if (this.output_queue)
setTimeout(this.outputHandler.bind(this), 0); setTimeout(this.outputHandler.bind(this), 0);
}; };
@ -520,3 +520,9 @@ Term.prototype.outputHandler = function() {
this.output_queue = ""; this.output_queue = "";
} }
}; };