move erase methods to InputHandler

This commit is contained in:
Jörg Breitbart
2018-08-30 18:10:18 +02:00
parent a1421b151e
commit 276e65fa0b
4 changed files with 74 additions and 50 deletions
+8 -8
View File
@@ -261,13 +261,13 @@ describe('InputHandler', () => {
function eraseInLine(params: number[]): void { function eraseInLine(params: number[]): void {
switch (params[0]) { switch (params[0]) {
case 0: case 0:
term.eraseRight(term.buffer.x, term.buffer.y); inputHandler.eraseRight(term.buffer.x, term.buffer.y);
break; break;
case 1: case 1:
term.eraseLeft(term.buffer.x, term.buffer.y); inputHandler.eraseLeft(term.buffer.x, term.buffer.y);
break; break;
case 2: case 2:
term.eraseLine(term.buffer.y); inputHandler.eraseLine(term.buffer.y);
break; break;
} }
} }
@@ -321,22 +321,22 @@ describe('InputHandler', () => {
let j; let j;
switch (params[0]) { switch (params[0]) {
case 0: case 0:
termOld.eraseRight(termOld.buffer.x, termOld.buffer.y); inputHandlerOld.eraseRight(termOld.buffer.x, termOld.buffer.y);
j = termOld.buffer.y + 1; j = termOld.buffer.y + 1;
for (; j < termOld.rows; j++) { for (; j < termOld.rows; j++) {
termOld.eraseLine(j); inputHandlerOld.eraseLine(j);
} }
break; break;
case 1: case 1:
termOld.eraseLeft(termOld.buffer.x, termOld.buffer.y); inputHandlerOld.eraseLeft(termOld.buffer.x, termOld.buffer.y);
j = termOld.buffer.y; j = termOld.buffer.y;
while (j--) { while (j--) {
termOld.eraseLine(j); inputHandlerOld.eraseLine(j);
} }
break; break;
case 2: case 2:
j = termOld.rows; j = termOld.rows;
while (j--) termOld.eraseLine(j); while (j--) inputHandlerOld.eraseLine(j);
break; break;
case 3: case 3:
// Clear scrollback (everything not in viewport) // Clear scrollback (everything not in viewport)
+63
View File
@@ -1986,4 +1986,67 @@ export class InputHandler extends Disposable implements IInputHandler {
public setgLevel(level: number): void { public setgLevel(level: number): void {
this._terminal.setgLevel(level); // TODO: save to move from terminal? this._terminal.setgLevel(level); // TODO: save to move from terminal?
} }
/**
* Erase in the identified line everything from "x" to the end of the line (right).
* @param x The column from which to start erasing to the end of the line.
* @param y The line in which to operate.
*/
// FIXME: decide whether to remove from Terminal
public eraseRight(x: number, y: number): void {
const line = this._terminal.buffer.lines.get(this._terminal.buffer.ybase + y);
if (!line) {
return;
}
line.replaceCells(x, this._terminal.cols, [this._terminal.eraseAttr(), NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]);
this._terminal.updateRange(y);
}
/**
* Erase in the identified line everything from "x" to the start of the line (left).
* @param x The column from which to start erasing to the start of the line.
* @param y The line in which to operate.
*/
// FIXME: decide whether to remove from Terminal
public eraseLeft(x: number, y: number): void {
const line = this._terminal.buffer.lines.get(this._terminal.buffer.ybase + y);
if (!line) {
return;
}
line.replaceCells(0, x + 1, [this._terminal.eraseAttr(), NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]);
this._terminal.updateRange(y);
}
/**
* Erase all content in the given line
* @param y The line to erase all of its contents.
*/
// FIXME: decide whether to remove from Terminal
public eraseLine(y: number): void {
this.eraseRight(0, y);
}
} }
-39
View File
@@ -1709,36 +1709,6 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
this._refreshEnd = this.rows - 1; this._refreshEnd = this.rows - 1;
} }
/**
* Erase in the identified line everything from "x" to the end of the line (right).
* @param x The column from which to start erasing to the end of the line.
* @param y The line in which to operate.
*/
// FIXME: decide whether to remove from Terminal
public eraseRight(x: number, y: number): void {
const line = this.buffer.lines.get(this.buffer.ybase + y);
if (!line) {
return;
}
line.replaceCells(x, this.cols, [this.eraseAttr(), NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]);
this.updateRange(y);
}
/**
* Erase in the identified line everything from "x" to the start of the line (left).
* @param x The column from which to start erasing to the start of the line.
* @param y The line in which to operate.
*/
// FIXME: decide whether to remove from Terminal
public eraseLeft(x: number, y: number): void {
const line = this.buffer.lines.get(this.buffer.ybase + y);
if (!line) {
return;
}
line.replaceCells(0, x + 1, [this.eraseAttr(), NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]);
this.updateRange(y);
}
/** /**
* Clear the entire buffer, making the prompt line the new first line. * Clear the entire buffer, making the prompt line the new first line.
*/ */
@@ -1759,15 +1729,6 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
this.emit('scroll', this.buffer.ydisp); this.emit('scroll', this.buffer.ydisp);
} }
/**
* Erase all content in the given line
* @param y The line to erase all of its contents.
*/
// FIXME: decide whether to remove from Terminal
public eraseLine(y: number): void {
this.eraseRight(0, y);
}
/** /**
* If cur return the back color xterm feature attribute. Else return default attribute. * If cur return the back color xterm feature attribute. Else return default attribute.
* @param cur * @param cur
+3 -3
View File
@@ -71,9 +71,6 @@ export interface IInputHandlingTerminal extends IEventEmitter {
scroll(isWrapped?: boolean): void; scroll(isWrapped?: boolean): void;
setgLevel(g: number): void; setgLevel(g: number): void;
eraseAttr(): number; eraseAttr(): number;
eraseRight(x: number, y: number): void;
eraseLine(y: number): void;
eraseLeft(x: number, y: number): void;
is(term: string): boolean; is(term: string): boolean;
setgCharset(g: number, charset: ICharset): void; setgCharset(g: number, charset: ICharset): void;
resize(x: number, y: number): void; resize(x: number, y: number): void;
@@ -115,6 +112,9 @@ export interface ICompositionHelper {
export interface IInputHandler { export interface IInputHandler {
parse(data: string): void; parse(data: string): void;
print(data: string, start: number, end: number): void; print(data: string, start: number, end: number): void;
eraseRight(x: number, y: number): void;
eraseLine(y: number): void;
eraseLeft(x: number, y: number): void;
/** C0 BEL */ bell(): void; /** C0 BEL */ bell(): void;
/** C0 LF */ lineFeed(): void; /** C0 LF */ lineFeed(): void;