mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Add onCursorMove, replace .on usage in addons
This commit is contained in:
@@ -218,6 +218,8 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
||||
public cols: number;
|
||||
public rows: number;
|
||||
|
||||
private _onCursorMove = new EventEmitter2<void>();
|
||||
public get onCursorMove(): IEvent<void> { return this._onCursorMove.event; }
|
||||
private _onLineFeed = new EventEmitter2<void>();
|
||||
public get onLineFeed(): IEvent<void> { return this._onLineFeed.event; }
|
||||
private _onSelectionChange = new EventEmitter2<void>();
|
||||
@@ -255,6 +257,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
||||
this._setup();
|
||||
|
||||
// TODO: Replace EventEmitter with EventEmitter2 internally
|
||||
this.on('cursormove', () => this._onCursorMove.fire());
|
||||
this.on('linefeed', () => this._onLineFeed.fire());
|
||||
this.on('selection', () => this._onSelectionChange.fire());
|
||||
this.on('data', e => this._onInput.fire(e));
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import { ISearchHelper, ISearchAddonTerminal, ISearchOptions, ISearchResult } from './Interfaces';
|
||||
import { IDisposable } from 'xterm';
|
||||
|
||||
const NON_WORD_CHARACTERS = ' ~!@#$%^&*()+`-=[]{}|\;:"\',./<>?';
|
||||
const LINES_CACHE_TIME_TO_LIVE = 15 * 1000; // 15 secs
|
||||
@@ -19,6 +20,7 @@ export class SearchHelper implements ISearchHelper {
|
||||
*/
|
||||
private _linesCache: string[] = null;
|
||||
private _linesCacheTimeoutId = 0;
|
||||
private _cursorMoveListener: IDisposable | undefined;
|
||||
|
||||
constructor(private _terminal: ISearchAddonTerminal) {
|
||||
this._destroyLinesCache = this._destroyLinesCache.bind(this);
|
||||
@@ -148,7 +150,7 @@ export class SearchHelper implements ISearchHelper {
|
||||
private _initLinesCache(): void {
|
||||
if (!this._linesCache) {
|
||||
this._linesCache = new Array(this._terminal._core.buffer.length);
|
||||
this._terminal.on('cursormove', this._destroyLinesCache);
|
||||
this._cursorMoveListener = this._terminal.onCursorMove(() => this._destroyLinesCache());
|
||||
}
|
||||
|
||||
window.clearTimeout(this._linesCacheTimeoutId);
|
||||
@@ -157,7 +159,10 @@ export class SearchHelper implements ISearchHelper {
|
||||
|
||||
private _destroyLinesCache(): void {
|
||||
this._linesCache = null;
|
||||
this._terminal.off('cursormove', this._destroyLinesCache);
|
||||
if (this._cursorMoveListener) {
|
||||
this._cursorMoveListener.dispose();
|
||||
this._cursorMoveListener = undefined;
|
||||
}
|
||||
if (this._linesCacheTimeoutId) {
|
||||
window.clearTimeout(this._linesCacheTimeoutId);
|
||||
this._linesCacheTimeoutId = 0;
|
||||
|
||||
@@ -59,9 +59,9 @@ export function terminadoAttach(term: Terminal, socket: WebSocket, bidirectional
|
||||
socket.addEventListener('message', addonTerminal.__getMessage);
|
||||
|
||||
if (bidirectional) {
|
||||
addonTerminal.on('data', addonTerminal.__sendData);
|
||||
addonTerminal.onInput(addonTerminal.__sendData);
|
||||
}
|
||||
addonTerminal.on('resize', addonTerminal.__setSize);
|
||||
addonTerminal.onResize(addonTerminal.__setSize);
|
||||
|
||||
socket.addEventListener('close', () => terminadoDetach(addonTerminal, socket));
|
||||
socket.addEventListener('error', () => terminadoDetach(addonTerminal, socket));
|
||||
|
||||
@@ -25,7 +25,7 @@ export function winptyCompatInit(terminal: Terminal): void {
|
||||
// space. This is certainly not without its problems, but generally on
|
||||
// Windows when text reaches the end of the terminal it's likely going to be
|
||||
// wrapped.
|
||||
addonTerminal.on('linefeed', () => {
|
||||
addonTerminal.onLineFeed(() => {
|
||||
const line = addonTerminal._core.buffer.lines.get(addonTerminal._core.buffer.ybase + addonTerminal._core.buffer.y - 1);
|
||||
const lastChar = line.get(addonTerminal.cols - 1);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ export class Terminal implements ITerminalApi {
|
||||
this._core = new TerminalCore(options);
|
||||
}
|
||||
|
||||
public get onCursorMove(): IEvent<void> { return this._core.onCursorMove; }
|
||||
public get onLineFeed(): IEvent<void> { return this._core.onLineFeed; }
|
||||
public get onSelectionChange(): IEvent<void> { return this._core.onSelectionChange; }
|
||||
public get onInput(): IEvent<string> { return this._core.onInput; }
|
||||
|
||||
@@ -8,7 +8,7 @@ import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminal, IBuff
|
||||
import { ICircularList, XtermListener } from '../common/Types';
|
||||
import { Buffer } from '../Buffer';
|
||||
import * as Browser from '../core/Platform';
|
||||
import { ITheme, IDisposable, IMarker } from 'xterm';
|
||||
import { ITheme, IDisposable, IMarker, IEvent } from 'xterm';
|
||||
import { Terminal } from '../Terminal';
|
||||
|
||||
export class TestTerminal extends Terminal {
|
||||
@@ -19,6 +19,15 @@ export class TestTerminal extends Terminal {
|
||||
}
|
||||
|
||||
export class MockTerminal implements ITerminal {
|
||||
onCursorMove: IEvent<void>;
|
||||
onLineFeed: IEvent<void>;
|
||||
onSelectionChange: IEvent<void>;
|
||||
onInput: IEvent<string>;
|
||||
onTitleChange: IEvent<string>;
|
||||
onScroll: IEvent<number>;
|
||||
onKey: IEvent<{ key: string; domEvent: KeyboardEvent; }>;
|
||||
onRender: IEvent<{ start: number; end: number; }>;
|
||||
onResize: IEvent<{ cols: number; rows: number; }>;
|
||||
markers: IMarker[];
|
||||
addMarker(cursorYOffset: number): IMarker {
|
||||
throw new Error('Method not implemented.');
|
||||
|
||||
Vendored
+6
@@ -361,6 +361,12 @@ declare module 'xterm' {
|
||||
*/
|
||||
constructor(options?: ITerminalOptions);
|
||||
|
||||
/**
|
||||
* Adds an event listener for the cursor moves.
|
||||
* @returns an `IDisposable` to stop listening.
|
||||
*/
|
||||
onCursorMove: IEvent<void>;
|
||||
|
||||
/**
|
||||
* Adds an event listener for when a line feed is added.
|
||||
* @returns an `IDisposable` to stop listening.
|
||||
|
||||
Reference in New Issue
Block a user