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