Client: don't assume the terminal is 24x80.
This commit is contained in:
parent
e6cb51d8bf
commit
ed87e67faa
3 changed files with 53 additions and 37 deletions
86
termemu.js
86
termemu.js
|
|
@ -61,8 +61,13 @@ var termemu = {
|
|||
normbuf: null, // The normal screen buffer
|
||||
altbuf: null, // The alternate screen buffer
|
||||
histbuf: null, // The screen history buffer
|
||||
/* Attributes */
|
||||
w: 0, // Screen width
|
||||
h: 0, // Screen height
|
||||
fgColor: "#b2b2b2", // Default color for text
|
||||
bgColor: "black", // Default background color
|
||||
scrT: 0, // top and bottom of scrolling region
|
||||
scrB: 0, // init() will set this properly
|
||||
c: null, // Contains cursor position and text attributes
|
||||
offedge: false, // Going off the edge doesn't mean adding a new line
|
||||
clearAttrs: function () {
|
||||
|
|
@ -123,8 +128,6 @@ var termemu = {
|
|||
else
|
||||
return fallback;
|
||||
},
|
||||
scrT: 0, // top and bottom of scrolling region
|
||||
scrB: 23,
|
||||
// These keyboard-related things don't really belong here.
|
||||
shift: false,
|
||||
shiftp: function () {
|
||||
|
|
@ -140,7 +143,7 @@ var termemu = {
|
|||
togglectrl: function () {
|
||||
this.ctrl = !this.ctrl;
|
||||
},
|
||||
init: function (divID) {
|
||||
init: function (divID, h, w) {
|
||||
/* Makes a div full of character cells. */
|
||||
if (this.screen != null)
|
||||
return;
|
||||
|
|
@ -150,6 +153,19 @@ var termemu = {
|
|||
while (owrap.firstChild != null)
|
||||
owrap.removeChild(owrap.firstChild);
|
||||
this.c = new Cursor(null);
|
||||
/* Set up the sizes. */
|
||||
var tn;
|
||||
tn = Number(h);
|
||||
if (tn > 0 && tn < 256)
|
||||
this.h = tn;
|
||||
else
|
||||
this.h = 24;
|
||||
tn = Number(w);
|
||||
if (tn > 0 && tn < 256)
|
||||
this.w = tn;
|
||||
else
|
||||
this.w = 80;
|
||||
this.scrB = this.h - 1;
|
||||
/* Create the contents of the terminal div */
|
||||
this.inwrap = document.createElement("div");
|
||||
this.inwrap.id = "inwrap";
|
||||
|
|
@ -165,7 +181,7 @@ var termemu = {
|
|||
this.normbuf = document.createElement("div");
|
||||
this.normbuf.id = "normbuf";
|
||||
termdiv.appendChild(this.normbuf);
|
||||
for (var row = 0; row < 24; row++) {
|
||||
for (var row = 0; row < this.h; row++) {
|
||||
this.normbuf.appendChild(this.makeRow());
|
||||
}
|
||||
this.altbuf = document.createElement("div");
|
||||
|
|
@ -227,7 +243,7 @@ var termemu = {
|
|||
return;
|
||||
while (this.altbuf.firstChild != null)
|
||||
this.altbuf.removeChild(this.altbuf.firstChild);
|
||||
for (var i = 0; i < 24; i++) {
|
||||
for (var i = 0; i < this.h; i++) {
|
||||
this.altbuf.appendChild(this.makeRow());
|
||||
}
|
||||
this.normc = new Cursor(this.c);
|
||||
|
|
@ -266,8 +282,8 @@ var termemu = {
|
|||
this.offedge = false;
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
else if (x > 79)
|
||||
x = 79;
|
||||
else if (x >= this.w)
|
||||
x = this.w - 1;
|
||||
}
|
||||
if (y == null) {
|
||||
if (this.c.y != null)
|
||||
|
|
@ -277,8 +293,8 @@ var termemu = {
|
|||
}
|
||||
else if (y < 0)
|
||||
y = 0;
|
||||
else if (y > 23)
|
||||
y = 23;
|
||||
else if (y >= this.h)
|
||||
y = this.h - 1;
|
||||
/* Un-reverse video the current location. */
|
||||
this.flipCursor();
|
||||
this.c.x = x;
|
||||
|
|
@ -314,7 +330,7 @@ var termemu = {
|
|||
var blankrow = this.makeRow();
|
||||
/* Careful with the order */
|
||||
if (lines > 0) {
|
||||
if (this.scrB == 23)
|
||||
if (this.scrB == this.h - 1)
|
||||
this.screen.appendChild(blankrow);
|
||||
else
|
||||
this.screen.insertBefore(blankrow, this.screen.childNodes[this.scrB
|
||||
|
|
@ -334,8 +350,8 @@ var termemu = {
|
|||
},
|
||||
newline: function (doReturn) {
|
||||
if (this.c.y == this.scrB)
|
||||
this.scroll(1)
|
||||
else if (this.c.y < 23)
|
||||
this.scroll(1);
|
||||
else if (this.c.y < this.h - 1)
|
||||
this.cmove(this.c.y + 1, null);
|
||||
/* If the cursor is at the bottom but outside the scrolling region,
|
||||
* nothing can be done. */
|
||||
|
|
@ -350,7 +366,7 @@ var termemu = {
|
|||
this.cmove(this.c.y - 1, null);
|
||||
},
|
||||
advance: function () {
|
||||
if (this.c.x < 79)
|
||||
if (this.c.x < this.w - 1)
|
||||
this.cmove(null, this.c.x + 1);
|
||||
else {
|
||||
this.offedge = true;
|
||||
|
|
@ -378,11 +394,11 @@ var termemu = {
|
|||
this.saved = null;
|
||||
this.normc = null;
|
||||
this.scrT = 0;
|
||||
this.scrB = 23;
|
||||
this.scrB = this.h - 1;
|
||||
while (this.histbuf.firstChild != null) {
|
||||
this.histbuf.removeChild(this.histbuf.firstChild);
|
||||
}
|
||||
for (var i = 0; i < 24; i++) {
|
||||
for (var i = 0; i < this.h; i++) {
|
||||
this.screen.replaceChild(this.makeRow(), this.screen.childNodes[i]);
|
||||
}
|
||||
this.flipCursor(); // make it appear in the new row
|
||||
|
|
@ -557,10 +573,10 @@ var termemu = {
|
|||
else if (codes[i] == 9) {
|
||||
/* tab */
|
||||
var xnew;
|
||||
if (this.c.x < 79) {
|
||||
if (this.c.x < this.w - 1) {
|
||||
xnew = 8 * (Math.floor(this.c.x / 8) + 1);
|
||||
if (xnew > 79)
|
||||
xnew = 79;
|
||||
if (xnew >= this.w)
|
||||
xnew = this.w - 1;
|
||||
this.cmove(null, xnew);
|
||||
}
|
||||
else {
|
||||
|
|
@ -701,10 +717,10 @@ var termemu = {
|
|||
y = params[0] - 1;
|
||||
if (params[1])
|
||||
x = params[1] - 1;
|
||||
if (y > 23)
|
||||
y = 23;
|
||||
if (x > 79)
|
||||
x = 79;
|
||||
if (y >= this.h)
|
||||
y = this.h - 1;
|
||||
if (x >= this.w)
|
||||
x = this.w - 1;
|
||||
debug(0, "Moving to row " + y + ", col " + x);
|
||||
this.cmove(y, x);
|
||||
}
|
||||
|
|
@ -717,8 +733,8 @@ var termemu = {
|
|||
}
|
||||
while (count > 0) {
|
||||
x = 8 * (Math.floor(x / 8) + 1);
|
||||
if (x > 79) {
|
||||
x = 79;
|
||||
if (x >= this.w) {
|
||||
x = this.w - 1;
|
||||
break;
|
||||
}
|
||||
count--;
|
||||
|
|
@ -739,7 +755,7 @@ var termemu = {
|
|||
if (!params[0]) {
|
||||
/* Either 0 or not given */
|
||||
start = this.c.y + 1;
|
||||
end = 23;
|
||||
end = this.h - 1;
|
||||
cols = 1;
|
||||
}
|
||||
else if (params[0] == 1) {
|
||||
|
|
@ -749,7 +765,7 @@ var termemu = {
|
|||
}
|
||||
else if (params[0] == 2) {
|
||||
start = 0;
|
||||
end = 23;
|
||||
end = this.h - 1;
|
||||
cols = 0;
|
||||
}
|
||||
else {
|
||||
|
|
@ -763,7 +779,7 @@ var termemu = {
|
|||
/* Otherwise, the whole screen was erased and the active row doesn't
|
||||
* need special treatment. */
|
||||
var cursrow = this.screen.childNodes[this.c.y];
|
||||
for (var ncol = this.c.x; ncol >= 0 && ncol < 80; ncol += cols) {
|
||||
for (var ncol = this.c.x; ncol >= 0 && ncol < this.w; ncol += cols) {
|
||||
cursrow.replaceChild(this.makeCell(' '), cursrow.childNodes[ncol]);
|
||||
}
|
||||
}
|
||||
|
|
@ -790,11 +806,11 @@ var termemu = {
|
|||
}
|
||||
else if (params[0] == 2) {
|
||||
start = 0;
|
||||
end = 79;
|
||||
end = this.w - 1;
|
||||
}
|
||||
else {
|
||||
start = this.c.x;
|
||||
end = 79;
|
||||
end = this.w - 1;
|
||||
}
|
||||
var rowdiv = this.screen.childNodes[this.c.y];
|
||||
for (var i = start; i <= end; i++) {
|
||||
|
|
@ -824,7 +840,7 @@ var termemu = {
|
|||
this.screen.insertBefore(blankrow, this.screen.childNodes[this.c.y]);
|
||||
}
|
||||
else {
|
||||
if (this.scrB == 23)
|
||||
if (this.scrB == this.h - 1)
|
||||
this.screen.appendChild(blankrow);
|
||||
else
|
||||
this.screen.insertBefore(blankrow, this.screen.childNodes[this.scrB
|
||||
|
|
@ -870,7 +886,7 @@ var termemu = {
|
|||
return;
|
||||
}
|
||||
var row = this.screen.childNodes[this.c.y];
|
||||
for (var i = 0; i < count && this.c.x + i < 80; i++) {
|
||||
for (var i = 0; i < count && this.c.x + i < this.w; i++) {
|
||||
row.replaceChild(this.makeCell(' '), row.childNodes[this.c.x + i]);
|
||||
}
|
||||
this.flipCursor();
|
||||
|
|
@ -1012,10 +1028,10 @@ var termemu = {
|
|||
else if (c == 114) {
|
||||
/* r - set scrolling region */
|
||||
var t = 0;
|
||||
var b = 23;
|
||||
if (params[0] && params[0] <= 23)
|
||||
var b = this.h - 1;
|
||||
if (params[0] && params[0] <= this.h - 1)
|
||||
t = params[0] - 1;
|
||||
if (params[1] && params[1] <= 24)
|
||||
if (params[1] && params[1] <= this.h)
|
||||
b = params[1] - 1;
|
||||
if (b <= t)
|
||||
return;
|
||||
|
|
@ -1076,7 +1092,7 @@ var termemu = {
|
|||
makeRow: function() {
|
||||
var blankrow = document.createElement("div");
|
||||
blankrow.className = "termrow";
|
||||
for (var i = 0; i < 80; i++)
|
||||
for (var i = 0; i < this.w; i++)
|
||||
blankrow.appendChild(this.makeCell(' '));
|
||||
return blankrow;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue