mirror of
https://git.proxmox.com/git/mirror_xterm.js
synced 2025-10-28 20:20:19 +00:00
Add IBuffer, IBufferSet and fix CircularList type
This commit is contained in:
parent
cb5a452c90
commit
59f75555bc
@ -13,7 +13,7 @@ import { CircularList } from './utils/CircularList';
|
|||||||
* - scroll position
|
* - scroll position
|
||||||
*/
|
*/
|
||||||
export class Buffer {
|
export class Buffer {
|
||||||
public lines: CircularList<[string, number, string]>;
|
public lines: CircularList<[number, string, number][]>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Buffer.
|
* Create a new Buffer.
|
||||||
@ -33,7 +33,7 @@ export class Buffer {
|
|||||||
public scrollTop: number = 0,
|
public scrollTop: number = 0,
|
||||||
public tabs: any = {},
|
public tabs: any = {},
|
||||||
) {
|
) {
|
||||||
this.lines = new CircularList<[string, number, string]>(this.terminal.scrollback);
|
this.lines = new CircularList<[number, string, number][]>(this.terminal.scrollback);
|
||||||
this.scrollBottom = this.terminal.rows - 1;
|
this.scrollBottom = this.terminal.rows - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ITerminal } from './Interfaces';
|
import { ITerminal, IBufferSet } from './Interfaces';
|
||||||
import { Buffer } from './Buffer';
|
import { Buffer } from './Buffer';
|
||||||
import { EventEmitter } from './EventEmitter';
|
import { EventEmitter } from './EventEmitter';
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ import { EventEmitter } from './EventEmitter';
|
|||||||
* The BufferSet represents the set of two buffers used by xterm terminals (normal and alt) and
|
* The BufferSet represents the set of two buffers used by xterm terminals (normal and alt) and
|
||||||
* provides also utilities for working with them.
|
* provides also utilities for working with them.
|
||||||
*/
|
*/
|
||||||
export class BufferSet extends EventEmitter {
|
export class BufferSet extends EventEmitter implements IBufferSet {
|
||||||
private _normal: Buffer;
|
private _normal: Buffer;
|
||||||
private _alt: Buffer;
|
private _alt: Buffer;
|
||||||
private _activeBuffer: Buffer;
|
private _activeBuffer: Buffer;
|
||||||
|
|||||||
@ -2,12 +2,14 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { IEventEmitter } from './Interfaces';
|
||||||
|
|
||||||
interface ListenerType {
|
interface ListenerType {
|
||||||
(): void;
|
(): void;
|
||||||
listener?: () => void;
|
listener?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class EventEmitter {
|
export class EventEmitter implements IEventEmitter {
|
||||||
private _events: {[type: string]: ListenerType[]};
|
private _events: {[type: string]: ListenerType[]};
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
@ -33,9 +33,8 @@ export interface ITerminal {
|
|||||||
cursorState: number;
|
cursorState: number;
|
||||||
defAttr: number;
|
defAttr: number;
|
||||||
scrollback: number;
|
scrollback: number;
|
||||||
buffers: any; // This should be a `BufferSet` class, but it would result in circular dependency
|
buffers: IBufferSet;
|
||||||
buffer: any; // This should be a `Buffer` class, but it would result in circular dependency
|
buffer: IBuffer;
|
||||||
viewport: any; // This should be a `Viewport` class, but it would result in circular dependency
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emit the 'data' event and populate the given data.
|
* Emit the 'data' event and populate the given data.
|
||||||
@ -51,6 +50,24 @@ export interface ITerminal {
|
|||||||
showCursor(): void;
|
showCursor(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IBuffer {
|
||||||
|
lines: ICircularList<[number, string, number][]>;
|
||||||
|
ydisp: number;
|
||||||
|
ybase: number;
|
||||||
|
y: number;
|
||||||
|
x: number;
|
||||||
|
tabs: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IBufferSet {
|
||||||
|
alt: IBuffer;
|
||||||
|
normal: IBuffer;
|
||||||
|
active: IBuffer;
|
||||||
|
|
||||||
|
activateNormalBuffer(): void;
|
||||||
|
activateAltBuffer(): void;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ISelectionManager {
|
export interface ISelectionManager {
|
||||||
selectionText: string;
|
selectionText: string;
|
||||||
selectionStart: [number, number];
|
selectionStart: [number, number];
|
||||||
@ -72,7 +89,7 @@ export interface ILinkifier {
|
|||||||
deregisterLinkMatcher(matcherId: number): boolean;
|
deregisterLinkMatcher(matcherId: number): boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ICircularList<T> {
|
export interface ICircularList<T> extends IEventEmitter {
|
||||||
length: number;
|
length: number;
|
||||||
maxLength: number;
|
maxLength: number;
|
||||||
|
|
||||||
@ -86,6 +103,11 @@ interface ICircularList<T> {
|
|||||||
shiftElements(start: number, count: number, offset: number): void;
|
shiftElements(start: number, count: number, offset: number): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IEventEmitter {
|
||||||
|
on(type, listener): void;
|
||||||
|
off(type, listener): void;
|
||||||
|
}
|
||||||
|
|
||||||
export interface LinkMatcherOptions {
|
export interface LinkMatcherOptions {
|
||||||
/**
|
/**
|
||||||
* The index of the link from the regex.match(text) call. This defaults to 0
|
* The index of the link from the regex.match(text) call. This defaults to 0
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
import jsdom = require('jsdom');
|
import jsdom = require('jsdom');
|
||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
import { ITerminal } from './Interfaces';
|
import { ITerminal, ICircularList } from './Interfaces';
|
||||||
import { CharMeasure } from './utils/CharMeasure';
|
import { CharMeasure } from './utils/CharMeasure';
|
||||||
import { CircularList } from './utils/CircularList';
|
import { CircularList } from './utils/CircularList';
|
||||||
import { SelectionManager } from './SelectionManager';
|
import { SelectionManager } from './SelectionManager';
|
||||||
@ -13,7 +13,7 @@ import { BufferSet } from './BufferSet';
|
|||||||
class TestSelectionManager extends SelectionManager {
|
class TestSelectionManager extends SelectionManager {
|
||||||
constructor(
|
constructor(
|
||||||
terminal: ITerminal,
|
terminal: ITerminal,
|
||||||
buffer: CircularList<any>,
|
buffer: ICircularList<[number, string, number][]>,
|
||||||
rowContainer: HTMLElement,
|
rowContainer: HTMLElement,
|
||||||
charMeasure: CharMeasure
|
charMeasure: CharMeasure
|
||||||
) {
|
) {
|
||||||
@ -37,7 +37,7 @@ describe('SelectionManager', () => {
|
|||||||
let document: Document;
|
let document: Document;
|
||||||
|
|
||||||
let terminal: ITerminal;
|
let terminal: ITerminal;
|
||||||
let bufferLines: CircularList<any>;
|
let bufferLines: ICircularList<[number, string, number][]>;
|
||||||
let rowContainer: HTMLElement;
|
let rowContainer: HTMLElement;
|
||||||
let selectionManager: TestSelectionManager;
|
let selectionManager: TestSelectionManager;
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import * as Browser from './utils/Browser';
|
|||||||
import { CharMeasure } from './utils/CharMeasure';
|
import { CharMeasure } from './utils/CharMeasure';
|
||||||
import { CircularList } from './utils/CircularList';
|
import { CircularList } from './utils/CircularList';
|
||||||
import { EventEmitter } from './EventEmitter';
|
import { EventEmitter } from './EventEmitter';
|
||||||
import { ITerminal } from './Interfaces';
|
import { ITerminal, ICircularList } from './Interfaces';
|
||||||
import { SelectionModel } from './SelectionModel';
|
import { SelectionModel } from './SelectionModel';
|
||||||
import { translateBufferLineToString } from './utils/BufferLine';
|
import { translateBufferLineToString } from './utils/BufferLine';
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ export class SelectionManager extends EventEmitter {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _terminal: ITerminal,
|
private _terminal: ITerminal,
|
||||||
private _buffer: CircularList<any>,
|
private _buffer: ICircularList<[number, string, number][]>,
|
||||||
private _rowContainer: HTMLElement,
|
private _rowContainer: HTMLElement,
|
||||||
private _charMeasure: CharMeasure
|
private _charMeasure: CharMeasure
|
||||||
) {
|
) {
|
||||||
@ -147,7 +147,7 @@ export class SelectionManager extends EventEmitter {
|
|||||||
* switched in or out.
|
* switched in or out.
|
||||||
* @param buffer The active buffer.
|
* @param buffer The active buffer.
|
||||||
*/
|
*/
|
||||||
public setBuffer(buffer: CircularList<any>): void {
|
public setBuffer(buffer: ICircularList<[number, string, number][]>): void {
|
||||||
this._buffer = buffer;
|
this._buffer = buffer;
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
}
|
}
|
||||||
@ -186,7 +186,7 @@ export class SelectionManager extends EventEmitter {
|
|||||||
for (let i = start[1] + 1; i <= end[1] - 1; i++) {
|
for (let i = start[1] + 1; i <= end[1] - 1; i++) {
|
||||||
const bufferLine = this._buffer.get(i);
|
const bufferLine = this._buffer.get(i);
|
||||||
const lineText = translateBufferLineToString(bufferLine, true);
|
const lineText = translateBufferLineToString(bufferLine, true);
|
||||||
if (bufferLine.isWrapped) {
|
if ((<any>bufferLine).isWrapped) {
|
||||||
result[result.length - 1] += lineText;
|
result[result.length - 1] += lineText;
|
||||||
} else {
|
} else {
|
||||||
result.push(lineText);
|
result.push(lineText);
|
||||||
@ -197,7 +197,7 @@ export class SelectionManager extends EventEmitter {
|
|||||||
if (start[1] !== end[1]) {
|
if (start[1] !== end[1]) {
|
||||||
const bufferLine = this._buffer.get(end[1]);
|
const bufferLine = this._buffer.get(end[1]);
|
||||||
const lineText = translateBufferLineToString(bufferLine, true, 0, end[0]);
|
const lineText = translateBufferLineToString(bufferLine, true, 0, end[0]);
|
||||||
if (bufferLine.isWrapped) {
|
if ((<any>bufferLine).isWrapped) {
|
||||||
result[result.length - 1] += lineText;
|
result[result.length - 1] += lineText;
|
||||||
} else {
|
} else {
|
||||||
result.push(lineText);
|
result.push(lineText);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user