mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Get rows/cols in input hander from buffer service
This commit is contained in:
+24
-26
@@ -26,8 +26,6 @@ function getCursor(term: TestTerminal): number[] {
|
||||
describe('InputHandler', () => {
|
||||
describe('save and restore cursor', () => {
|
||||
const terminal = new MockInputHandlingTerminal();
|
||||
terminal.cols = 80;
|
||||
terminal.rows = 30;
|
||||
terminal.curAttrData.fg = 3;
|
||||
const bufferService = new MockBufferService(80, 30);
|
||||
bufferService.buffer.x = 1;
|
||||
@@ -117,37 +115,37 @@ describe('InputHandler', () => {
|
||||
const inputHandler = new InputHandler(term, bufferService, new MockCoreService());
|
||||
|
||||
// insert some data in first and second line
|
||||
inputHandler.parse(Array(term.cols - 9).join('a'));
|
||||
inputHandler.parse(Array(bufferService.cols - 9).join('a'));
|
||||
inputHandler.parse('1234567890');
|
||||
inputHandler.parse(Array(term.cols - 9).join('a'));
|
||||
inputHandler.parse(Array(bufferService.cols - 9).join('a'));
|
||||
inputHandler.parse('1234567890');
|
||||
const line1: IBufferLine = bufferService.buffer.lines.get(0);
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + '1234567890');
|
||||
expect(line1.translateToString(false)).equals(Array(bufferService.cols - 9).join('a') + '1234567890');
|
||||
|
||||
// insert one char from params = [0]
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.insertChars(Params.fromArray([0]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + ' 123456789');
|
||||
expect(line1.translateToString(false)).equals(Array(bufferService.cols - 9).join('a') + ' 123456789');
|
||||
|
||||
// insert one char from params = [1]
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.insertChars(Params.fromArray([1]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + ' 12345678');
|
||||
expect(line1.translateToString(false)).equals(Array(bufferService.cols - 9).join('a') + ' 12345678');
|
||||
|
||||
// insert two chars from params = [2]
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.insertChars(Params.fromArray([2]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + ' 123456');
|
||||
expect(line1.translateToString(false)).equals(Array(bufferService.cols - 9).join('a') + ' 123456');
|
||||
|
||||
// insert 10 chars from params = [10]
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.insertChars(Params.fromArray([10]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + ' ');
|
||||
expect(line1.translateToString(true)).equals(Array(term.cols - 9).join('a'));
|
||||
expect(line1.translateToString(false)).equals(Array(bufferService.cols - 9).join('a') + ' ');
|
||||
expect(line1.translateToString(true)).equals(Array(bufferService.cols - 9).join('a'));
|
||||
});
|
||||
it('deleteChars', function(): void {
|
||||
const term = new Terminal();
|
||||
@@ -155,40 +153,40 @@ describe('InputHandler', () => {
|
||||
const inputHandler = new InputHandler(term, bufferService, new MockCoreService());
|
||||
|
||||
// insert some data in first and second line
|
||||
inputHandler.parse(Array(term.cols - 9).join('a'));
|
||||
inputHandler.parse(Array(bufferService.cols - 9).join('a'));
|
||||
inputHandler.parse('1234567890');
|
||||
inputHandler.parse(Array(term.cols - 9).join('a'));
|
||||
inputHandler.parse(Array(bufferService.cols - 9).join('a'));
|
||||
inputHandler.parse('1234567890');
|
||||
const line1: IBufferLine = bufferService.buffer.lines.get(0);
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + '1234567890');
|
||||
expect(line1.translateToString(false)).equals(Array(bufferService.cols - 9).join('a') + '1234567890');
|
||||
|
||||
// delete one char from params = [0]
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.deleteChars(Params.fromArray([0]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + '234567890 ');
|
||||
expect(line1.translateToString(true)).equals(Array(term.cols - 9).join('a') + '234567890');
|
||||
expect(line1.translateToString(false)).equals(Array(bufferService.cols - 9).join('a') + '234567890 ');
|
||||
expect(line1.translateToString(true)).equals(Array(bufferService.cols - 9).join('a') + '234567890');
|
||||
|
||||
// insert one char from params = [1]
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.deleteChars(Params.fromArray([1]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + '34567890 ');
|
||||
expect(line1.translateToString(true)).equals(Array(term.cols - 9).join('a') + '34567890');
|
||||
expect(line1.translateToString(false)).equals(Array(bufferService.cols - 9).join('a') + '34567890 ');
|
||||
expect(line1.translateToString(true)).equals(Array(bufferService.cols - 9).join('a') + '34567890');
|
||||
|
||||
// insert two chars from params = [2]
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.deleteChars(Params.fromArray([2]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + '567890 ');
|
||||
expect(line1.translateToString(true)).equals(Array(term.cols - 9).join('a') + '567890');
|
||||
expect(line1.translateToString(false)).equals(Array(bufferService.cols - 9).join('a') + '567890 ');
|
||||
expect(line1.translateToString(true)).equals(Array(bufferService.cols - 9).join('a') + '567890');
|
||||
|
||||
// insert 10 chars from params = [10]
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.deleteChars(Params.fromArray([10]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + ' ');
|
||||
expect(line1.translateToString(true)).equals(Array(term.cols - 9).join('a'));
|
||||
expect(line1.translateToString(false)).equals(Array(bufferService.cols - 9).join('a') + ' ');
|
||||
expect(line1.translateToString(true)).equals(Array(bufferService.cols - 9).join('a'));
|
||||
});
|
||||
it('eraseInLine', function(): void {
|
||||
const term = new Terminal();
|
||||
@@ -196,9 +194,9 @@ describe('InputHandler', () => {
|
||||
const inputHandler = new InputHandler(term, bufferService, new MockCoreService());
|
||||
|
||||
// fill 6 lines to test 3 different states
|
||||
inputHandler.parse(Array(term.cols + 1).join('a'));
|
||||
inputHandler.parse(Array(term.cols + 1).join('a'));
|
||||
inputHandler.parse(Array(term.cols + 1).join('a'));
|
||||
inputHandler.parse(Array(bufferService.cols + 1).join('a'));
|
||||
inputHandler.parse(Array(bufferService.cols + 1).join('a'));
|
||||
inputHandler.parse(Array(bufferService.cols + 1).join('a'));
|
||||
|
||||
// params[0] - right erase
|
||||
bufferService.buffer.y = 0;
|
||||
@@ -216,7 +214,7 @@ describe('InputHandler', () => {
|
||||
bufferService.buffer.y = 2;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.eraseInLine(Params.fromArray([2]));
|
||||
expect(bufferService.buffer.lines.get(2).translateToString(false)).equals(Array(term.cols + 1).join(' '));
|
||||
expect(bufferService.buffer.lines.get(2).translateToString(false)).equals(Array(bufferService.cols + 1).join(' '));
|
||||
|
||||
});
|
||||
it('eraseInDisplay', function(): void {
|
||||
@@ -225,7 +223,7 @@ describe('InputHandler', () => {
|
||||
const inputHandler = new InputHandler(term, bufferService, new MockCoreService());
|
||||
|
||||
// fill display with a's
|
||||
for (let i = 0; i < term.rows; ++i) inputHandler.parse(Array(bufferService.cols + 1).join('a'));
|
||||
for (let i = 0; i < bufferService.rows; ++i) inputHandler.parse(Array(bufferService.cols + 1).join('a'));
|
||||
|
||||
// params [0] - right and below erase
|
||||
bufferService.buffer.y = 5;
|
||||
|
||||
+29
-29
@@ -368,7 +368,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
const buffer = this._bufferService.buffer;
|
||||
const charset = this._terminal.charset;
|
||||
const screenReaderMode = this._terminal.options.screenReaderMode;
|
||||
const cols = this._terminal.cols;
|
||||
const cols = this._bufferService.cols;
|
||||
const wraparoundMode = this._terminal.wraparoundMode;
|
||||
const insertMode = this._terminal.insertMode;
|
||||
const curAttr = this._terminal.curAttrData;
|
||||
@@ -525,7 +525,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
this._terminal.scroll();
|
||||
}
|
||||
// If the end of the line is hit, prevent this action from wrapping around to the next line.
|
||||
if (buffer.x >= this._terminal.cols) {
|
||||
if (buffer.x >= this._bufferService.cols) {
|
||||
buffer.x--;
|
||||
}
|
||||
|
||||
@@ -556,7 +556,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Horizontal Tab (HT) (Ctrl-I).
|
||||
*/
|
||||
public tab(): void {
|
||||
if (this._bufferService.buffer.x >= this._terminal.cols) {
|
||||
if (this._bufferService.buffer.x >= this._bufferService.cols) {
|
||||
return;
|
||||
}
|
||||
const originalX = this._bufferService.buffer.x;
|
||||
@@ -588,10 +588,10 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Restrict cursor to viewport size / scroll margin (origin mode).
|
||||
*/
|
||||
private _restrictCursor(): void {
|
||||
this._bufferService.buffer.x = Math.min(this._terminal.cols - 1, Math.max(0, this._bufferService.buffer.x));
|
||||
this._bufferService.buffer.x = Math.min(this._bufferService.cols - 1, Math.max(0, this._bufferService.buffer.x));
|
||||
this._bufferService.buffer.y = this._terminal.originMode
|
||||
? Math.min(this._bufferService.buffer.scrollBottom, Math.max(this._bufferService.buffer.scrollTop, this._bufferService.buffer.y))
|
||||
: Math.min(this._terminal.rows - 1, Math.max(0, this._bufferService.buffer.y));
|
||||
: Math.min(this._bufferService.rows - 1, Math.max(0, this._bufferService.buffer.y));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -757,7 +757,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
|
||||
*/
|
||||
public cursorForwardTab(params: IParams): void {
|
||||
if (this._bufferService.buffer.x >= this._terminal.cols) {
|
||||
if (this._bufferService.buffer.x >= this._bufferService.cols) {
|
||||
return;
|
||||
}
|
||||
let param = params.params[0] || 1;
|
||||
@@ -770,7 +770,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
|
||||
*/
|
||||
public cursorBackwardTab(params: IParams): void {
|
||||
if (this._bufferService.buffer.x >= this._terminal.cols) {
|
||||
if (this._bufferService.buffer.x >= this._bufferService.cols) {
|
||||
return;
|
||||
}
|
||||
let param = params.params[0] || 1;
|
||||
@@ -833,8 +833,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
case 0:
|
||||
j = this._bufferService.buffer.y;
|
||||
this._terminal.updateRange(j);
|
||||
this._eraseInBufferLine(j++, this._bufferService.buffer.x, this._terminal.cols, this._bufferService.buffer.x === 0);
|
||||
for (; j < this._terminal.rows; j++) {
|
||||
this._eraseInBufferLine(j++, this._bufferService.buffer.x, this._bufferService.cols, this._bufferService.buffer.x === 0);
|
||||
for (; j < this._bufferService.rows; j++) {
|
||||
this._resetBufferLine(j);
|
||||
}
|
||||
this._terminal.updateRange(j);
|
||||
@@ -844,7 +844,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
this._terminal.updateRange(j);
|
||||
// Deleted front part of line and everything before. This line will no longer be wrapped.
|
||||
this._eraseInBufferLine(j, 0, this._bufferService.buffer.x + 1, true);
|
||||
if (this._bufferService.buffer.x + 1 >= this._terminal.cols) {
|
||||
if (this._bufferService.buffer.x + 1 >= this._bufferService.cols) {
|
||||
// Deleted entire previous line. This next line can no longer be wrapped.
|
||||
this._bufferService.buffer.lines.get(j + 1).isWrapped = false;
|
||||
}
|
||||
@@ -854,7 +854,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
this._terminal.updateRange(0);
|
||||
break;
|
||||
case 2:
|
||||
j = this._terminal.rows;
|
||||
j = this._bufferService.rows;
|
||||
this._terminal.updateRange(j - 1);
|
||||
while (j--) {
|
||||
this._resetBufferLine(j);
|
||||
@@ -863,7 +863,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
break;
|
||||
case 3:
|
||||
// Clear scrollback (everything not in viewport)
|
||||
const scrollBackSize = this._bufferService.buffer.lines.length - this._terminal.rows;
|
||||
const scrollBackSize = this._bufferService.buffer.lines.length - this._bufferService.rows;
|
||||
if (scrollBackSize > 0) {
|
||||
this._bufferService.buffer.lines.trimStart(scrollBackSize);
|
||||
this._bufferService.buffer.ybase = Math.max(this._bufferService.buffer.ybase - scrollBackSize, 0);
|
||||
@@ -890,13 +890,13 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
this._restrictCursor();
|
||||
switch (params.params[0]) {
|
||||
case 0:
|
||||
this._eraseInBufferLine(this._bufferService.buffer.y, this._bufferService.buffer.x, this._terminal.cols);
|
||||
this._eraseInBufferLine(this._bufferService.buffer.y, this._bufferService.buffer.x, this._bufferService.cols);
|
||||
break;
|
||||
case 1:
|
||||
this._eraseInBufferLine(this._bufferService.buffer.y, 0, this._bufferService.buffer.x + 1);
|
||||
break;
|
||||
case 2:
|
||||
this._eraseInBufferLine(this._bufferService.buffer.y, 0, this._terminal.cols);
|
||||
this._eraseInBufferLine(this._bufferService.buffer.y, 0, this._bufferService.cols);
|
||||
break;
|
||||
}
|
||||
this._terminal.updateRange(this._bufferService.buffer.y);
|
||||
@@ -919,8 +919,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
|
||||
const row: number = buffer.y + buffer.ybase;
|
||||
|
||||
const scrollBottomRowsOffset = this._terminal.rows - 1 - buffer.scrollBottom;
|
||||
const scrollBottomAbsolute = this._terminal.rows - 1 + buffer.ybase - scrollBottomRowsOffset + 1;
|
||||
const scrollBottomRowsOffset = this._bufferService.rows - 1 - buffer.scrollBottom;
|
||||
const scrollBottomAbsolute = this._bufferService.rows - 1 + buffer.ybase - scrollBottomRowsOffset + 1;
|
||||
while (param--) {
|
||||
// test: echo -e '\e[44m\e[1L\e[0m'
|
||||
// blankLine(true) - xterm/linux behavior
|
||||
@@ -952,8 +952,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
const row: number = buffer.y + buffer.ybase;
|
||||
|
||||
let j: number;
|
||||
j = this._terminal.rows - 1 - buffer.scrollBottom;
|
||||
j = this._terminal.rows - 1 + buffer.ybase - j;
|
||||
j = this._bufferService.rows - 1 - buffer.scrollBottom;
|
||||
j = this._bufferService.rows - 1 + buffer.ybase - j;
|
||||
while (param--) {
|
||||
// test: echo -e '\e[44m\e[1M\e[0m'
|
||||
// blankLine(true) - xterm/linux behavior
|
||||
@@ -1273,8 +1273,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
break;
|
||||
case 3: // 132 col mode
|
||||
// TODO: move DECCOLM into compat addon
|
||||
this._terminal.savedCols = this._terminal.cols;
|
||||
this._terminal.resize(132, this._terminal.rows);
|
||||
this._terminal.savedCols = this._bufferService.cols;
|
||||
this._terminal.resize(132, this._bufferService.rows);
|
||||
this._terminal.reset();
|
||||
break;
|
||||
case 6:
|
||||
@@ -1354,7 +1354,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
case 47: // alt screen buffer
|
||||
case 1047: // alt screen buffer
|
||||
this._bufferService.buffers.activateAltBuffer(this._terminal.eraseAttrData());
|
||||
this._terminal.refresh(0, this._terminal.rows - 1);
|
||||
this._terminal.refresh(0, this._bufferService.rows - 1);
|
||||
if (this._terminal.viewport) {
|
||||
this._terminal.viewport.syncScrollArea();
|
||||
}
|
||||
@@ -1474,8 +1474,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
// TODO: move DECCOLM into compat addon
|
||||
// Note: This impl currently does not enforce col 80, instead reverts
|
||||
// to previous terminal width before entering DECCOLM 132
|
||||
if (this._terminal.cols === 132 && this._terminal.savedCols) {
|
||||
this._terminal.resize(this._terminal.savedCols, this._terminal.rows);
|
||||
if (this._bufferService.cols === 132 && this._terminal.savedCols) {
|
||||
this._terminal.resize(this._terminal.savedCols, this._bufferService.rows);
|
||||
}
|
||||
delete this._terminal.savedCols;
|
||||
this._terminal.reset();
|
||||
@@ -1539,7 +1539,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
if (param === 1049) {
|
||||
this.restoreCursor();
|
||||
}
|
||||
this._terminal.refresh(0, this._terminal.rows - 1);
|
||||
this._terminal.refresh(0, this._bufferService.rows - 1);
|
||||
if (this._terminal.viewport) {
|
||||
this._terminal.viewport.syncScrollArea();
|
||||
}
|
||||
@@ -1870,7 +1870,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
}
|
||||
this._coreService.decPrivateModes.applicationCursorKeys = false;
|
||||
this._bufferService.buffer.scrollTop = 0;
|
||||
this._bufferService.buffer.scrollBottom = this._terminal.rows - 1;
|
||||
this._bufferService.buffer.scrollBottom = this._bufferService.rows - 1;
|
||||
this._terminal.curAttrData = DEFAULT_ATTR_DATA.clone();
|
||||
this._bufferService.buffer.x = this._bufferService.buffer.y = 0; // ?
|
||||
this._terminal.charset = null;
|
||||
@@ -1926,8 +1926,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
const top = params.params[0] || 1;
|
||||
let bottom: number;
|
||||
|
||||
if (params.length < 2 || (bottom = params.params[1]) > this._terminal.rows || bottom === 0) {
|
||||
bottom = this._terminal.rows;
|
||||
if (params.length < 2 || (bottom = params.params[1]) > this._bufferService.rows || bottom === 0) {
|
||||
bottom = this._bufferService.rows;
|
||||
}
|
||||
|
||||
if (bottom > top) {
|
||||
@@ -2149,13 +2149,13 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
const buffer = this._bufferService.buffer;
|
||||
|
||||
this._setCursor(0, 0);
|
||||
for (let yOffset = 0; yOffset < this._terminal.rows; ++yOffset) {
|
||||
for (let yOffset = 0; yOffset < this._bufferService.rows; ++yOffset) {
|
||||
const row = buffer.y + buffer.ybase + yOffset;
|
||||
buffer.lines.get(row).fill(cell);
|
||||
buffer.lines.get(row).isWrapped = false;
|
||||
}
|
||||
this._terminal.updateRange(0);
|
||||
this._terminal.updateRange(this._terminal.rows);
|
||||
this._terminal.updateRange(this._bufferService.rows);
|
||||
this._setCursor(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user