Add CharData and LineData

This commit is contained in:
Daniel Imms
2017-08-05 21:11:16 -07:00
parent 2878d978c4
commit ae3169e6ae
8 changed files with 35 additions and 27 deletions
+5 -4
View File
@@ -4,6 +4,7 @@
import { ITerminal, IBuffer } from './Interfaces';
import { CircularList } from './utils/CircularList';
import { LineData, CharData } from './Types';
/**
* This class represents a terminal buffer (an internal state of the terminal), where the
@@ -13,7 +14,7 @@ import { CircularList } from './utils/CircularList';
* - scroll position
*/
export class Buffer implements IBuffer {
private _lines: CircularList<[number, string, number][]>;
private _lines: CircularList<LineData>;
public ydisp: number;
public ybase: number;
@@ -39,7 +40,7 @@ export class Buffer implements IBuffer {
this.clear();
}
public get lines(): CircularList<[number, string, number][]> {
public get lines(): CircularList<LineData> {
return this._lines;
}
@@ -60,7 +61,7 @@ export class Buffer implements IBuffer {
this.scrollBottom = 0;
this.scrollTop = 0;
this.tabs = {};
this._lines = new CircularList<[number, string, number][]>(this._terminal.options.scrollback);
this._lines = new CircularList<LineData>(this._terminal.options.scrollback);
this.scrollBottom = this._terminal.rows - 1;
}
@@ -72,7 +73,7 @@ export class Buffer implements IBuffer {
// Deal with columns increasing (we don't do anything when columns reduce)
if (this._terminal.cols < newCols) {
const ch: [number, string, number] = [this._terminal.defAttr, ' ', 1]; // does xterm use the default attr?
const ch: CharData = [this._terminal.defAttr, ' ', 1]; // does xterm use the default attr?
for (let i = 0; i < this._lines.length; i++) {
if (this._lines.get(i) === undefined) {
this._lines.set(i, this._terminal.blankLine());
+4 -3
View File
@@ -5,6 +5,7 @@
import { IInputHandler, ITerminal, IInputHandlingTerminal } from './Interfaces';
import { C0 } from './EscapeSequences';
import { DEFAULT_CHARSET } from './Charsets';
import { CharData } from './Types';
/**
* The terminal's standard implementation of IInputHandler, this handles all
@@ -194,7 +195,7 @@ export class InputHandler implements IInputHandler {
const row = this._terminal.buffer.y + this._terminal.buffer.ybase;
let j = this._terminal.buffer.x;
const ch: [number, string, number] = [this._terminal.eraseAttr(), ' ', 1]; // xterm
const ch: CharData = [this._terminal.eraseAttr(), ' ', 1]; // xterm
while (param-- && j < this._terminal.cols) {
this._terminal.buffer.lines.get(row).splice(j++, 0, ch);
@@ -510,7 +511,7 @@ export class InputHandler implements IInputHandler {
}
const row = this._terminal.buffer.y + this._terminal.buffer.ybase;
const ch: [number, string, number] = [this._terminal.eraseAttr(), ' ', 1]; // xterm
const ch: CharData = [this._terminal.eraseAttr(), ' ', 1]; // xterm
while (param--) {
this._terminal.buffer.lines.get(row).splice(this._terminal.buffer.x, 1);
@@ -558,7 +559,7 @@ export class InputHandler implements IInputHandler {
const row = this._terminal.buffer.y + this._terminal.buffer.ybase;
let j = this._terminal.buffer.x;
const ch: [number, string, number] = [this._terminal.eraseAttr(), ' ', 1]; // xterm
const ch: CharData = [this._terminal.eraseAttr(), ' ', 1]; // xterm
while (param-- && j < this._terminal.cols) {
this._terminal.buffer.lines.get(row)[j++] = ch;
+5 -5
View File
@@ -3,7 +3,7 @@
*/
import { ILinkMatcherOptions } from './Interfaces';
import { LinkMatcherHandler, LinkMatcherValidationCallback, Charset } from './Types';
import { LinkMatcherHandler, LinkMatcherValidationCallback, Charset, LineData } from './Types';
export interface IBrowser {
isNode: boolean;
@@ -46,7 +46,7 @@ export interface ITerminal extends IEventEmitter {
log(text: string): void;
reset(): void;
showCursor(): void;
blankLine(cur?: boolean, isWrapped?: boolean): [number, string, number];
blankLine(cur?: boolean, isWrapped?: boolean): LineData;
}
/**
@@ -97,7 +97,7 @@ export interface IInputHandlingTerminal extends IEventEmitter {
eraseRight(x: number, y: number): void;
eraseLine(y: number): void;
eraseLeft(x: number, y: number): void;
blankLine(cur?: boolean, isWrapped?: boolean): [number, string, number][];
blankLine(cur?: boolean, isWrapped?: boolean): LineData;
prevStop(x?: number): number;
is(term: string): boolean;
send(data: string): void;
@@ -134,7 +134,7 @@ export interface ITerminalOptions {
}
export interface IBuffer {
lines: ICircularList<[number, string, number][]>;
lines: ICircularList<LineData>;
ydisp: number;
ybase: number;
y: number;
@@ -166,7 +166,7 @@ export interface ISelectionManager {
disable(): void;
enable(): void;
setBuffer(buffer: ICircularList<[number, string, number][]>): void;
setBuffer(buffer: ICircularList<LineData>): void;
setSelection(row: number, col: number, length: number): void;
}
+5 -4
View File
@@ -10,11 +10,12 @@ import { SelectionManager } from './SelectionManager';
import { SelectionModel } from './SelectionModel';
import { BufferSet } from './BufferSet';
import { MockTerminal } from './utils/TestUtils';
import { LineData } from './Types';
class TestSelectionManager extends SelectionManager {
constructor(
terminal: ITerminal,
buffer: ICircularList<[number, string, number][]>,
buffer: ICircularList<LineData>,
rowContainer: HTMLElement,
charMeasure: CharMeasure
) {
@@ -38,7 +39,7 @@ describe('SelectionManager', () => {
let document: Document;
let terminal: ITerminal;
let bufferLines: ICircularList<[number, string, number][]>;
let bufferLines: ICircularList<LineData>;
let rowContainer: HTMLElement;
let selectionManager: TestSelectionManager;
@@ -57,8 +58,8 @@ describe('SelectionManager', () => {
selectionManager = new TestSelectionManager(terminal, bufferLines, rowContainer, null);
});
function stringToRow(text: string): [number, string, number][] {
let result: [number, string, number][] = [];
function stringToRow(text: string): LineData {
let result: LineData = [];
for (let i = 0; i < text.length; i++) {
result.push([0, text.charAt(i), 1]);
}
+3 -2
View File
@@ -10,6 +10,7 @@ import { EventEmitter } from './EventEmitter';
import { ITerminal, ICircularList, ISelectionManager } from './Interfaces';
import { SelectionModel } from './SelectionModel';
import { translateBufferLineToString } from './utils/BufferLine';
import { LineData } from './Types';
/**
* The number of pixels the mouse needs to be above or below the viewport in
@@ -101,7 +102,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
constructor(
private _terminal: ITerminal,
private _buffer: ICircularList<[number, string, number][]>,
private _buffer: ICircularList<LineData>,
private _rowContainer: HTMLElement,
private _charMeasure: CharMeasure
) {
@@ -150,7 +151,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
* switched in or out.
* @param buffer The active buffer.
*/
public setBuffer(buffer: ICircularList<[number, string, number][]>): void {
public setBuffer(buffer: ICircularList<LineData>): void {
this._buffer = buffer;
this.clearSelection();
}
+7 -7
View File
@@ -29,7 +29,7 @@ import * as Mouse from './utils/Mouse';
import { CHARSETS } from './Charsets';
import { getRawByteCoords } from './utils/Mouse';
import { translateBufferLineToString } from './utils/BufferLine';
import { CustomKeyEventHandler, Charset, LinkMatcherHandler, LinkMatcherValidationCallback } from './Types';
import { CustomKeyEventHandler, Charset, LinkMatcherHandler, LinkMatcherValidationCallback, CharData, LineData } from './Types';
import { ITerminal, IBrowser, ITerminalOptions, IInputHandlingTerminal, ILinkMatcherOptions } from './Interfaces';
// Declare for RequireJS in loadAddon
@@ -2056,7 +2056,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
if (!line) {
return;
}
const ch: [number, string, number] = [this.eraseAttr(), ' ', 1]; // xterm
const ch: CharData = [this.eraseAttr(), ' ', 1]; // xterm
for (; x < this.cols; x++) {
line[x] = ch;
}
@@ -2073,7 +2073,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
if (!line) {
return;
}
const ch: [number, string, number] = [this.eraseAttr(), ' ', 1]; // xterm
const ch: CharData = [this.eraseAttr(), ' ', 1]; // xterm
x++;
while (x--) {
line[x] = ch;
@@ -2114,11 +2114,11 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
* @param {boolean} cur First bunch of data for each "blank" character.
* @param {boolean} isWrapped Whether the new line is wrapped from the previous line.
*/
public blankLine(cur?: boolean, isWrapped?: boolean): [number, string, number][] {
public blankLine(cur?: boolean, isWrapped?: boolean): LineData {
const attr = cur ? this.eraseAttr() : this.defAttr;
const ch = [attr, ' ', 1]; // width defaults to 1 halfwidth character
const line = [];
const ch: CharData = [attr, ' ', 1]; // width defaults to 1 halfwidth character
const line: LineData = [];
// TODO: It is not ideal that this is a property on an array, a buffer line
// class should be added that will hold this data and other useful functions.
@@ -2137,7 +2137,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
* If cur return the back color xterm feature attribute. Else return defAttr.
* @param cur
*/
public ch(cur?: boolean): [number, string, number] {
public ch(cur?: boolean): CharData {
return cur ? [this.eraseAttr(), ' ', 1] : [this.defAttr, ' ', 1];
}
+3
View File
@@ -15,3 +15,6 @@ export type LinkMatcherValidationCallback = (uri: string, element: HTMLElement,
export type CustomKeyEventHandler = (event: KeyboardEvent) => boolean;
export type Charset = {[key: string]: string};
export type CharData = [number, string, number];
export type LineData = CharData[];
+3 -2
View File
@@ -1,4 +1,5 @@
import { ITerminal, IBuffer, IBufferSet, IBrowser, ICharMeasure, ISelectionManager, ITerminalOptions, IListenerType } from '../Interfaces';
import { LineData } from '../Types';
export class MockTerminal implements ITerminal {
options: ITerminalOptions = {};
@@ -47,8 +48,8 @@ export class MockTerminal implements ITerminal {
showCursor(): void {
throw new Error('Method not implemented.');
}
blankLine(cur?: boolean, isWrapped?: boolean): [number, string, number][] {
const line: [number, string, number][] = [];
blankLine(cur?: boolean, isWrapped?: boolean): LineData {
const line: LineData = [];
for (let i = 0; i < this.cols; i++) {
line.push([0, ' ', 1]);
}