Add CSI @, E, F, G

This commit is contained in:
Daniel Imms
2017-01-09 23:06:36 -08:00
parent db81c28bd7
commit 411b80cdc0
4 changed files with 89 additions and 79 deletions
+73 -5
View File
@@ -79,6 +79,26 @@ export class InputHandler implements IInputHandler {
this._terminal.setgLevel(0);
}
/**
* CSI Ps @
* Insert Ps (Blank) Character(s) (default = 1) (ICH).
*/
public insertChars(params: number[]): void {
let param, row, j, ch;
param = params[0];
if (param < 1) param = 1;
row = this._terminal.y + this._terminal.ybase;
j = this._terminal.x;
ch = [this._terminal.eraseAttr(), ' ', 1]; // xterm
while (param-- && j < this._terminal.cols) {
this._terminal.lines.get(row).splice(j++, 0, ch);
this._terminal.lines.get(row).pop();
}
}
/**
* CSI Ps A
* Cursor Up Ps Times (default = 1) (CUU).
@@ -139,11 +159,59 @@ export class InputHandler implements IInputHandler {
}
}
/**
* CSI Ps E
* Cursor Next Line Ps Times (default = 1) (CNL).
* same as CSI Ps B ?
*/
public cursorNextLine(params: number[]): void {
let param = params[0];
if (param < 1) {
param = 1;
}
this._terminal.y += param;
if (this._terminal.y >= this._terminal.rows) {
this._terminal.y = this._terminal.rows - 1;
}
this._terminal.x = 0;
};
/**
* CSI Ps F
* Cursor Preceding Line Ps Times (default = 1) (CNL).
* reuse CSI Ps A ?
*/
public cursorPrecedingLine(params: number[]): void {
let param = params[0];
if (param < 1) {
param = 1;
}
this._terminal.y -= param;
if (this._terminal.y < 0) {
this._terminal.y = 0;
}
this._terminal.x = 0;
};
/**
* CSI Ps G
* Cursor Character Absolute [column] (default = [row,1]) (CHA).
*/
public cursorCharAbsolute(params: number[]): void {
let param = params[0];
if (param < 1) {
param = 1;
}
this._terminal.x = param - 1;
}
/**
* CSI Ps ; Ps H
* Cursor Position [row;column] (default = [1,1]) (CUP).
*/
public cursorPosition(params: number[]) {
public cursorPosition(params: number[]): void {
let row, col;
row = params[0] - 1;
@@ -182,7 +250,7 @@ export class InputHandler implements IInputHandler {
* Ps = 1 -> Selective Erase Above.
* Ps = 2 -> Selective Erase All.
*/
public eraseInDisplay(params: number[]) {
public eraseInDisplay(params: number[]): void {
let j;
switch (params[0]) {
case 0:
@@ -220,7 +288,7 @@ export class InputHandler implements IInputHandler {
* Ps = 1 -> Selective Erase to Left.
* Ps = 2 -> Selective Erase All.
*/
public eraseInLine(params: number[]) {
public eraseInLine(params: number[]): void {
switch (params[0]) {
case 0:
this._terminal.eraseRight(this._terminal.x, this._terminal.y);
@@ -298,7 +366,7 @@ export class InputHandler implements IInputHandler {
* Ps = 4 8 ; 5 ; Ps -> Set background color to the second
* Ps.
*/
public charAttributes(params: number[]) {
public charAttributes(params: number[]): void {
// Optimize a single SGR0.
if (params.length === 1 && params[0] === 0) {
this._terminal.curAttr = this._terminal.defAttr;
@@ -438,7 +506,7 @@ export class InputHandler implements IInputHandler {
* CSI ? 5 3 n Locator available, if compiled-in, or
* CSI ? 5 0 n No Locator, if not.
*/
public deviceStatus(params: number[]) {
public deviceStatus(params: number[]): void {
if (!this._terminal.prefix) {
switch (params[0]) {
case 5:
+12 -8
View File
@@ -44,13 +44,17 @@ export interface IInputHandler {
tab(): void;
shiftOut(): void;
shiftIn(): void;
insertChars(params);
cursorUp(params: number[]): void;
cursorDown(params: number[]);
cursorForward(params: number[]);
cursorBackward(params: number[]);
cursorPosition(params: number[]);
eraseInDisplay(params: number[]);
eraseInLine(params: number[]);
charAttributes(params: number[]);
deviceStatus(params: number[]);
cursorDown(params: number[]): void;
cursorForward(params: number[]): void;
cursorBackward(params: number[]): void;
cursorNextLine(params: number[]): void;
cursorPrecedingLine(params: number[]): void;
cursorCharAbsolute(params: number[]): void;
cursorPosition(params: number[]): void;
eraseInDisplay(params: number[]): void;
eraseInLine(params: number[]): void;
charAttributes(params: number[]): void;
deviceStatus(params: number[]): void;
}
+4 -6
View File
@@ -35,10 +35,14 @@ csiParamStateHandler['\''] = (parser) => parser.setPostfix('\'');
csiParamStateHandler[';'] = (parser) => parser.finalizeParam();
const csiStateHandler: {[key: string]: (handler: IInputHandler, params: number[]) => void} = {};
csiStateHandler['@'] = (handler, params) => handler.insertChars(params);
csiStateHandler['A'] = (handler, params) => handler.cursorUp(params);
csiStateHandler['B'] = (handler, params) => handler.cursorDown(params);
csiStateHandler['C'] = (handler, params) => handler.cursorForward(params);
csiStateHandler['D'] = (handler, params) => handler.cursorBackward(params);
csiStateHandler['E'] = (handler, params) => handler.cursorNextLine(params);
csiStateHandler['F'] = (handler, params) => handler.cursorPrecedingLine(params);
csiStateHandler['G'] = (handler, params) => handler.cursorCharAbsolute(params);
csiStateHandler['H'] = (handler, params) => handler.cursorPosition(params);
csiStateHandler['J'] = (handler, params) => handler.eraseInDisplay(params);
csiStateHandler['K'] = (handler, params) => handler.eraseInLine(params);
@@ -543,12 +547,6 @@ export class Parser {
* Additions
*/
// CSI Ps @
// Insert Ps (Blank) Character(s) (default = 1) (ICH).
case '@':
this._terminal.insertChars(this._terminal.params);
break;
// CSI Ps E
// Cursor Next Line Ps Times (default = 1) (CNL).
case 'E':
-60
View File
@@ -2227,66 +2227,6 @@ Terminal.prototype.tabSet = function() {
* Additions
*/
/**
* CSI Ps @
* Insert Ps (Blank) Character(s) (default = 1) (ICH).
*/
Terminal.prototype.insertChars = function(params) {
var param, row, j, ch;
param = params[0];
if (param < 1) param = 1;
row = this.y + this.ybase;
j = this.x;
ch = [this.eraseAttr(), ' ', 1]; // xterm
while (param-- && j < this.cols) {
this.lines.get(row).splice(j++, 0, ch);
this.lines.get(row).pop();
}
};
/**
* CSI Ps E
* Cursor Next Line Ps Times (default = 1) (CNL).
* same as CSI Ps B ?
*/
Terminal.prototype.cursorNextLine = function(params) {
var param = params[0];
if (param < 1) param = 1;
this.y += param;
if (this.y >= this.rows) {
this.y = this.rows - 1;
}
this.x = 0;
};
/**
* CSI Ps F
* Cursor Preceding Line Ps Times (default = 1) (CNL).
* reuse CSI Ps A ?
*/
Terminal.prototype.cursorPrecedingLine = function(params) {
var param = params[0];
if (param < 1) param = 1;
this.y -= param;
if (this.y < 0) this.y = 0;
this.x = 0;
};
/**
* CSI Ps G
* Cursor Character Absolute [column] (default = [row,1]) (CHA).
*/
Terminal.prototype.cursorCharAbsolute = function(params) {
var param = params[0];
if (param < 1) param = 1;
this.x = param - 1;
};
/**
* CSI Ps L