mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-24 03:30:40 +02:00
* Yet more work on inserting and word wrapping as we go. Lots of bugs but getting there
This commit is contained in:
parent
832442288e
commit
d16a13707f
1 changed files with 45 additions and 31 deletions
|
@ -127,9 +127,31 @@ function MultiLineEditTextView2(options) {
|
||||||
return i + 1;
|
return i + 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.redrawRows = function(startRow, endRow) {
|
||||||
|
self.client.term.write(self.getSGR());
|
||||||
|
self.client.term.write(ansi.hideCursor());
|
||||||
|
|
||||||
|
var startIndex = self.getTextLinesIndex(startRow);
|
||||||
|
var endIndex = Math.min(self.getTextLinesIndex(endRow), self.textLines.length);
|
||||||
|
console.log(self.position)
|
||||||
|
var absPos = self.getAbsolutePosition(startRow, 0);
|
||||||
|
console.log(absPos)
|
||||||
|
|
||||||
|
for(var i = startIndex; i < endIndex; ++i) {
|
||||||
|
self.client.term.write(ansi.goto(absPos.row++, absPos.col));
|
||||||
|
self.client.term.write(self.getRenderText(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
self.client.term.write(ansi.showCursor());
|
||||||
|
};
|
||||||
|
|
||||||
this.redrawVisibleArea = function() {
|
this.redrawVisibleArea = function() {
|
||||||
assert(self.topVisibleIndex <= self.textLines.length);
|
assert(self.topVisibleIndex <= self.textLines.length);
|
||||||
|
|
||||||
|
self.redrawRows(0, self.dimens.height);
|
||||||
|
//Math.min(self.topVisibleIndex + self.dimens.height, self.textLines.length));
|
||||||
|
/*
|
||||||
|
|
||||||
self.client.term.write(self.getSGR());
|
self.client.term.write(self.getSGR());
|
||||||
self.client.term.write(ansi.hideCursor());
|
self.client.term.write(ansi.hideCursor());
|
||||||
|
|
||||||
|
@ -141,6 +163,7 @@ function MultiLineEditTextView2(options) {
|
||||||
++row;
|
++row;
|
||||||
}
|
}
|
||||||
self.client.term.write(ansi.showCursor());
|
self.client.term.write(ansi.showCursor());
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getVisibleText = function(index) {
|
this.getVisibleText = function(index) {
|
||||||
|
@ -337,7 +360,10 @@ function MultiLineEditTextView2(options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getAbsolutePosition = function(row, col) {
|
this.getAbsolutePosition = function(row, col) {
|
||||||
return { row : self.position.row + self.cursorPos.row, col : self.position.col + self.cursorPos.col };
|
return {
|
||||||
|
row : self.position.row + row,
|
||||||
|
col : self.position.col + col,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
this.moveClientCusorToCursorPos = function() {
|
this.moveClientCusorToCursorPos = function() {
|
||||||
|
@ -367,44 +393,26 @@ function MultiLineEditTextView2(options) {
|
||||||
|
|
||||||
if(self.getText(index).length > self.dimens.width) {
|
if(self.getText(index).length > self.dimens.width) {
|
||||||
//
|
//
|
||||||
// We'll need to word wrap and ajust text below up
|
// Past available space -- word wrap from current point
|
||||||
// the next eol. Then, redraw from this point down
|
// to the next EOL. Update textLines with the newly
|
||||||
//
|
// formatted array.
|
||||||
// 1) Word wrap current line -> next actual EOL into a
|
|
||||||
// temp array. For this we'll need the output version
|
|
||||||
// of the buffer.
|
|
||||||
//
|
//
|
||||||
var nextEolIndex = self.getNextEndOfLineIndex(self.getTextLinesIndex());
|
var nextEolIndex = self.getNextEndOfLineIndex(self.getTextLinesIndex());
|
||||||
var newLines = self.wordWrapSingleLine(self.getOutputText(index, nextEolIndex));
|
var newLines = self.wordWrapSingleLine(self.getOutputText(index, nextEolIndex));
|
||||||
|
|
||||||
//
|
for(var i = 0; i < newLines.length; ++i) {
|
||||||
// Replace index -> nextEolIndex with our newly rendered line objects
|
newLines[i] = { text : newLines[i] };
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// Replace existing entries in textLines up to nextEolIndex, then
|
|
||||||
// insert any additional required lines
|
|
||||||
//
|
|
||||||
var i = 0;
|
|
||||||
var j;
|
|
||||||
for(j = index; j < nextEolIndex; ++j) {
|
|
||||||
self.textLines[j].text = newLines[i++];
|
|
||||||
}
|
}
|
||||||
|
newLines[newLines.length - 1].eof = true;
|
||||||
|
|
||||||
// :TODO: this part isn't working yet:
|
Array.prototype.splice.apply(self.textLines, [index, nextEolIndex - index].concat(newLines));
|
||||||
while(i < newLines.length) {
|
|
||||||
self.textLines.splice(j, 0, { text : newLines[i] } );
|
|
||||||
if(newLines.length == i) {
|
|
||||||
self.textLines[j].eof = true;
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
++j;
|
|
||||||
}
|
|
||||||
|
|
||||||
//console.log(newLines)
|
var absPos = self.getAbsolutePosition(self.cursorPos.row, self.cursorPos.col);
|
||||||
console.log(self.textLines)
|
self.redrawRows(self.cursorPos.row, self.cursorPos.row + self.getRemainingLinesBelowRow());
|
||||||
|
self.client.term.write(ansi.goto(absPos.row, absPos.col));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// We must only redraw from col -> end of current visible line
|
// We must only redraw from col -> end of current visible line
|
||||||
//
|
//
|
||||||
|
@ -416,6 +424,12 @@ function MultiLineEditTextView2(options) {
|
||||||
ansi.showCursor()
|
ansi.showCursor()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(self.cursorPos.col > self.dimens.width) {
|
||||||
|
self.cursorPos.col = 0;
|
||||||
|
self.cursorPos.row++;
|
||||||
|
self.moveClientCusorToCursorPos();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue