simplify cursor movements
This commit is contained in:
+30
-39
@@ -598,7 +598,11 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
this._terminal.updateRange(this._terminal.buffer.y);
|
this._terminal.updateRange(this._terminal.buffer.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// restrict cursor changes to addressable cols/rows
|
/**
|
||||||
|
* FIXME:
|
||||||
|
* - create Cursor class living on Buffer
|
||||||
|
* - move these private cursor methods to Cursor class as API
|
||||||
|
*/
|
||||||
private _restrictCursor(): void {
|
private _restrictCursor(): void {
|
||||||
// cols
|
// cols
|
||||||
if (this._terminal.buffer.x < 0) {
|
if (this._terminal.buffer.x < 0) {
|
||||||
@@ -614,6 +618,19 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _setCursor(x: number, y: number): void {
|
||||||
|
this._terminal.buffer.x = x;
|
||||||
|
this._terminal.buffer.y = y;
|
||||||
|
this._restrictCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
private _moveCursor(x: number, y: number): void {
|
||||||
|
// for relative changes we have to make sure we are within 0 .. cols/rows - 1
|
||||||
|
// before calculating the new position
|
||||||
|
this._restrictCursor();
|
||||||
|
this._setCursor(this._terminal.buffer.x + x, this._terminal.buffer.y + y);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CSI Ps A
|
* CSI Ps A
|
||||||
* Cursor Up Ps Times (default = 1) (CUU).
|
* Cursor Up Ps Times (default = 1) (CUU).
|
||||||
@@ -623,9 +640,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
if (param < 1) {
|
if (param < 1) {
|
||||||
param = 1;
|
param = 1;
|
||||||
}
|
}
|
||||||
this._restrictCursor();
|
this._moveCursor(0, -param);
|
||||||
this._terminal.buffer.y -= param;
|
|
||||||
this._restrictCursor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -637,9 +652,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
if (param < 1) {
|
if (param < 1) {
|
||||||
param = 1;
|
param = 1;
|
||||||
}
|
}
|
||||||
this._restrictCursor();
|
this._moveCursor(0, param);
|
||||||
this._terminal.buffer.y += param;
|
|
||||||
this._restrictCursor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -651,9 +664,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
if (param < 1) {
|
if (param < 1) {
|
||||||
param = 1;
|
param = 1;
|
||||||
}
|
}
|
||||||
this._restrictCursor();
|
this._moveCursor(param, 0);
|
||||||
this._terminal.buffer.x += param;
|
|
||||||
this._restrictCursor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -665,9 +676,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
if (param < 1) {
|
if (param < 1) {
|
||||||
param = 1;
|
param = 1;
|
||||||
}
|
}
|
||||||
this._restrictCursor();
|
this._moveCursor(-param, 0);
|
||||||
this._terminal.buffer.x -= param;
|
|
||||||
this._restrictCursor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -680,10 +689,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
if (param < 1) {
|
if (param < 1) {
|
||||||
param = 1;
|
param = 1;
|
||||||
}
|
}
|
||||||
this._restrictCursor();
|
this._moveCursor(0, param);
|
||||||
this._terminal.buffer.y += param;
|
|
||||||
this._terminal.buffer.x = 0;
|
this._terminal.buffer.x = 0;
|
||||||
this._restrictCursor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -697,10 +704,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
if (param < 1) {
|
if (param < 1) {
|
||||||
param = 1;
|
param = 1;
|
||||||
}
|
}
|
||||||
this._restrictCursor();
|
this._moveCursor(0, -param);
|
||||||
this._terminal.buffer.y -= param;
|
|
||||||
this._terminal.buffer.x = 0;
|
this._terminal.buffer.x = 0;
|
||||||
this._restrictCursor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -713,9 +718,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
if (param < 1) {
|
if (param < 1) {
|
||||||
param = 1;
|
param = 1;
|
||||||
}
|
}
|
||||||
this._restrictCursor();
|
this._setCursor(param - 1, this._terminal.buffer.y);
|
||||||
this._terminal.buffer.x = param - 1;
|
|
||||||
this._restrictCursor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -731,11 +734,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
} else {
|
} else {
|
||||||
col = 0;
|
col = 0;
|
||||||
}
|
}
|
||||||
|
this._setCursor(col, row);
|
||||||
this._restrictCursor();
|
|
||||||
this._terminal.buffer.x = col;
|
|
||||||
this._terminal.buffer.y = row;
|
|
||||||
this._restrictCursor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1018,9 +1017,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
if (param < 1) {
|
if (param < 1) {
|
||||||
param = 1;
|
param = 1;
|
||||||
}
|
}
|
||||||
this._restrictCursor();
|
this._setCursor(param - 1, this._terminal.buffer.y);
|
||||||
this._terminal.buffer.x = param - 1;
|
|
||||||
this._restrictCursor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1033,9 +1030,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
if (param < 1) {
|
if (param < 1) {
|
||||||
param = 1;
|
param = 1;
|
||||||
}
|
}
|
||||||
this._restrictCursor();
|
this._moveCursor(param, 0);
|
||||||
this._terminal.buffer.x += param;
|
|
||||||
this._restrictCursor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1148,9 +1143,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
if (param < 1) {
|
if (param < 1) {
|
||||||
param = 1;
|
param = 1;
|
||||||
}
|
}
|
||||||
this._restrictCursor();
|
this._setCursor(this._terminal.buffer.x, param - 1);
|
||||||
this._terminal.buffer.y = param - 1;
|
|
||||||
this._restrictCursor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1163,9 +1156,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
if (param < 1) {
|
if (param < 1) {
|
||||||
param = 1;
|
param = 1;
|
||||||
}
|
}
|
||||||
this._restrictCursor();
|
this._moveCursor(0, param);
|
||||||
this._terminal.buffer.y += param;
|
|
||||||
this._restrictCursor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user