From 0b5ff47cc0f92d5fba77baa85b30adb74d37aa8e Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 5 Aug 2017 02:57:34 -0700 Subject: [PATCH] Give terminal options a proper interface --- src/Interfaces.ts | 21 +++++++++++++++++++++ src/Terminal.ts | 19 ++++++++++--------- src/Types.ts | 2 -- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/Interfaces.ts b/src/Interfaces.ts index c24aa2ef..98c7626a 100644 --- a/src/Interfaces.ts +++ b/src/Interfaces.ts @@ -50,6 +50,27 @@ export interface ITerminal { showCursor(): void; } +export interface ITerminalOptions { + cancelEvents?: boolean; + colors?: string[]; + cols?: number; + convertEol?: boolean; + cursorBlink?: boolean; + cursorStyle?: string; + debug?: boolean; + disableStdin?: boolean; + geometry?: [number, number]; + handler?: (data: string) => void; + popOnBell?: boolean; + rows?: number; + screenKeys?: boolean; + scrollback?: number; + tabStopWidth?: number; + termName?: string; + useFlowControl?: boolean; + visualBell?: boolean; +} + export interface IBuffer { lines: ICircularList<[number, string, number][]>; ydisp: number; diff --git a/src/Terminal.ts b/src/Terminal.ts index ebb0c687..79b5972f 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -29,8 +29,8 @@ import * as Mouse from './utils/Mouse'; import { CHARSETS } from './Charsets'; import { getRawByteCoords } from './utils/Mouse'; import { translateBufferLineToString } from './utils/BufferLine'; -import { TerminalOptions, CustomKeyEventHandler, Charset } from './Types'; -import { ITerminal, IBrowser } from './Interfaces'; +import { CustomKeyEventHandler, Charset } from './Types'; +import { ITerminal, IBrowser, ITerminalOptions } from './Interfaces'; // Declare for RequireJS in loadAddon declare var define: any; @@ -71,7 +71,7 @@ const CURSOR_BLINK_INTERVAL = 600; // TODO: Most of the color code should be removed after truecolor is implemented // Colors 0-15 -const tangoColors = [ +const tangoColors: string[] = [ // dark: '#2e3436', '#cc0000', @@ -94,7 +94,7 @@ const tangoColors = [ // Colors 0-15 + 16-255 // Much thanks to TooTallNate for writing this. -const defaultColors = (function() { +const defaultColors: string[] = (function() { let colors = tangoColors.slice(); let r = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff]; let i; @@ -125,9 +125,9 @@ const defaultColors = (function() { return colors; })(); -const _colors = defaultColors.slice(); +const _colors: string[] = defaultColors.slice(); -const vcolors = (function() { +const vcolors: number[][] = (function() { const out = []; let color; @@ -143,7 +143,7 @@ const vcolors = (function() { return out; })(); -const DEFAULT_OPTIONS: TerminalOptions = { +const DEFAULT_OPTIONS: ITerminalOptions = { colors: defaultColors, convertEol: false, termName: 'xterm', @@ -186,7 +186,7 @@ export class Terminal extends EventEmitter implements ITerminal { public browser: IBrowser = Browser; // TODO: Options should be private, remove from interface in favor of getOption - public options: TerminalOptions; + public options: ITerminalOptions; private colors: any; // TODO: This can be changed to an enum or boolean, 0 and 1 seem to be the only options @@ -294,7 +294,7 @@ export class Terminal extends EventEmitter implements ITerminal { * @alias module:xterm/src/xterm */ constructor( - options: any = {} + options: ITerminalOptions = {} ) { super(); @@ -2269,6 +2269,7 @@ export class Terminal extends EventEmitter implements ITerminal { const cursorBlinkInterval = this.cursorBlinkInterval; const inputHandler = this.inputHandler; const buffers = this.buffers; + // TODO: Need to make sure this still works Terminal.call(this, this.options); this.customKeyEventHandler = customKeyEventHandler; this.cursorBlinkInterval = cursorBlinkInterval; diff --git a/src/Types.ts b/src/Types.ts index 9e4b1e1a..34c6d94a 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -13,7 +13,5 @@ export type LinkMatcher = { export type LinkMatcherHandler = (event: MouseEvent, uri: string) => boolean | void; export type LinkMatcherValidationCallback = (uri: string, element: HTMLElement, callback: (isValid: boolean) => void) => void; -// TODO: Make this type more specific -export type TerminalOptions = {[key: string]: any}; export type CustomKeyEventHandler = (event: KeyboardEvent) => boolean; export type Charset = {[key: string]: string};