mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
@@ -13,18 +13,6 @@ describe('EventEmitter', () => {
|
||||
eventEmitter = new EventEmitter();
|
||||
});
|
||||
|
||||
describe('once', () => {
|
||||
it('should trigger the listener only once', () => {
|
||||
let count = 0;
|
||||
const listener = () => count++;
|
||||
eventEmitter.once('test', listener);
|
||||
eventEmitter.emit('test');
|
||||
assert.equal(count, 1);
|
||||
eventEmitter.emit('test');
|
||||
assert.equal(count, 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('emit', () => {
|
||||
it('should emit events to listeners', () => {
|
||||
let count1 = 0;
|
||||
|
||||
+6
-16
@@ -3,10 +3,10 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { IEventEmitter, IListenerType } from './Interfaces';
|
||||
import { IEventEmitter } from 'xterm';
|
||||
|
||||
export class EventEmitter implements IEventEmitter {
|
||||
private _events: {[type: string]: IListenerType[]};
|
||||
private _events: {[type: string]: ((...args: any[]) => void)[]};
|
||||
|
||||
constructor() {
|
||||
// Restore the previous events if available, this will happen if the
|
||||
@@ -14,12 +14,12 @@ export class EventEmitter implements IEventEmitter {
|
||||
this._events = this._events || {};
|
||||
}
|
||||
|
||||
public on(type: string, listener: IListenerType): void {
|
||||
public on(type: string, listener: ((...args: any[]) => void)): void {
|
||||
this._events[type] = this._events[type] || [];
|
||||
this._events[type].push(listener);
|
||||
}
|
||||
|
||||
public off(type: string, listener: IListenerType): void {
|
||||
public off(type: string, listener: ((...args: any[]) => void)): void {
|
||||
if (!this._events[type]) {
|
||||
return;
|
||||
}
|
||||
@@ -28,7 +28,7 @@ export class EventEmitter implements IEventEmitter {
|
||||
let i = obj.length;
|
||||
|
||||
while (i--) {
|
||||
if (obj[i] === listener || obj[i].listener === listener) {
|
||||
if (obj[i] === listener) {
|
||||
obj.splice(i, 1);
|
||||
return;
|
||||
}
|
||||
@@ -41,16 +41,6 @@ export class EventEmitter implements IEventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
public once(type: string, listener: IListenerType): void {
|
||||
function on(): void {
|
||||
let args = Array.prototype.slice.call(arguments);
|
||||
this.off(type, on);
|
||||
listener.apply(this, args);
|
||||
}
|
||||
(<any>on).listener = listener;
|
||||
this.on(type, on);
|
||||
}
|
||||
|
||||
public emit(type: string, ...args: any[]): void {
|
||||
if (!this._events[type]) {
|
||||
return;
|
||||
@@ -61,7 +51,7 @@ export class EventEmitter implements IEventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
public listeners(type: string): IListenerType[] {
|
||||
public listeners(type: string): ((...args: any[]) => void)[] {
|
||||
return this._events[type] || [];
|
||||
}
|
||||
|
||||
|
||||
+6
-28
@@ -3,6 +3,9 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/// <reference path="../typings/xterm.d.ts"/>
|
||||
|
||||
import { Terminal as PublicTerminal, ITerminalOptions as IPublicTerminalOptions, IEventEmitter } from 'xterm';
|
||||
import { ICharset, ILinkMatcherOptions } from './Interfaces';
|
||||
import { LinkMatcherHandler, LinkMatcherValidationCallback, LineData } from './Types';
|
||||
import { IColorSet, IRenderer } from './renderer/Interfaces';
|
||||
@@ -32,7 +35,7 @@ export interface ILinkifierAccessor {
|
||||
linkifier: ILinkifier;
|
||||
}
|
||||
|
||||
export interface ITerminal extends ILinkifierAccessor, IBufferAccessor, IElementAccessor, IEventEmitter {
|
||||
export interface ITerminal extends PublicTerminal, ILinkifierAccessor, IBufferAccessor, IElementAccessor {
|
||||
selectionManager: ISelectionManager;
|
||||
charMeasure: ICharMeasure;
|
||||
textarea: HTMLTextAreaElement;
|
||||
@@ -127,28 +130,14 @@ export interface IInputHandlingTerminal extends IEventEmitter {
|
||||
setOption(key: string, value: any): void;
|
||||
}
|
||||
|
||||
export interface ITerminalOptions {
|
||||
bellSound?: string;
|
||||
bellStyle?: string;
|
||||
// TODO: The options that are not in the public API should be reviewed
|
||||
export interface ITerminalOptions extends IPublicTerminalOptions {
|
||||
cancelEvents?: boolean;
|
||||
cols?: number;
|
||||
convertEol?: boolean;
|
||||
cursorBlink?: boolean;
|
||||
cursorStyle?: string;
|
||||
debug?: boolean;
|
||||
disableStdin?: boolean;
|
||||
enableBold?: boolean;
|
||||
fontSize?: number;
|
||||
fontFamily?: string;
|
||||
handler?: (data: string) => void;
|
||||
letterSpacing?: number;
|
||||
lineHeight?: number;
|
||||
rows?: number;
|
||||
screenKeys?: boolean;
|
||||
scrollback?: number;
|
||||
tabStopWidth?: number;
|
||||
termName?: string;
|
||||
theme?: ITheme;
|
||||
useFlowControl?: boolean;
|
||||
}
|
||||
|
||||
@@ -239,17 +228,6 @@ export interface ICircularList<T> extends IEventEmitter {
|
||||
shiftElements(start: number, count: number, offset: number): void;
|
||||
}
|
||||
|
||||
export interface IEventEmitter {
|
||||
on(type: string, listener: IListenerType): void;
|
||||
off(type: string, listener: IListenerType): void;
|
||||
emit(type: string, data?: any): void;
|
||||
}
|
||||
|
||||
export interface IListenerType {
|
||||
(data?: any): void;
|
||||
listener?: (data?: any) => void;
|
||||
}
|
||||
|
||||
export interface ILinkMatcherOptions {
|
||||
/**
|
||||
* The index of the link from the regex.match(text) call. This defaults to 0
|
||||
|
||||
+6
-4
@@ -2112,13 +2112,15 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
|
||||
}
|
||||
|
||||
private visualBell(): boolean {
|
||||
return this.options.bellStyle === 'visual' ||
|
||||
this.options.bellStyle === 'both';
|
||||
return false;
|
||||
// return this.options.bellStyle === 'visual' ||
|
||||
// this.options.bellStyle === 'both';
|
||||
}
|
||||
|
||||
private soundBell(): boolean {
|
||||
return this.options.bellStyle === 'sound' ||
|
||||
this.options.bellStyle === 'both';
|
||||
return this.options.bellStyle === 'sound';
|
||||
// return this.options.bellStyle === 'sound' ||
|
||||
// this.options.bellStyle === 'both';
|
||||
}
|
||||
|
||||
private syncBellSound(): void {
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { ITerminal, ITerminalOptions, ITheme, IEventEmitter } from '../Interfaces';
|
||||
import { ITerminal, ITerminalOptions, ITheme } from '../Interfaces';
|
||||
import { IEventEmitter } from 'xterm';
|
||||
|
||||
export interface IRenderer extends IEventEmitter {
|
||||
dimensions: IRenderDimensions;
|
||||
|
||||
@@ -3,13 +3,73 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { ITerminal, IBuffer, IBufferSet, IBrowser, ICharMeasure, ISelectionManager, ITerminalOptions, IListenerType, IInputHandlingTerminal, IViewport, ICircularList, ICompositionHelper, ITheme, ILinkifier, IMouseHelper } from '../Interfaces';
|
||||
import { ITerminal, IBuffer, IBufferSet, IBrowser, ICharMeasure, ISelectionManager, ITerminalOptions, IInputHandlingTerminal, IViewport, ICircularList, ICompositionHelper, ITheme, ILinkifier, IMouseHelper, ILinkMatcherOptions } from '../Interfaces';
|
||||
import { LineData } from '../Types';
|
||||
import { Buffer } from '../Buffer';
|
||||
import * as Browser from './Browser';
|
||||
import { IColorSet, IRenderer, IRenderDimensions, IColorManager } from '../renderer/Interfaces';
|
||||
|
||||
export class MockTerminal implements ITerminal {
|
||||
getOption(key: any): any {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
setOption(key: any, value: any): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
blur(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
focus(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
resize(columns: number, rows: number): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
writeln(data: string): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
open(parent: HTMLElement): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
registerLinkMatcher(regex: RegExp, handler: (event: MouseEvent, uri: string) => boolean | void, options?: ILinkMatcherOptions): number {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
deregisterLinkMatcher(matcherId: number): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
hasSelection(): boolean {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
getSelection(): string {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
clearSelection(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
selectAll(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
destroy(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
scrollPages(pageCount: number): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
scrollToTop(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
scrollToBottom(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
clear(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
write(data: string): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
bracketedPasteMode: boolean;
|
||||
mouseHelper: IMouseHelper;
|
||||
renderer: IRenderer;
|
||||
@@ -39,7 +99,7 @@ export class MockTerminal implements ITerminal {
|
||||
on(event: string, callback: () => void): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
off(type: string, listener: IListenerType): void {
|
||||
off(type: string, listener: (...args: any[]) => void): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
scrollLines(disp: number, suppressScrollEvent: boolean): void {
|
||||
@@ -184,10 +244,10 @@ export class MockInputHandlingTerminal implements IInputHandlingTerminal {
|
||||
setOption(key: string, value: any): void {
|
||||
this.options[key] = value;
|
||||
}
|
||||
on(type: string, listener: IListenerType): void {
|
||||
on(type: string, listener: (...args: any[]) => void): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
off(type: string, listener: IListenerType): void {
|
||||
off(type: string, listener: (...args: any[]) => void): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
emit(type: string, data?: any): void {
|
||||
@@ -220,10 +280,10 @@ export class MockBuffer implements IBuffer {
|
||||
|
||||
export class MockRenderer implements IRenderer {
|
||||
colorManager: IColorManager;
|
||||
on(type: string, listener: IListenerType): void {
|
||||
on(type: string, listener: (...args: any[]) => void): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
off(type: string, listener: IListenerType): void {
|
||||
off(type: string, listener: (...args: any[]) => void): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
emit(type: string, data?: any): void {
|
||||
|
||||
Vendored
+10
-2
@@ -172,10 +172,16 @@ declare module 'xterm' {
|
||||
priority?: number;
|
||||
}
|
||||
|
||||
export interface IEventEmitter {
|
||||
on(type: string, listener: (...args: any[]) => void): void;
|
||||
off(type: string, listener: (...args: any[]) => void): void;
|
||||
emit(type: string, data?: any): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* The class that represents an xterm.js terminal.
|
||||
*/
|
||||
export class Terminal {
|
||||
export class Terminal implements IEventEmitter {
|
||||
/**
|
||||
* The element containing the terminal.
|
||||
*/
|
||||
@@ -224,7 +230,7 @@ declare module 'xterm' {
|
||||
* @param type The type of the event.
|
||||
* @param listener The listener.
|
||||
*/
|
||||
on(type: 'data', listener: (data?: string) => void): void;
|
||||
on(type: 'data', listener: (...args: any[]) => void): void;
|
||||
/**
|
||||
* Registers an event listener.
|
||||
* @param type The type of the event.
|
||||
@@ -275,6 +281,8 @@ declare module 'xterm' {
|
||||
*/
|
||||
off(type: 'blur' | 'focus' | 'linefeed' | 'selection' | 'data' | 'key' | 'keypress' | 'keydown' | 'refresh' | 'resize' | 'scroll' | 'title' | string, listener: (...args: any[]) => void): void;
|
||||
|
||||
emit(type: string, data?: any): void;
|
||||
|
||||
/**
|
||||
* Resizes the terminal.
|
||||
* @param x The number of columns to resize to.
|
||||
|
||||
Reference in New Issue
Block a user