Skip to content

Commit

Permalink
Add new search addon, move AddonManager to public
Browse files Browse the repository at this point in the history
Because addons build on top of the API it needs to live in public, the main
reason for this is because the implementation of buffer differs on
public/Terminal and src/Terminal.
  • Loading branch information
Tyriar committed May 12, 2019
1 parent 0c588a7 commit 96be112
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 17 deletions.
9 changes: 6 additions & 3 deletions demo/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import { Terminal } from '../lib/public/Terminal';
import { AttachAddon } from 'xterm-addon-attach';
import { SearchAddon } from 'xterm-addon-search';
import { WebLinksAddon } from 'xterm-addon-web-links';

import * as fit from '../lib/addons/fit/fit';
Expand All @@ -28,10 +29,10 @@ declare let window: IWindowWithTerminal;

Terminal.applyAddon(fit);
Terminal.applyAddon(fullscreen);
Terminal.applyAddon(search);

let term;
let attachAddon: AttachAddon;
let searchAddon: SearchAddon;
let protocol;
let socketURL;
let socket;
Expand Down Expand Up @@ -95,6 +96,8 @@ function createTerminal(): void {
typedTerm.loadAddon(new WebLinksAddon());
attachAddon = new AttachAddon();
typedTerm.loadAddon(attachAddon);
searchAddon = new SearchAddon();
typedTerm.loadAddon(searchAddon);

window.term = term; // Expose `term` to window for debugging purposes
term.onResize((size: { cols: number, rows: number }) => {
Expand All @@ -119,12 +122,12 @@ function createTerminal(): void {
addDomListener(actionElements.findNext, 'keyup', (e) => {
const searchOptions = getSearchOptions();
searchOptions.incremental = e.key !== `Enter`;
term.findNext(actionElements.findNext.value, searchOptions);
searchAddon.findNext(actionElements.findNext.value, searchOptions);
});

addDomListener(actionElements.findPrevious, 'keyup', (e) => {
if (e.key === `Enter`) {
term.findPrevious(actionElements.findPrevious.value, getSearchOptions());
searchAddon.findPrevious(actionElements.findPrevious.value, getSearchOptions());
}
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"webpack": "^4.17.1",
"webpack-cli": "^3.1.0",
"xterm-addon-attach": "0.1.0-beta7",
"xterm-addon-search": "0.1.0-beta3",
"xterm-addon-web-links": "0.1.0-beta6",
"zmodem.js": "^0.1.5"
},
Expand Down
10 changes: 1 addition & 9 deletions src/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ import { DEFAULT_BELL_SOUND, SoundManager } from './SoundManager';
import { MouseZoneManager } from './MouseZoneManager';
import { AccessibilityManager } from './AccessibilityManager';
import { ScreenDprMonitor } from './ui/ScreenDprMonitor';
import { ITheme, IMarker, IDisposable, ITerminalAddon, ISelectionPosition } from 'xterm';
import { ITheme, IMarker, IDisposable, ISelectionPosition } from 'xterm';
import { removeTerminalFromCache } from './renderer/atlas/CharAtlasCache';
import { DomRenderer } from './renderer/dom/DomRenderer';
import { IKeyboardEvent } from './common/Types';
import { evaluateKeyboardEvent } from './core/input/Keyboard';
import { KeyboardResultType, ICharset, IBufferLine, IAttributeData } from './core/Types';
import { clone } from './common/Clone';
import { AddonManager } from './ui/AddonManager';
import { EventEmitter2, IEvent } from './common/EventEmitter2';
import { Attributes, DEFAULT_ATTR_DATA } from './core/buffer/BufferLine';
import { applyWindowsMode } from './WindowsMode';
Expand Down Expand Up @@ -212,7 +211,6 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
private _mouseZoneManager: IMouseZoneManager;
public mouseHelper: MouseHelper;
private _accessibilityManager: AccessibilityManager;
private _addonManager: AddonManager;
private _screenDprMonitor: ScreenDprMonitor;
private _theme: ITheme;
private _windowsMode: IDisposable | undefined;
Expand Down Expand Up @@ -275,7 +273,6 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
}

public dispose(): void {
this._addonManager.dispose();
super.dispose();
if (this._windowsMode) {
this._windowsMode.dispose();
Expand Down Expand Up @@ -361,7 +358,6 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
this.linkifier = this.linkifier || new Linkifier(this);
this._mouseZoneManager = this._mouseZoneManager || null;
this.soundManager = this.soundManager || new SoundManager(this);
this._addonManager = this._addonManager || new AddonManager();

// Create the terminal's buffers and set the current buffer
this.buffers = new BufferSet(this);
Expand Down Expand Up @@ -1973,10 +1969,6 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
// return this.options.bellStyle === 'sound' ||
// this.options.bellStyle === 'both';
}

public loadAddon(addon: ITerminalAddon): void {
return this._addonManager.loadAddon(this, addon);
}
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ export interface IPublicTerminal extends IDisposable, IEventEmitter {
setOption(key: string, value: any): void;
refresh(start: number, end: number): void;
reset(): void;
loadAddon(addon: ITerminalAddon): void;
}

export interface ITerminalAddon extends IDisposable {
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions src/ui/AddonManager.ts → src/public/AddonManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* @license MIT
*/

import { ITerminalAddon, IDisposable } from 'xterm';
import { IPublicTerminal } from '../Types';
import { ITerminalAddon, IDisposable, Terminal } from 'xterm';

export interface ILoadedAddon {
instance: ITerminalAddon;
Expand All @@ -24,7 +23,7 @@ export class AddonManager implements IDisposable {
}
}

public loadAddon(terminal: IPublicTerminal, instance: ITerminalAddon): void {
public loadAddon(terminal: Terminal, instance: ITerminalAddon): void {
const loadedAddon: ILoadedAddon = {
instance,
dispose: instance.dispose,
Expand Down
6 changes: 5 additions & 1 deletion src/public/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import { IBufferLine } from '../core/Types';
import { Terminal as TerminalCore } from '../Terminal';
import * as Strings from '../Strings';
import { IEvent } from '../common/EventEmitter2';
import { AddonManager } from './AddonManager';

export class Terminal implements ITerminalApi {
private _core: ITerminal;
private _addonManager: AddonManager;

constructor(options?: ITerminalOptions) {
this._core = new TerminalCore(options);
this._addonManager = new AddonManager();
}

public get onCursorMove(): IEvent<void> { return this._core.onCursorMove; }
Expand Down Expand Up @@ -115,6 +118,7 @@ export class Terminal implements ITerminalApi {
this._core.selectLines(start, end);
}
public dispose(): void {
this._addonManager.dispose();
this._core.dispose();
}
public destroy(): void {
Expand Down Expand Up @@ -174,7 +178,7 @@ export class Terminal implements ITerminalApi {
addon.apply(Terminal);
}
public loadAddon(addon: ITerminalAddon): void {
return this._core.loadAddon(addon);
return this._addonManager.loadAddon(this, addon);
}
public static get strings(): ILocalizableStrings {
return Strings;
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7231,6 +7231,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/xterm-addon-attach/-/xterm-addon-attach-0.1.0-beta7.tgz#787f6cce709611ee08ab731b95a62fa1c0bce6a9"
integrity sha512-nQr6LcYtpZcyDoHyL/BDIPJcTgL7qlHR/rvm8lSizQysGVT0pSzr5M7SjY3kQHw33U3hTer3c6oZzwjfj4ohOw==

[email protected]:
version "0.1.0-beta3"
resolved "https://registry.yarnpkg.com/xterm-addon-search/-/xterm-addon-search-0.1.0-beta3.tgz#0754fa329cd505d6591abf24aac560c72f865636"
integrity sha512-09w/h3wsFtCveH1C0Fu8dwVvjiNvWRgp2lDABSK/yQEGETq4nznLzRSiMnFMz1y1rilFUi3Xn+l4+tQK+8iORg==

[email protected]:
version "0.1.0-beta6"
resolved "https://registry.yarnpkg.com/xterm-addon-web-links/-/xterm-addon-web-links-0.1.0-beta6.tgz#9b4e862be8928ef455a667745bea479665db6c6b"
Expand Down

0 comments on commit 96be112

Please sign in to comment.