diff --git a/.gitignore b/.gitignore index f98114933b..8e28c797f8 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ npm-debug.log build/ .vscode/ .DS_Store +fixtures/typings-test/*.js # Directories needed for code coverage /coverage/ diff --git a/fixtures/typings-test/tsconfig.json b/fixtures/typings-test/tsconfig.json new file mode 100644 index 0000000000..2dcff2ea1e --- /dev/null +++ b/fixtures/typings-test/tsconfig.json @@ -0,0 +1,9 @@ +{ + "files": [ + "typings-test.ts" + ], + "compilerOptions": { + "module": "commonjs", + "target": "es5" + } +} diff --git a/fixtures/typings-test/typings-test.ts b/fixtures/typings-test/typings-test.ts new file mode 100644 index 0000000000..ffe6afd496 --- /dev/null +++ b/fixtures/typings-test/typings-test.ts @@ -0,0 +1,219 @@ +/** + * @license MIT + */ + +/// + +import { Terminal } from 'xterm'; + +namespace constructor { + { + new Terminal(); + new Terminal({}); + new Terminal({ + cols: 1, + rows: 1 + }); + new Terminal({ + 'cols': 1, + 'cursorBlink': true, + 'cursorStyle': 'block', + 'disableStdin': false, + 'rows': 1, + 'scrollback': 10, + 'tabStopWidth': 2, + }); + } +} + +namespace properties { + { + const t: Terminal = new Terminal(); + const element: HTMLElement = t.element; + const textarea: HTMLTextAreaElement = t.textarea; + } +} + +namespace static_methods { + { + Terminal.loadAddon('attach'); + Terminal.loadAddon('fit'); + Terminal.loadAddon('fullscreen'); + Terminal.loadAddon('search'); + Terminal.loadAddon('terminado'); + } +} + +namespace methods_core { + { + const t: Terminal = new Terminal(); + t.blur(); + t.focus(); + t.destroy(); + t.clear(); + t.refresh(0, 1); + t.reset(); + t.resize(1, 1); + t.write('foo'); + t.writeln('foo'); + } + { + const t: Terminal = new Terminal(); + // no arg + t.on('blur', () => {}); + t.on('focus', () => {}); + t.on('lineFeed', () => {}); + // args + t.on('data', () => {}); + t.on('data', (data: string) => console.log(data)); + t.on('key', () => {}); + t.on('key', (key: string) => console.log(key, event)); + t.on('key', (key: string, event: KeyboardEvent) => console.log(key, event)); + t.on('keydown', () => {}); + t.on('keydown', (event: KeyboardEvent) => console.log(event)); + t.on('keypress', () => {}); + t.on('keypress', (event: KeyboardEvent) => console.log(event)); + t.on('refresh', () => {}); + t.on('refresh', (data: {start: number, end: number}) => console.log(data)); + t.on('resize', () => {}); + t.on('resize', (data: {cols: number, rows: number}) => console.log(data)); + t.on('scroll', () => {}); + t.on('scroll', (ydisp: number) => console.log(ydisp)); + t.on('title', () => {}); + t.on('title', (title: string) => console.log(title)); + } + { + const t: Terminal = new Terminal(); + // no arg + t.off('blur', () => {}); + t.off('focus', () => {}); + t.off('lineFeed', () => {}); + // args + t.off('data', () => {}); + t.off('data', (data: string) => console.log(data)); + t.off('key', () => {}); + t.off('key', (key: string) => console.log(key, event)); + t.off('key', (key: string, event: KeyboardEvent) => console.log(key, event)); + t.off('keydown', () => {}); + t.off('keydown', (event: KeyboardEvent) => console.log(event)); + t.off('keypress', () => {}); + t.off('keypress', (event: KeyboardEvent) => console.log(event)); + t.off('refresh', () => {}); + t.off('refresh', (data: {element: HTMLElement, start: number, end: number}) => console.log(data)); + t.off('resize', () => {}); + t.off('resize', (data: {terminal: Terminal, cols: number, rows: number}) => console.log(data)); + t.off('scroll', () => {}); + t.off('scroll', (ydisp: number) => console.log(ydisp)); + t.off('title', () => {}); + t.off('title', (title: string) => console.log(title)); + } + { + const t: Terminal = new Terminal(); + const e: HTMLElement = null; + t.open(e); + } + { + const t: Terminal = new Terminal(); + t.attachCustomKeyEventHandler((e: KeyboardEvent) => true); + t.attachCustomKeyEventHandler((e: KeyboardEvent) => false); + } + namespace options { + { + const t: Terminal = new Terminal(); + const r01: string = t.getOption('cursorStyle'); + const r02: string = t.getOption('termName'); + const r03: boolean = t.getOption('cancelEvents'); + const r04: boolean = t.getOption('convertEol'); + const r05: boolean = t.getOption('cursorBlink'); + const r06: boolean = t.getOption('debug'); + const r07: boolean = t.getOption('disableStdin'); + const r08: boolean = t.getOption('popOnBell'); + const r09: boolean = t.getOption('screenKeys'); + const r10: boolean = t.getOption('useFlowControl'); + const r11: boolean = t.getOption('visualBell'); + const r12: string[] = t.getOption('colors'); + const r13: number = t.getOption('cols'); + const r14: number = t.getOption('rows'); + const r15: number = t.getOption('tabStopWidth'); + const r16: number = t.getOption('scrollback'); + const r17: [number, number] = t.getOption('geometry'); + const r18: (data: string) => void = t.getOption('handler'); + const r19: string = t.getOption('bellSound'); + const r20: string = t.getOption('bellStyle'); + } + { + const t: Terminal = new Terminal(); + t.setOption('cursorStyle', 'bar'); + t.setOption('cursorStyle', 'block'); + t.setOption('cursorStyle', 'underline'); + t.setOption('termName', 'foo'); + t.setOption('cancelEvents', true); + t.setOption('convertEol', true); + t.setOption('cursorBlink', true); + t.setOption('debug', true); + t.setOption('disableStdin', true); + t.setOption('popOnBell', true); + t.setOption('screenKeys', true); + t.setOption('useFlowControl', true); + t.setOption('visualBell', true); + t.setOption('colors', ['a', 'b']); + t.setOption('cols', 1); + t.setOption('rows', 1); + t.setOption('tabStopWidth', 1); + t.setOption('scrollback', 1); + t.setOption('geometry', [1, 1]); + t.setOption('handler', (data: string) => console.log(data)); + t.setOption('bellSound', 'foo'); + t.setOption('bellStyle', 'none'); + t.setOption('bellStyle', 'visual'); + t.setOption('bellStyle', 'sound'); + t.setOption('bellStyle', 'both'); + } + } + namespace scrolling { + { + const t: Terminal = new Terminal(); + t.scrollDisp(-1); + t.scrollDisp(1); + t.scrollDisp(-1); + t.scrollDisp(1); + t.scrollToTop(); + t.scrollToBottom(); + } + } + namespace selection { + { + const t: Terminal = new Terminal(); + const r1: boolean = t.hasSelection(); + const r2: string = t.getSelection(); + t.clearSelection(); + t.selectAll(); + } + } +} + +namespace methods_experimental { + { + const t: Terminal = new Terminal(); + t.registerLinkMatcher(/foo/, () => {}); + t.registerLinkMatcher(new RegExp('foo'), () => {}); + t.registerLinkMatcher(/foo/, () => {}, {}); + t.registerLinkMatcher(/foo/, (event: MouseEvent, uri: string) => { + console.log(event, uri); + return void 0; + }, {}); + t.registerLinkMatcher(/foo/, () => true, {}); + t.registerLinkMatcher(/foo/, () => false, {}); + t.registerLinkMatcher(/foo/, () => true, { + matchIndex: 1 + }); + t.registerLinkMatcher(/foo/, () => true, { + matchIndex: 1, + priority: 1, + validationCallback: (uri: string, element: HTMLElement, callback: (isValid: boolean) => void) => { + console.log(uri, element, callback); + } + }); + t.deregisterLinkMatcher(1); + } +} diff --git a/package.json b/package.json index a5f0bd755e..9b550d6765 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ ".gitignore" ], "main": "lib/Terminal.js", - "types": "lib/Terminal.d.ts", + "types": "typings/xterm.d.ts", "repository": "https://github.com/sourcelair/xterm.js", "license": "MIT", "files": [ diff --git a/src/Renderer.ts b/src/Renderer.ts index f2999afaf5..b51a9ff93c 100644 --- a/src/Renderer.ts +++ b/src/Renderer.ts @@ -320,7 +320,7 @@ export class Renderer { this._terminal.element.appendChild(this._terminal.rowContainer); } - this._terminal.emit('refresh', {element: this._terminal.element, start: start, end: end}); + this._terminal.emit('refresh', {start, end}); }; /** diff --git a/src/Terminal.integration.ts b/src/Terminal.integration.ts index 2155d0e0b9..124e89cb8e 100644 --- a/src/Terminal.integration.ts +++ b/src/Terminal.integration.ts @@ -4,11 +4,13 @@ * This file contains integration tests for xterm.js. */ +import * as cp from 'child_process'; import * as glob from 'glob'; import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; import * as pty from 'node-pty'; +import { assert } from 'chai'; import { Terminal } from './Terminal'; import { CHAR_DATA_CHAR_INDEX } from './Buffer'; @@ -143,3 +145,18 @@ if (os.platform() !== 'win32') { } }); } + +describe('typings', () => { + it('should throw no compile errors', function (): void { + this.timeout(20000); + let tsc = path.join(__dirname, '..', 'node_modules', '.bin', 'tsc'); + if (process.platform === 'win32') { + tsc += '.cmd'; + } + const fixtureDir = path.join(__dirname, '..', 'fixtures', 'typings-test'); + let result = cp.spawnSync(tsc, { cwd: fixtureDir }); + assert.equal(result.status, 0, `build did not succeed:\nstdout: ${result.stdout.toString()}\nstderr: ${result.stderr.toString()}\n`); + // Clean up + fs.unlinkSync(path.join(fixtureDir, 'typings-test.js')); + }); +}); diff --git a/src/Terminal.ts b/src/Terminal.ts index 332642b104..a17cf94a9f 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -37,7 +37,7 @@ import * as Browser from './utils/Browser'; import * as Mouse from './utils/Mouse'; import { CHARSETS } from './Charsets'; import { getRawByteCoords } from './utils/Mouse'; -import { CustomKeyEventHandler, Charset, LinkMatcherHandler, LinkMatcherValidationCallback, CharData, LineData, Option, StringOption, BooleanOption, StringArrayOption, NumberOption, GeometryOption, HandlerOption } from './Types'; +import { CustomKeyEventHandler, Charset, LinkMatcherHandler, LinkMatcherValidationCallback, CharData, LineData } from './Types'; import { ITerminal, IBrowser, ITerminalOptions, IInputHandlingTerminal, ILinkMatcherOptions, IViewport, ICompositionHelper } from './Interfaces'; import { BellSound } from './utils/Sounds'; @@ -149,7 +149,7 @@ const DEFAULT_OPTIONS: ITerminalOptions = { cursorBlink: false, cursorStyle: 'block', bellSound: BellSound, - bellStyle: null, + bellStyle: 'none', scrollback: 1000, screenKeys: false, debug: false, @@ -415,13 +415,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT * Retrieves an option's value from the terminal. * @param {string} key The option key. */ - public getOption(key: StringOption): string; - public getOption(key: BooleanOption): boolean; - public getOption(key: StringArrayOption): number[]; - public getOption(key: NumberOption): number; - public getOption(key: GeometryOption): [number, number]; - public getOption(key: HandlerOption): (data: string) => void; - public getOption(key: Option): any { + public getOption(key: string): any { if (!(key in DEFAULT_OPTIONS)) { throw new Error('No option with key "' + key + '"'); } @@ -438,17 +432,21 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT * @param {string} key The option key. * @param {any} value The option value. */ - public setOption(key: StringOption, value: string): void; - public setOption(key: BooleanOption, value: boolean): void; - public setOption(key: StringArrayOption, value: number[]): void; - public setOption(key: NumberOption, value: number): void; - public setOption(key: GeometryOption, value: [number, number]): void; - public setOption(key: HandlerOption, value: (data: string) => void): void; - public setOption(key: Option, value: any): void { + public setOption(key: string, value: any): void { if (!(key in DEFAULT_OPTIONS)) { throw new Error('No option with key "' + key + '"'); } switch (key) { + case 'bellStyle': + if (!value) { + value = 'none'; + } + break; + case 'cursorStyle': + if (!value) { + value = 'block'; + } + break; case 'tabStopWidth': if (value < 1) { console.warn(`tabStopWidth cannot be less than 1, value: ${value}`); @@ -524,14 +522,15 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.showCursor(); this.restartCursorBlinking.apply(this); // TODO: Why pass terminal here? - this.emit('focus', {terminal: this}); + this.emit('focus'); }); }; /** - * Blur the terminal. Delegates blur handling to the terminal's DOM element. + * Blur the terminal, calling the blur function on the terminal's underlying + * textarea. */ - private blur(): void { + public blur(): void { return this.textarea.blur(); } @@ -547,7 +546,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.element.classList.remove('focus'); this.clearCursorBlinkingInterval.apply(this); // TODO: Why pass terminal here? - this.emit('blur', {terminal: this}); + this.emit('blur'); }); } @@ -722,14 +721,8 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.textarea.setAttribute('autocapitalize', 'off'); this.textarea.setAttribute('spellcheck', 'false'); this.textarea.tabIndex = 0; - this.textarea.addEventListener('focus', () => { - // TODO: Do we need terminal passed here? - this.emit('focus', {terminal: this}); - }); - this.textarea.addEventListener('blur', () => { - // TODO: Do we need terminal passed here? - this.emit('blur', {terminal: this}); - }); + this.textarea.addEventListener('focus', () => this.emit('focus')); + this.textarea.addEventListener('blur', () => this.emit('blur')); this.helperContainer.appendChild(this.textarea); this.compositionView = document.createElement('div'); @@ -777,13 +770,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT // Listen for mouse events and translate // them into terminal mouse protocols. this.bindMouse(); - - /** - * This event is emitted when terminal has completed opening. - * - * @event open - */ - this.emit('open'); } /** @@ -1233,9 +1219,9 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT /** * Scroll the display of the terminal - * @param {number} disp The number of lines to scroll down (negatives scroll up). + * @param {number} disp The number of lines to scroll down (negative scroll up). * @param {boolean} suppressScrollEvent Don't emit the scroll event as scrollDisp. This is used - * to avoid unwanted events being handled by the veiwport when the event was triggered from the + * to avoid unwanted events being handled by the viewport when the event was triggered from the * viewport originally. */ public scrollDisp(disp: number, suppressScrollEvent?: boolean): void { @@ -1355,12 +1341,13 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT } /** - * Attaches a custom key event handler which is run before keys are processed, giving consumers of - * xterm.js ultimate control as to what keys should be processed by the terminal and what keys - * should not. - * @param {function} customKeyEventHandler The custom KeyboardEvent handler to attach. This is a - * function that takes a KeyboardEvent, allowing consumers to stop propogation and/or prevent - * the default action. The function returns whether the event should be processed by xterm.js. + * Attaches a custom key event handler which is run before keys are processed, + * giving consumers of xterm.js ultimate control as to what keys should be + * processed by the terminal and what keys should not. + * @param customKeyEventHandler The custom KeyboardEvent handler to attach. + * This is a function that takes a KeyboardEvent, allowing consumers to stop + * propogation and/or prevent the default action. The function returns whether + * the event should be processed by xterm.js. */ public attachCustomKeyEventHandler(customKeyEventHandler: CustomKeyEventHandler): void { this.customKeyEventHandler = customKeyEventHandler; @@ -1403,10 +1390,10 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT * this searches the textContent of the rows. You will want to use \s to match * a space ' ' character for example. * @param handler The callback when the link is called. - * @param [options] Options for the link matcher. + * @param options Options for the link matcher. * @return The ID of the new matcher, this can be used to deregister. */ - public registerLinkMatcher(regex: RegExp, handler: LinkMatcherHandler, options: ILinkMatcherOptions): number { + public registerLinkMatcher(regex: RegExp, handler: LinkMatcherHandler, options?: ILinkMatcherOptions): number { if (this.linkifier) { const matcherId = this.linkifier.registerLinkMatcher(regex, handler, options); this.refresh(0, this.rows - 1); @@ -1962,7 +1949,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.refresh(0, this.rows - 1); this.geometry = [this.cols, this.rows]; - this.emit('resize', {terminal: this, cols: x, rows: y}); + this.emit('resize', {cols: x, rows: y}); } /** @@ -2063,7 +2050,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT } /** - * Clears the entire buffer, making the prompt line the new first line. + * Clear the entire buffer, making the prompt line the new first line. */ public clear(): void { if (this.buffer.ybase === 0 && this.buffer.y === 0) { diff --git a/src/Types.ts b/src/Types.ts index c1cf9e63e5..0753d80e19 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -18,26 +18,3 @@ export type Charset = {[key: string]: string}; export type CharData = [number, string, number]; export type LineData = CharData[]; - -export type Option = BooleanOption | StringOption | StringArrayOption | NumberOption | GeometryOption | HandlerOption; -export type BooleanOption = - 'cancelEvents' | - 'convertEol' | - 'cursorBlink' | - 'debug' | - 'disableStdin' | - 'screenKeys' | - 'useFlowControl'; -export type StringOption = - 'cursorStyle' | - 'bellStyle' | - 'bellSound' | - 'termName'; -export type StringArrayOption = 'colors'; -export type NumberOption = - 'cols' | - 'rows' | - 'tabStopWidth' | - 'scrollback'; -export type GeometryOption = 'geometry'; -export type HandlerOption = 'handler'; diff --git a/tsconfig.json b/tsconfig.json index a3aa790cfa..38bfd2faf6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,8 +5,7 @@ "rootDir": "src", "outDir": "lib", "sourceMap": true, - "removeComments": true, - "declaration": true + "removeComments": true }, "include": [ "src/**/*" diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts new file mode 100644 index 0000000000..7ccd19435e --- /dev/null +++ b/typings/xterm.d.ts @@ -0,0 +1,389 @@ +/** + * @license MIT + * + * This contains the type declarations for the xterm.js library. Note that + * some interfaces differ between this file and the actual implementation in + * src/, that's because this file declares the *public* API which is intended + * to be stable and consumed by external programs. + */ + +/** + * An object containing start up options for the terminal. + */ +interface ITerminalOptions { + /** + * A data uri of the sound to use for the bell (needs bellStyle = 'sound'). + */ + bellSound?: string; + + /** + * The type of the bell notification the terminal will use. + */ + bellStyle?: 'none' | 'visual' | 'sound' | 'both'; + + /** + * The number of columns in the terminal. + */ + cols?: number; + + /** + * Whether the cursor blinks. + */ + cursorBlink?: boolean; + + /** + * The style of the cursor. + */ + cursorStyle?: 'block' | 'underline' | 'bar'; + + /** + * Whether input should be disabled. + */ + disableStdin?: boolean; + + /** + * The number of rows in the terminal. + */ + rows?: number; + + /** + * The amount of scrollback in the terminal. Scrollback is the amount of rows + * that are retained when lines are scrolled beyond the initial viewport. + */ + scrollback?: number; + + /** + * The size of tab stops in the terminal. + */ + tabStopWidth?: number; +} + +/** + * An object containing options for a link matcher. + */ +interface ILinkMatcherOptions { + /** + * The index of the link from the regex.match(text) call. This defaults to 0 + * (for regular expressions without capture groups). + */ + matchIndex?: number; + + /** + * A callback that validates an individual link, returning true if valid and + * false if invalid. + */ + validationCallback?: (uri: string, element: HTMLElement, callback: (isValid: boolean) => void) => void; + + /** + * The priority of the link matcher, this defines the order in which the link + * matcher is evaluated relative to others, from highest to lowest. The + * default value is 0. + */ + priority?: number; +} + +declare module 'xterm' { + /** + * The class that represents an xterm.js terminal. + */ + export class Terminal { + element: HTMLElement; + textarea: HTMLTextAreaElement; + + /** + * Creates a new `Terminal` object. + * + * @param options An object containing a set of options. + */ + constructor(options?: ITerminalOptions); + + /** + * Unfocus the terminal. + */ + blur(): void; + + /** + * Focus the terminal. + */ + focus(): void; + + /** + * Registers an event listener. + * @param type The type of the event. + * @param listener The listener. + */ + on(type: 'blur' | 'focus' | 'lineFeed', listener: () => void): void; + /** + * Registers an event listener. + * @param type The type of the event. + * @param listener The listener. + */ + on(type: 'data', listener: (data?: string) => void): void; + /** + * Registers an event listener. + * @param type The type of the event. + * @param listener The listener. + */ + on(type: 'key', listener: (key?: string, event?: KeyboardEvent) => void): void; + /** + * Registers an event listener. + * @param type The type of the event. + * @param listener The listener. + */ + on(type: 'keypress' | 'keydown', listener: (event?: KeyboardEvent) => void): void; + /** + * Registers an event listener. + * @param type The type of the event. + * @param listener The listener. + */ + on(type: 'refresh', listener: (data?: {start: number, end: number}) => void): void; + /** + * Registers an event listener. + * @param type The type of the event. + * @param listener The listener. + */ + on(type: 'resize', listener: (data?: {cols: number, rows: number}) => void): void; + /** + * Registers an event listener. + * @param type The type of the event. + * @param listener The listener. + */ + on(type: 'scroll', listener: (ydisp?: number) => void): void; + /** + * Registers an event listener. + * @param type The type of the event. + * @param listener The listener. + */ + on(type: 'title', listener: (title?: string) => void): void; + + /** + * Deregisters an event listener. + * @param type The type of the event. + * @param listener The listener. + */ + off(type: 'blur' | 'focus' | 'lineFeed' | 'data' | 'key' | 'keypress' | 'keydown' | 'refresh' | 'resize' | 'scroll' | 'title', listener: (...args: any[]) => void): void; + + /** + * Resizes the terminal. + * @param x The number of columns to resize to. + * @param y The number of rows to resize to. + */ + resize(columns: number, rows: number): void; + + /** + * Writes text to the terminal, followed by a break line character (\n). + * @param data The text to write to the terminal. + */ + writeln(data: string): void; + + /** + * Opens the terminal within an element. + * @param parent The element to create the terminal within. + */ + open(parent: HTMLElement): void; + + /** + * Attaches a custom key event handler which is run before keys are + * processed, giving consumers of xterm.js ultimate control as to what keys + * should be processed by the terminal and what keys should not. + * @param customKeyEventHandler The custom KeyboardEvent handler to attach. + * This is a function that takes a KeyboardEvent, allowing consumers to stop + * propogation and/or prevent the default action. The function returns + * whether the event should be processed by xterm.js. + */ + attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void; + + /** + * (EXPERIMENTAL) Registers a link matcher, allowing custom link patterns to + * be matched and handled. + * @param regex The regular expression to search for, specifically this + * searches the textContent of the rows. You will want to use \s to match a + * space ' ' character for example. + * @param handler The callback when the link is called. + * @param options Options for the link matcher. + * @return The ID of the new matcher, this can be used to deregister. + */ + registerLinkMatcher(regex: RegExp, handler: (event: MouseEvent, uri: string) => boolean | void , options?: ILinkMatcherOptions): number; + + /** + * (EXPERIMENTAL) Deregisters a link matcher if it has been registered. + * @param matcherId The link matcher's ID (returned after register) + */ + deregisterLinkMatcher(matcherId: number): void; + + /** + * Gets whether the terminal has an active selection. + */ + hasSelection(): boolean; + + /** + * Gets the terminal's current selection, this is useful for implementing + * copy behavior outside of xterm.js. + */ + getSelection(): string; + + /** + * Clears the current terminal selection. + */ + clearSelection(): void; + + /** + * Selects all text within the terminal. + */ + selectAll(): void; + + // /** + // * Find the next instance of the term, then scroll to and select it. If it + // * doesn't exist, do nothing. + // * @param term Tne search term. + // * @return Whether a result was found. + // */ + // findNext(term: string): boolean; + + // /** + // * Find the previous instance of the term, then scroll to and select it. If it + // * doesn't exist, do nothing. + // * @param term Tne search term. + // * @return Whether a result was found. + // */ + // findPrevious(term: string): boolean; + + /** + * Destroys the terminal and detaches it from the DOM. + */ + destroy(): void; + + /** + * Scroll the display of the terminal + * @param amount The number of lines to scroll down (negative scroll up). + */ + scrollDisp(amount: number): void; + + /** + * Scroll the display of the terminal by a number of pages. + * @param pageCount The number of pages to scroll (negative scrolls up). + */ + scrollPages(pageCount: number): void; + + /** + * Scrolls the display of the terminal to the top. + */ + scrollToTop(): void; + + /** + * Scrolls the display of the terminal to the bottom. + */ + scrollToBottom(): void; + + /** + * Clear the entire buffer, making the prompt line the new first line. + */ + clear(): void; + + /** + * Writes text to the terminal. + * @param data The text to write to the terminal. + */ + write(data: string): void; + + /** + * Retrieves an option's value from the terminal. + * @param key The option key. + */ + getOption(key: 'bellSound' | 'bellStyle' | 'cursorStyle' | 'termName'): string; + /** + * Retrieves an option's value from the terminal. + * @param key The option key. + */ + getOption(key: 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell'): boolean; + /** + * Retrieves an option's value from the terminal. + * @param key The option key. + */ + getOption(key: 'colors'): string[]; + /** + * Retrieves an option's value from the terminal. + * @param key The option key. + */ + getOption(key: 'cols' | 'rows' | 'tabStopWidth' | 'scrollback'): number; + /** + * Retrieves an option's value from the terminal. + * @param key The option key. + */ + getOption(key: 'geometry'): [number, number]; + /** + * Retrieves an option's value from the terminal. + * @param key The option key. + */ + getOption(key: 'handler'): (data: string) => void; + + /** + * Sets an option on the terminal. + * @param key The option key. + * @param value The option value. + */ + setOption(key: 'termName' | 'bellSound', value: string): void; + /** + * Sets an option on the terminal. + * @param key The option key. + * @param value The option value. + */ + setOption(key: 'bellStyle', value: null | 'none' | 'visual' | 'sound' | 'both'): void; + /** + * Sets an option on the terminal. + * @param key The option key. + * @param value The option value. + */ + setOption(key: 'cursorStyle', value: null | 'block' | 'underline' | 'bar'): void; + /** + * Sets an option on the terminal. + * @param key The option key. + * @param value The option value. + */ + setOption(key: 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell', value: boolean): void; + /** + * Sets an option on the terminal. + * @param key The option key. + * @param value The option value. + */ + setOption(key: 'colors', value: string[]): void; + /** + * Sets an option on the terminal. + * @param key The option key. + * @param value The option value. + */ + setOption(key: 'cols' | 'rows' | 'tabStopWidth' | 'scrollback', value: number): void; + /** + * Sets an option on the terminal. + * @param key The option key. + * @param value The option value. + */ + setOption(key: 'geometry', value: [number, number]): void; + /** + * Sets an option on the terminal. + * @param key The option key. + * @param value The option value. + */ + setOption(key: 'handler', value: (data: string) => void): void; + + /** + * Tells the renderer to refresh terminal content between two rows + * (inclusive) at the next opportunity. + * @param start The row to start from (between 0 and this.rows - 1). + * @param end The row to end at (between start and this.rows - 1). + */ + refresh(start: number, end: number): void; + + /** + * Perform a full reset (RIS, aka '\x1bc'). + */ + reset(): void + + /** + * Loads an addon, attaching it to the Terminal prototype and making it + * available to all newly created Terminals. + * @param addon The addon to load. + */ + static loadAddon(addon: 'attach' | 'fit' | 'fullscreen' | 'search' | 'terminado'): void; + } +}