Rename cursorLine/Col to cursorY/X

openid
Marcin Kulik 13 years ago
parent 9bc08366b3
commit 83381f220a

@ -1,8 +1,10 @@
SP.Terminal = function(cols, lines) {
this.cols = cols;
this.lines = lines;
this.cursorLine = 0;
this.cursorCol = 0;
this.cursorX = 0;
this.cursorY = 0;
this.normalBuffer = [];
this.alternateBuffer = [];
this.lineData = this.normalBuffer;
@ -20,7 +22,7 @@ SP.Terminal.prototype = {
},
getLine: function(n) {
n = (typeof n != "undefined" ? n : this.cursorLine);
n = (typeof n != "undefined" ? n : this.cursorY);
var line = this.lineData[n];
@ -33,9 +35,9 @@ SP.Terminal.prototype = {
},
clearScreen: function() {
this.lineData.length = 0;
this.cursorLine = this.cursorCol = 0;
this.element.empty();
// this.lineData.length = 0;
this.cursorY = this.cursorX = 0;
this.element.find(".line").empty();
},
switchToNormalBuffer: function() {
@ -51,17 +53,8 @@ SP.Terminal.prototype = {
renderLine: function(n) {
var html = this.getLine(n);
if (n == this.cursorLine) {
html = html.slice(0, this.cursorCol).concat(['<span class="cursor">' + (html[this.cursorCol] || '') + "</span>"], html.slice(this.cursorCol + 1) || []);
}
var missingLines = this.lineData.length - this.element.find('.line').length;
for (var i = 0; i < missingLines; i++) {
var row = $('<span class="line">');
this.element.append(row);
this.element.append("\n");
this.element.scrollTop(100000);//row.offset().top);
if (n == this.cursorY) {
html = html.slice(0, this.cursorX).concat(['<span class="cursor">' + (html[this.cursorX] || '') + "</span>"], html.slice(this.cursorX + 1) || []);
}
this.element.find(".line:eq(" + n + ")").html(html.join(''));
@ -82,7 +75,7 @@ SP.Terminal.prototype = {
},
updateLine: function(n) {
n = (typeof n != "undefined" ? n : this.cursorLine);
n = (typeof n != "undefined" ? n : this.cursorY);
this.dirtyLines.push(n);
},
@ -132,54 +125,59 @@ SP.Terminal.prototype = {
setCursorPos: function(line, col) {
line -= 1;
col -= 1;
var oldLine = this.cursorLine;
this.cursorLine = line;
this.cursorCol = col;
var oldLine = this.cursorY;
this.cursorY = line;
this.cursorX = col;
this.updateLine(oldLine);
this.updateLine();
},
saveCursor: function() {
this.savedCol = this.cursorCol;
this.savedLine = this.cursorLine;
this.savedCol = this.cursorX;
this.savedLine = this.cursorY;
},
restoreCursor: function() {
var oldLine = this.cursorLine;
var oldLine = this.cursorY;
this.cursorLine = this.savedLine;
this.cursorCol = this.savedCol;
this.cursorY = this.savedLine;
this.cursorX = this.savedCol;
this.updateLine(oldLine);
this.updateLine();
},
cursorLeft: function() {
if (this.cursorCol > 0) {
this.cursorCol -= 1;
if (this.cursorX > 0) {
this.cursorX -= 1;
this.updateLine();
}
},
cursorRight: function() {
if (this.cursorCol < this.cols) {
this.cursorCol += 1;
if (this.cursorX < this.cols) {
this.cursorX += 1;
this.updateLine();
}
},
cursorUp: function() {
if (this.cursorLine > 0) {
this.cursorLine -= 1;
this.updateLine(this.cursorLine);
this.updateLine(this.cursorLine+1);
if (this.cursorY > 0) {
this.cursorY -= 1;
this.updateLine(this.cursorY);
this.updateLine(this.cursorY+1);
}
},
cursorDown: function() {
this.cursorLine += 1;
this.updateLine(this.cursorLine);
this.updateLine(this.cursorLine-1);
if (this.cursorY + 1 < this.lines) {
this.cursorY += 1;
this.updateLine(this.cursorY-1);
this.updateLine(this.cursorY);
} else {
this.lineData.splice(0, 1);
this.updateScreen();
}
},
cursorForward: function(n) {
@ -191,14 +189,14 @@ SP.Terminal.prototype = {
},
cr: function() {
this.cursorCol = 0;
this.cursorX = 0;
this.updateLine();
},
bs: function() {
if (this.cursorCol > 0) {
this.getLine()[this.cursorCol - 1] = ' ';
this.cursorCol -= 1;
if (this.cursorX > 0) {
this.getLine()[this.cursorX - 1] = ' ';
this.cursorX -= 1;
this.updateLine();
}
},
@ -207,13 +205,13 @@ SP.Terminal.prototype = {
text = Utf8.decode(text);
for (var i=0; i<text.length; i++) {
if (this.cursorCol >= this.cols) {
this.cursorLine += 1;
this.cursorCol = 0;
if (this.cursorX >= this.cols) {
this.cursorY += 1;
this.cursorX = 0;
}
this.fill(this.cursorLine, this.cursorCol, 1, text[i]);
this.cursorCol += 1;
this.fill(this.cursorY, this.cursorX, 1, text[i]);
this.cursorX += 1;
}
this.updateLine();
@ -222,19 +220,19 @@ SP.Terminal.prototype = {
eraseData: function(n) {
if (n == 0) {
this.eraseLine(0);
for (var l=this.cursorLine+1; l<this.lineData.length; l++) {
this.lineData[l] = [];
for (var l=this.cursorY+1; l<this.lines; l++) {
this.clearLineData(l);
this.updateLine(l);
}
} else if (n == 1) {
for (var l=0; l<this.cursorLine; l++) {
this.lineData[l] = [];
for (var l=0; l<this.cursorY; l++) {
this.clearLineData(l);
this.updateLine(l);
}
this.eraseLine(n);
} else if (n == 2) {
for (var l=0; l<this.lineData.length; l++) {
this.lineData[l] = [];
for (var l=0; l<this.lines; l++) {
this.clearLineData(l);
this.updateLine(l);
}
}
@ -242,18 +240,13 @@ SP.Terminal.prototype = {
eraseLine: function(n) {
if (n == 0) {
this.fill(this.cursorLine, this.cursorCol, this.cols - this.cursorCol, ' ');
// this.lineData[this.cursorLine] = this.lineData[this.cursorLine].slice(0, this.cursorCol);
// this.lineData[this.cursorLine] = this.lineData[this.cursorLine].slice(0, this.cursorCol) + " ".times(this.cols - this.cursorCol);
this.fill(this.cursorY, this.cursorX, this.cols - this.cursorX, ' ');
this.updateLine();
} else if (n == 1) {
this.fill(this.cursorLine, 0, this.cursorCol, ' ');
// this.lineData[this.cursorLine] = " ".times(this.cursorCol).split('').concat(this.lineData[this.cursorLine].slice(this.cursorCol));
// this.lineData[this.cursorLine] = " ".times(this.cursorCol) + this.lineData[this.cursorLine].slice(this.cursorCol);
this.fill(this.cursorY, 0, this.cursorX, ' ');
this.updateLine();
} else if (n == 2) {
this.fill(this.cursorLine, 0, this.cols, ' ');
// this.lineData[this.cursorLine] = [] // " ".times(this.cols);
this.fill(this.cursorY, 0, this.cols, ' ');
this.updateLine();
}
},
@ -264,7 +257,7 @@ SP.Terminal.prototype = {
reserveCharacters: function(n) {
var line = this.getLine();
this.lineData[this.cursorLine] = line.slice(0, this.cursorCol).concat(" ".times(n).split(''), line.slice(this.cursorCol, this.cols - n));
this.lineData[this.cursorY] = line.slice(0, this.cursorX).concat(" ".times(n).split(''), line.slice(this.cursorX, this.cols - n));
this.updateLine();
},

Loading…
Cancel
Save