Skip to content

Commit

Permalink
Merge f654044 into 0fae9bb
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar authored May 12, 2019
2 parents 0fae9bb + f654044 commit e54993f
Show file tree
Hide file tree
Showing 17 changed files with 333 additions and 80 deletions.
21 changes: 13 additions & 8 deletions demo/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
/// <reference path="../typings/xterm.d.ts"/>

import { Terminal } from '../lib/public/Terminal';
import * as attach from '../lib/addons/attach/attach';
import { AttachAddon } from 'xterm-addon-attach';
import { WebLinksAddon } from 'xterm-addon-web-links';

import * as fit from '../lib/addons/fit/fit';
import * as fullscreen from '../lib/addons/fullscreen/fullscreen';
import * as search from '../lib/addons/search/search';
import * as webLinks from '../lib/addons/webLinks/webLinks';
import { ISearchOptions } from '../lib/addons/search/Interfaces';

// Pulling in the module's types relies on the <reference> above, it's looks a
Expand All @@ -25,14 +26,12 @@ export interface IWindowWithTerminal extends Window {
}
declare let window: IWindowWithTerminal;

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


let term;
let attachAddon: AttachAddon;
let protocol;
let socketURL;
let socket;
Expand Down Expand Up @@ -85,10 +84,18 @@ function createTerminal(): void {
while (terminalContainer.children.length) {
terminalContainer.removeChild(terminalContainer.children[0]);
}

const isWindows = ['Windows', 'Win16', 'Win32', 'WinCE'].indexOf(navigator.platform) >= 0;
term = new Terminal({
windowsMode: isWindows
} as ITerminalOptions);

// Load addons
const typedTerm = term as TerminalType;
typedTerm.loadAddon(new WebLinksAddon());
attachAddon = new AttachAddon();
typedTerm.loadAddon(attachAddon);

window.term = term; // Expose `term` to window for debugging purposes
term.onResize((size: { cols: number, rows: number }) => {
if (!pid) {
Expand All @@ -104,8 +111,6 @@ function createTerminal(): void {
socketURL = protocol + location.hostname + ((location.port) ? (':' + location.port) : '') + '/terminals/';

term.open(terminalContainer);

term.webLinksInit();
term.fit();
term.focus();

Expand Down Expand Up @@ -148,7 +153,7 @@ function createTerminal(): void {
}

function runRealTerminal(): void {
term.attach(socket);
attachAddon.attach(socket);
term._initialized = true;
}

Expand Down
4 changes: 3 additions & 1 deletion demo/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ const clientConfig = {
{
test: /\.js$/,
use: ["source-map-loader"],
enforce: "pre"
enforce: "pre",
exclude: /node_modules/
}
]
},
resolve: {
modules: [path.resolve(__dirname, '..'), 'node_modules'],
extensions: [ '.tsx', '.ts', '.js' ]
},
output: {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"vinyl-source-stream": "^1.1.0",
"webpack": "^4.17.1",
"webpack-cli": "^3.1.0",
"xterm-addon-attach": "0.1.0-beta7",
"xterm-addon-web-links": "0.1.0-beta6",
"zmodem.js": "^0.1.5"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/Terminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TestTerminal extends Terminal {
public keyPress(ev: any): boolean { return this._keyPress(ev); }
}

describe('xterm.js', () => {
describe('Terminal', () => {
let term: TestTerminal;
const termOptions = {
cols: INIT_COLS,
Expand Down
10 changes: 9 additions & 1 deletion src/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ import { DEFAULT_BELL_SOUND, SoundManager } from './SoundManager';
import { MouseZoneManager } from './MouseZoneManager';
import { AccessibilityManager } from './AccessibilityManager';
import { ScreenDprMonitor } from './ui/ScreenDprMonitor';
import { ITheme, IMarker, IDisposable } from 'xterm';
import { ITheme, IMarker, IDisposable, ITerminalAddon } 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 @@ -211,6 +212,7 @@ 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 @@ -273,6 +275,7 @@ 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 @@ -358,6 +361,7 @@ 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 @@ -1946,6 +1950,10 @@ 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
5 changes: 4 additions & 1 deletion src/TestUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IBufferLine, ICellData, IAttributeData } from './core/Types';
import { ICircularList, XtermListener } from './common/Types';
import { Buffer } from './Buffer';
import * as Browser from './common/Platform';
import { ITheme, IDisposable, IMarker, IEvent } from 'xterm';
import { ITheme, IDisposable, IMarker, IEvent, ITerminalAddon } from 'xterm';
import { Terminal } from './Terminal';
import { AttributeData } from './core/buffer/BufferLine';

Expand All @@ -30,6 +30,9 @@ export class MockTerminal implements ITerminal {
onKey: IEvent<{ key: string; domEvent: KeyboardEvent; }>;
onRender: IEvent<{ start: number; end: number; }>;
onResize: IEvent<{ cols: number; rows: number; }>;
loadAddon(addon: ITerminalAddon): void {
throw new Error('Method not implemented.');
}
markers: IMarker[];
addMarker(cursorYOffset: number): IMarker {
throw new Error('Method not implemented.');
Expand Down
97 changes: 51 additions & 46 deletions src/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @license MIT
*/

import { ITerminalOptions as IPublicTerminalOptions, IEventEmitter, IDisposable, IMarker } from 'xterm';
import { ITerminalOptions as IPublicTerminalOptions, IEventEmitter, IDisposable, IMarker, Terminal } from 'xterm';
import { IColorSet, IRenderer } from './renderer/Types';
import { ICharset, IAttributeData, ICellData, IBufferLine, CharData } from './core/Types';
import { ICircularList } from './common/Types';
Expand Down Expand Up @@ -221,51 +221,56 @@ export interface ITerminal extends IPublicTerminal, IElementAccessor, IBufferAcc
}

export interface IPublicTerminal extends IDisposable, IEventEmitter {
textarea: HTMLTextAreaElement;
rows: number;
cols: number;
buffer: IBuffer;
markers: IMarker[];
onCursorMove: IEvent<void>;
onData: IEvent<string>;
onKey: IEvent<{ key: string, domEvent: KeyboardEvent }>;
onLineFeed: IEvent<void>;
onScroll: IEvent<number>;
onSelectionChange: IEvent<void>;
onRender: IEvent<{ start: number, end: number }>;
onResize: IEvent<{ cols: number, rows: number }>;
onTitleChange: IEvent<string>;
blur(): void;
focus(): void;
resize(columns: number, rows: number): void;
writeln(data: string): void;
open(parent: HTMLElement): void;
attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;
addCsiHandler(flag: string, callback: (params: number[], collect: string) => boolean): IDisposable;
addOscHandler(ident: number, callback: (data: string) => boolean): IDisposable;
registerLinkMatcher(regex: RegExp, handler: (event: MouseEvent, uri: string) => void, options?: ILinkMatcherOptions): number;
deregisterLinkMatcher(matcherId: number): void;
registerCharacterJoiner(handler: (text: string) => [number, number][]): number;
deregisterCharacterJoiner(joinerId: number): void;
addMarker(cursorYOffset: number): IMarker;
hasSelection(): boolean;
getSelection(): string;
clearSelection(): void;
selectAll(): void;
selectLines(start: number, end: number): void;
dispose(): void;
destroy(): void;
scrollLines(amount: number): void;
scrollPages(pageCount: number): void;
scrollToTop(): void;
scrollToBottom(): void;
scrollToLine(line: number): void;
clear(): void;
write(data: string): void;
getOption(key: string): any;
setOption(key: string, value: any): void;
refresh(start: number, end: number): void;
reset(): void;
textarea: HTMLTextAreaElement;
rows: number;
cols: number;
buffer: IBuffer;
markers: IMarker[];
onCursorMove: IEvent<void>;
onData: IEvent<string>;
onKey: IEvent<{ key: string, domEvent: KeyboardEvent }>;
onLineFeed: IEvent<void>;
onScroll: IEvent<number>;
onSelectionChange: IEvent<void>;
onRender: IEvent<{ start: number, end: number }>;
onResize: IEvent<{ cols: number, rows: number }>;
onTitleChange: IEvent<string>;
blur(): void;
focus(): void;
resize(columns: number, rows: number): void;
writeln(data: string): void;
open(parent: HTMLElement): void;
attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;
addCsiHandler(flag: string, callback: (params: number[], collect: string) => boolean): IDisposable;
addOscHandler(ident: number, callback: (data: string) => boolean): IDisposable;
registerLinkMatcher(regex: RegExp, handler: (event: MouseEvent, uri: string) => void, options?: ILinkMatcherOptions): number;
deregisterLinkMatcher(matcherId: number): void;
registerCharacterJoiner(handler: (text: string) => [number, number][]): number;
deregisterCharacterJoiner(joinerId: number): void;
addMarker(cursorYOffset: number): IMarker;
hasSelection(): boolean;
getSelection(): string;
clearSelection(): void;
selectAll(): void;
selectLines(start: number, end: number): void;
dispose(): void;
destroy(): void;
scrollLines(amount: number): void;
scrollPages(pageCount: number): void;
scrollToTop(): void;
scrollToBottom(): void;
scrollToLine(line: number): void;
clear(): void;
write(data: string): void;
getOption(key: string): any;
setOption(key: string, value: any): void;
refresh(start: number, end: number): void;
reset(): void;
loadAddon(addon: ITerminalAddon): void;
}

export interface ITerminalAddon extends IDisposable {
activate(terminal: Terminal): void;
}

export interface IBufferAccessor {
Expand Down
1 change: 0 additions & 1 deletion src/addons/search/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Terminal } from 'xterm';

// TODO: Don't rely on this private API
export interface ITerminalCore {
buffer: any;
selectionManager: any;
}

Expand Down
Loading

0 comments on commit e54993f

Please sign in to comment.