Merge pull request #1214 from Tyriar/fix_lint

Fix lint, update tslint and add more tslint rules
This commit is contained in:
Daniel Imms
2018-01-18 12:28:02 -08:00
committed by GitHub
35 changed files with 484 additions and 979 deletions
+251 -759
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -66,7 +66,7 @@
"node-pty": "^0.7.2", "node-pty": "^0.7.2",
"nodemon": "1.10.2", "nodemon": "1.10.2",
"sorcery": "^0.10.0", "sorcery": "^0.10.0",
"tslint": "^4.0.2", "tslint": "^5.9.1",
"typescript": "~2.4.0", "typescript": "~2.4.0",
"vinyl-buffer": "^1.0.0", "vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0", "vinyl-source-stream": "^1.1.0",
+3 -3
View File
@@ -3,19 +3,19 @@
* @license MIT * @license MIT
*/ */
import { Charset } from './Types'; import { ICharset } from './Interfaces';
/** /**
* The character sets supported by the terminal. These enable several languages * The character sets supported by the terminal. These enable several languages
* to be represented within the terminal with only 8-bit encoding. See ISO 2022 * to be represented within the terminal with only 8-bit encoding. See ISO 2022
* for a discussion on character sets. Only VT100 character sets are supported. * for a discussion on character sets. Only VT100 character sets are supported.
*/ */
export const CHARSETS: { [key: string]: Charset } = {}; export const CHARSETS: { [key: string]: ICharset } = {};
/** /**
* The default character set, US. * The default character set, US.
*/ */
export const DEFAULT_CHARSET: Charset = CHARSETS['B']; export const DEFAULT_CHARSET: ICharset = CHARSETS['B'];
/** /**
* DEC Special Character and Line Drawing Set. * DEC Special Character and Line Drawing Set.
+2 -2
View File
@@ -217,7 +217,7 @@ export class CompositionHelper {
if (!dontRecurse) { if (!dontRecurse) {
setTimeout(() => this.updateCompositionElements(true), 0); setTimeout(() => this.updateCompositionElements(true), 0);
} }
}; }
/** /**
* Clears the textarea's position so that the cursor does not blink on IE. * Clears the textarea's position so that the cursor does not blink on IE.
@@ -226,5 +226,5 @@ export class CompositionHelper {
private clearTextareaPosition(): void { private clearTextareaPosition(): void {
this.textarea.style.left = ''; this.textarea.style.left = '';
this.textarea.style.top = ''; this.textarea.style.top = '';
}; }
} }
+1 -1
View File
@@ -76,4 +76,4 @@ export namespace C0 {
export const SP = '\x20'; export const SP = '\x20';
/** Delete (Caret = ^?) */ /** Delete (Caret = ^?) */
export const DEL = '\x7f'; export const DEL = '\x7f';
}; }
+7 -7
View File
@@ -26,7 +26,7 @@ export class InputHandler implements IInputHandler {
if (char >= ' ') { if (char >= ' ') {
// calculate print space // calculate print space
// expensive call, therefore we save width in line buffer // expensive call, therefore we save width in line buffer
const ch_width = wcwidth(code); const chWidth = wcwidth(code);
if (this._terminal.charset && this._terminal.charset[char]) { if (this._terminal.charset && this._terminal.charset[char]) {
char = this._terminal.charset[char]; char = this._terminal.charset[char];
@@ -36,7 +36,7 @@ export class InputHandler implements IInputHandler {
// insert combining char in last cell // insert combining char in last cell
// FIXME: needs handling after cursor jumps // FIXME: needs handling after cursor jumps
if (!ch_width && this._terminal.buffer.x) { if (!chWidth && this._terminal.buffer.x) {
// dont overflow left // dont overflow left
if (this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1]) { if (this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1]) {
if (!this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1][CHAR_DATA_WIDTH_INDEX]) { if (!this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1][CHAR_DATA_WIDTH_INDEX]) {
@@ -56,7 +56,7 @@ export class InputHandler implements IInputHandler {
// goto next line if ch would overflow // goto next line if ch would overflow
// TODO: needs a global min terminal width of 2 // TODO: needs a global min terminal width of 2
if (this._terminal.buffer.x + ch_width - 1 >= this._terminal.cols) { if (this._terminal.buffer.x + chWidth - 1 >= this._terminal.cols) {
// autowrap - DECAWM // autowrap - DECAWM
if (this._terminal.wraparoundMode) { if (this._terminal.wraparoundMode) {
this._terminal.buffer.x = 0; this._terminal.buffer.x = 0;
@@ -70,7 +70,7 @@ export class InputHandler implements IInputHandler {
(<any>this._terminal.buffer.lines.get(this._terminal.buffer.y)).isWrapped = true; (<any>this._terminal.buffer.lines.get(this._terminal.buffer.y)).isWrapped = true;
} }
} else { } else {
if (ch_width === 2) // FIXME: check for xterm behavior if (chWidth === 2) // FIXME: check for xterm behavior
return; return;
} }
} }
@@ -79,7 +79,7 @@ export class InputHandler implements IInputHandler {
// insert mode: move characters to right // insert mode: move characters to right
if (this._terminal.insertMode) { if (this._terminal.insertMode) {
// do this twice for a fullwidth char // do this twice for a fullwidth char
for (let moves = 0; moves < ch_width; ++moves) { for (let moves = 0; moves < chWidth; ++moves) {
// remove last cell, if it's width is 0 // remove last cell, if it's width is 0
// we have to adjust the second last cell as well // we have to adjust the second last cell as well
const removed = this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase).pop(); const removed = this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase).pop();
@@ -94,12 +94,12 @@ export class InputHandler implements IInputHandler {
} }
} }
this._terminal.buffer.lines.get(row)[this._terminal.buffer.x] = [this._terminal.curAttr, char, ch_width, char.charCodeAt(0)]; this._terminal.buffer.lines.get(row)[this._terminal.buffer.x] = [this._terminal.curAttr, char, chWidth, char.charCodeAt(0)];
this._terminal.buffer.x++; this._terminal.buffer.x++;
this._terminal.updateRange(this._terminal.buffer.y); this._terminal.updateRange(this._terminal.buffer.y);
// fullwidth char - set next cell width to zero and advance cursor // fullwidth char - set next cell width to zero and advance cursor
if (ch_width === 2) { if (chWidth === 2) {
this._terminal.buffer.lines.get(row)[this._terminal.buffer.x] = [this._terminal.curAttr, '', 0, undefined]; this._terminal.buffer.lines.get(row)[this._terminal.buffer.x] = [this._terminal.curAttr, '', 0, undefined];
this._terminal.buffer.x++; this._terminal.buffer.x++;
} }
+27 -6
View File
@@ -3,8 +3,8 @@
* @license MIT * @license MIT
*/ */
import { ILinkMatcherOptions } from './Interfaces'; import { ICharset, ILinkMatcherOptions } from './Interfaces';
import { LinkMatcherHandler, LinkMatcherValidationCallback, Charset, LineData } from './Types'; import { LinkMatcherHandler, LinkMatcherValidationCallback, LineData } from './Types';
import { IColorSet, IRenderer } from './renderer/Interfaces'; import { IColorSet, IRenderer } from './renderer/Interfaces';
import { IMouseZoneManager } from './input/Interfaces'; import { IMouseZoneManager } from './input/Interfaces';
@@ -74,10 +74,10 @@ export interface IInputHandlingTerminal extends IEventEmitter {
options: ITerminalOptions; options: ITerminalOptions;
cols: number; cols: number;
rows: number; rows: number;
charset: Charset; charset: ICharset;
gcharset: number; gcharset: number;
glevel: number; glevel: number;
charsets: Charset[]; charsets: ICharset[];
applicationKeypad: boolean; applicationKeypad: boolean;
applicationCursor: boolean; applicationCursor: boolean;
originMode: boolean; originMode: boolean;
@@ -116,7 +116,7 @@ export interface IInputHandlingTerminal extends IEventEmitter {
blankLine(cur?: boolean, isWrapped?: boolean): LineData; blankLine(cur?: boolean, isWrapped?: boolean): LineData;
is(term: string): boolean; is(term: string): boolean;
send(data: string): void; send(data: string): void;
setgCharset(g: number, charset: Charset): void; setgCharset(g: number, charset: ICharset): void;
resize(x: number, y: number): void; resize(x: number, y: number): void;
log(text: string, data?: any): void; log(text: string, data?: any): void;
reset(): void; reset(): void;
@@ -248,7 +248,7 @@ export interface IEventEmitter {
export interface IListenerType { export interface IListenerType {
(data?: any): void; (data?: any): void;
listener?: (data?: any) => void; listener?: (data?: any) => void;
}; }
export interface ILinkMatcherOptions { export interface ILinkMatcherOptions {
/** /**
@@ -352,3 +352,24 @@ export interface ITheme {
brightCyan?: string; brightCyan?: string;
brightWhite?: string; brightWhite?: string;
} }
export interface ILinkMatcher {
id: number;
regex: RegExp;
handler: LinkMatcherHandler;
hoverTooltipCallback?: LinkMatcherHandler;
hoverLeaveCallback?: () => void;
matchIndex?: number;
validationCallback?: LinkMatcherValidationCallback;
priority?: number;
}
export interface ICharset {
[key: string]: string;
}
export interface ILinkHoverEvent {
x: number;
y: number;
length: number;
}
+3 -3
View File
@@ -4,9 +4,9 @@
*/ */
import { assert } from 'chai'; import { assert } from 'chai';
import { ITerminal, ILinkifier, IBuffer, IBufferAccessor, IElementAccessor } from './Interfaces'; import { ITerminal, ILinkifier, ILinkMatcher, IBuffer, IBufferAccessor, IElementAccessor } from './Interfaces';
import { Linkifier } from './Linkifier'; import { Linkifier } from './Linkifier';
import { LinkMatcher, LineData } from './Types'; import { LineData } from './Types';
import { IMouseZoneManager, IMouseZone } from './input/Interfaces'; import { IMouseZoneManager, IMouseZone } from './input/Interfaces';
import { MockBuffer } from './utils/TestUtils.test'; import { MockBuffer } from './utils/TestUtils.test';
import { CircularList } from './utils/CircularList'; import { CircularList } from './utils/CircularList';
@@ -17,7 +17,7 @@ class TestLinkifier extends Linkifier {
Linkifier.TIME_BEFORE_LINKIFY = 0; Linkifier.TIME_BEFORE_LINKIFY = 0;
} }
public get linkMatchers(): LinkMatcher[] { return this._linkMatchers; } public get linkMatchers(): ILinkMatcher[] { return this._linkMatchers; }
public linkifyRows(): void { super.linkifyRows(0, this._terminal.buffer.lines.length - 1); } public linkifyRows(): void { super.linkifyRows(0, this._terminal.buffer.lines.length - 1); }
} }
+10 -10
View File
@@ -3,8 +3,8 @@
* @license MIT * @license MIT
*/ */
import { ILinkMatcherOptions, ITerminal, IBufferAccessor, ILinkifier, IElementAccessor } from './Interfaces'; import { ILinkHoverEvent, ILinkMatcher, ILinkMatcherOptions, ITerminal, IBufferAccessor, ILinkifier, IElementAccessor } from './Interfaces';
import { LinkMatcher, LinkMatcherHandler, LinkMatcherValidationCallback, LineData, LinkHoverEvent, LinkHoverEventTypes } from './Types'; import { LinkMatcherHandler, LinkMatcherValidationCallback, LineData, LinkHoverEventTypes } from './Types';
import { IMouseZoneManager } from './input/Interfaces'; import { IMouseZoneManager } from './input/Interfaces';
import { MouseZone } from './input/MouseZoneManager'; import { MouseZone } from './input/MouseZoneManager';
import { EventEmitter } from './EventEmitter'; import { EventEmitter } from './EventEmitter';
@@ -44,7 +44,7 @@ export class Linkifier extends EventEmitter implements ILinkifier {
*/ */
protected static TIME_BEFORE_LINKIFY = 200; protected static TIME_BEFORE_LINKIFY = 200;
protected _linkMatchers: LinkMatcher[] = []; protected _linkMatchers: ILinkMatcher[] = [];
private _mouseZoneManager: IMouseZoneManager; private _mouseZoneManager: IMouseZoneManager;
private _rowsTimeoutId: number; private _rowsTimeoutId: number;
@@ -143,7 +143,7 @@ export class Linkifier extends EventEmitter implements ILinkifier {
if (this._nextLinkMatcherId !== HYPERTEXT_LINK_MATCHER_ID && !handler) { if (this._nextLinkMatcherId !== HYPERTEXT_LINK_MATCHER_ID && !handler) {
throw new Error('handler must be defined'); throw new Error('handler must be defined');
} }
const matcher: LinkMatcher = { const matcher: ILinkMatcher = {
id: this._nextLinkMatcherId++, id: this._nextLinkMatcherId++,
regex, regex,
handler, handler,
@@ -163,7 +163,7 @@ export class Linkifier extends EventEmitter implements ILinkifier {
* considered after older link matchers. * considered after older link matchers.
* @param matcher The link matcher to be added. * @param matcher The link matcher to be added.
*/ */
private _addLinkMatcherToList(matcher: LinkMatcher): void { private _addLinkMatcherToList(matcher: ILinkMatcher): void {
if (this._linkMatchers.length === 0) { if (this._linkMatchers.length === 0) {
this._linkMatchers.push(matcher); this._linkMatchers.push(matcher);
return; return;
@@ -219,7 +219,7 @@ export class Linkifier extends EventEmitter implements ILinkifier {
* @param offset The how much of the row has already been linkified. * @param offset The how much of the row has already been linkified.
* @return The link element(s) that were added. * @return The link element(s) that were added.
*/ */
private _doLinkifyRow(rowIndex: number, text: string, matcher: LinkMatcher, offset: number = 0): void { private _doLinkifyRow(rowIndex: number, text: string, matcher: ILinkMatcher, offset: number = 0): void {
// Iterate over nodes as we want to consider text nodes // Iterate over nodes as we want to consider text nodes
let result = []; let result = [];
const isHttpLinkMatcher = matcher.id === HYPERTEXT_LINK_MATCHER_ID; const isHttpLinkMatcher = matcher.id === HYPERTEXT_LINK_MATCHER_ID;
@@ -264,7 +264,7 @@ export class Linkifier extends EventEmitter implements ILinkifier {
* @param uri The URI of the link. * @param uri The URI of the link.
* @param matcher The link matcher for the link. * @param matcher The link matcher for the link.
*/ */
private _addLink(x: number, y: number, uri: string, matcher: LinkMatcher): void { private _addLink(x: number, y: number, uri: string, matcher: ILinkMatcher): void {
this._mouseZoneManager.add(new MouseZone( this._mouseZoneManager.add(new MouseZone(
x + 1, x + 1,
x + 1 + uri.length, x + 1 + uri.length,
@@ -276,17 +276,17 @@ export class Linkifier extends EventEmitter implements ILinkifier {
window.open(uri, '_blank'); window.open(uri, '_blank');
}, },
e => { e => {
this.emit(LinkHoverEventTypes.HOVER, <LinkHoverEvent>{ x, y, length: uri.length}); this.emit(LinkHoverEventTypes.HOVER, <ILinkHoverEvent>{ x, y, length: uri.length});
this._terminal.element.style.cursor = 'pointer'; this._terminal.element.style.cursor = 'pointer';
}, },
e => { e => {
this.emit(LinkHoverEventTypes.TOOLTIP, <LinkHoverEvent>{ x, y, length: uri.length}); this.emit(LinkHoverEventTypes.TOOLTIP, <ILinkHoverEvent>{ x, y, length: uri.length});
if (matcher.hoverTooltipCallback) { if (matcher.hoverTooltipCallback) {
matcher.hoverTooltipCallback(e, uri); matcher.hoverTooltipCallback(e, uri);
} }
}, },
() => { () => {
this.emit(LinkHoverEventTypes.LEAVE, <LinkHoverEvent>{ x, y, length: uri.length}); this.emit(LinkHoverEventTypes.LEAVE, <ILinkHoverEvent>{ x, y, length: uri.length});
this._terminal.element.style.cursor = ''; this._terminal.element.style.cursor = '';
if (matcher.hoverLeaveCallback) { if (matcher.hoverLeaveCallback) {
matcher.hoverLeaveCallback(); matcher.hoverLeaveCallback();
+1 -1
View File
@@ -6,7 +6,7 @@
import { assert } from 'chai'; import { assert } from 'chai';
import { ITerminal } from './Interfaces'; import { ITerminal } from './Interfaces';
import { SelectionModel } from './SelectionModel'; import { SelectionModel } from './SelectionModel';
import {BufferSet} from './BufferSet'; import { BufferSet } from './BufferSet';
import { MockTerminal } from './utils/TestUtils.test'; import { MockTerminal } from './utils/TestUtils.test';
class TestSelectionModel extends SelectionModel { class TestSelectionModel extends SelectionModel {
+18 -18
View File
@@ -15,17 +15,17 @@ import { assert } from 'chai';
import { Terminal } from './Terminal'; import { Terminal } from './Terminal';
import { CHAR_DATA_CHAR_INDEX } from './Buffer'; import { CHAR_DATA_CHAR_INDEX } from './Buffer';
let primitive_pty: any; let primitivePty: any;
// fake sychronous pty write - read // fake sychronous pty write - read
// we just pipe the data from slave to master as a child program would do // we just pipe the data from slave to master as a child program would do
// pty.js opens pipe fds with O_NONBLOCK // pty.js opens pipe fds with O_NONBLOCK
// just wait 10ms instead of setting fds to blocking mode // just wait 10ms instead of setting fds to blocking mode
function ptyWriteRead(data: string, cb: (result: string) => void): void { function ptyWriteRead(data: string, cb: (result: string) => void): void {
fs.writeSync(primitive_pty.slave, data); fs.writeSync(primitivePty.slave, data);
setTimeout(() => { setTimeout(() => {
let b = new Buffer(64000); let b = new Buffer(64000);
let bytes = fs.readSync(primitive_pty.master, b, 0, 64000, null); let bytes = fs.readSync(primitivePty.master, b, 0, 64000, null);
cb(b.toString('utf8', 0, bytes)); cb(b.toString('utf8', 0, bytes));
}); });
} }
@@ -37,7 +37,7 @@ function ptyReset(cb: (result: string) => void): void {
/* debug helpers */ /* debug helpers */
// generate colorful noisy output to compare xterm and emulator cell states // generate colorful noisy output to compare xterm and emulator cell states
function formatError(in_: string, out_: string, expected: string): string { function formatError(input: string, output: string, expected: string): string {
function addLineNumber(start: number, color: string): (s: string) => string { function addLineNumber(start: number, color: string): (s: string) => string {
let counter = start || 0; let counter = start || 0;
return function(s: string): string { return function(s: string): string {
@@ -47,9 +47,9 @@ function formatError(in_: string, out_: string, expected: string): string {
} }
let line80 = '12345678901234567890123456789012345678901234567890123456789012345678901234567890'; let line80 = '12345678901234567890123456789012345678901234567890123456789012345678901234567890';
let s = ''; let s = '';
s += '\n\x1b[34m' + JSON.stringify(in_); s += '\n\x1b[34m' + JSON.stringify(input);
s += '\n\x1b[33m ' + line80 + '\n'; s += '\n\x1b[33m ' + line80 + '\n';
s += out_.split('\n').map(addLineNumber(0, '\x1b[31m')).join('\n'); s += output.split('\n').map(addLineNumber(0, '\x1b[31m')).join('\n');
s += '\n\x1b[33m ' + line80 + '\n'; s += '\n\x1b[33m ' + line80 + '\n';
s += expected.split('\n').map(addLineNumber(0, '\x1b[32m')).join('\n'); s += expected.split('\n').map(addLineNumber(0, '\x1b[32m')).join('\n');
return s; return s;
@@ -58,15 +58,15 @@ function formatError(in_: string, out_: string, expected: string): string {
// simple debug output of terminal cells // simple debug output of terminal cells
function terminalToString(term: Terminal): string { function terminalToString(term: Terminal): string {
let result = ''; let result = '';
let line_s = ''; let lineText = '';
for (let line = term.buffer.ybase; line < term.buffer.ybase + term.rows; line++) { for (let line = term.buffer.ybase; line < term.buffer.ybase + term.rows; line++) {
line_s = ''; lineText = '';
for (let cell = 0; cell < term.cols; ++cell) { for (let cell = 0; cell < term.cols; ++cell) {
line_s += term.buffer.lines.get(line)[cell][CHAR_DATA_CHAR_INDEX]; lineText += term.buffer.lines.get(line)[cell][CHAR_DATA_CHAR_INDEX];
} }
// rtrim empty cells as xterm does // rtrim empty cells as xterm does
line_s = line_s.replace(/\s+$/, ''); lineText = lineText.replace(/\s+$/, '');
result += line_s; result += lineText;
result += '\n'; result += '\n';
} }
return result; return result;
@@ -83,7 +83,7 @@ if (os.platform() !== 'win32') {
/** some helpers for pty interaction */ /** some helpers for pty interaction */
// we need a pty in between to get the termios decorations // we need a pty in between to get the termios decorations
// for the basic test cases a raw pty device is enough // for the basic test cases a raw pty device is enough
primitive_pty = pty.native.open(COLS, ROWS); primitivePty = pty.native.open(COLS, ROWS);
/** tests */ /** tests */
describe('xterm output comparison', () => { describe('xterm output comparison', () => {
@@ -118,24 +118,24 @@ if (os.platform() !== 'win32') {
((filename: string) => { ((filename: string) => {
it(filename.split('/').slice(-1)[0], done => { it(filename.split('/').slice(-1)[0], done => {
ptyReset(() => { ptyReset(() => {
let in_file = fs.readFileSync(filename, 'utf8'); let inFile = fs.readFileSync(filename, 'utf8');
ptyWriteRead(in_file, from_pty => { ptyWriteRead(inFile, fromPty => {
// uncomment this to get log from terminal // uncomment this to get log from terminal
// console.log = function(){}; // console.log = function(){};
// Perform a synchronous .write(data) // Perform a synchronous .write(data)
xterm.writeBuffer.push(from_pty); xterm.writeBuffer.push(fromPty);
xterm.innerWrite(); xterm.innerWrite();
let from_emulator = terminalToString(xterm); let fromEmulator = terminalToString(xterm);
console.log = CONSOLE_LOG; console.log = CONSOLE_LOG;
let expected = fs.readFileSync(filename.split('.')[0] + '.text', 'utf8'); let expected = fs.readFileSync(filename.split('.')[0] + '.text', 'utf8');
// Some of the tests have whitespace on the right of lines, we trim all the linex // Some of the tests have whitespace on the right of lines, we trim all the linex
// from xterm.js so ignore this for now at least. // from xterm.js so ignore this for now at least.
let expectedRightTrimmed = expected.split('\n').map(l => l.replace(/\s+$/, '')).join('\n'); let expectedRightTrimmed = expected.split('\n').map(l => l.replace(/\s+$/, '')).join('\n');
if (from_emulator !== expectedRightTrimmed) { if (fromEmulator !== expectedRightTrimmed) {
// uncomment to get noisy output // uncomment to get noisy output
throw new Error(formatError(in_file, from_emulator, expected)); throw new Error(formatError(inFile, fromEmulator, expected));
// throw new Error('mismatch'); // throw new Error('mismatch');
} }
done(); done();
+11 -11
View File
@@ -38,9 +38,9 @@ import { CharMeasure } from './utils/CharMeasure';
import * as Browser from './utils/Browser'; import * as Browser from './utils/Browser';
import { MouseHelper } from './utils/MouseHelper'; import { MouseHelper } from './utils/MouseHelper';
import { CHARSETS } from './Charsets'; import { CHARSETS } from './Charsets';
import { CustomKeyEventHandler, Charset, LinkMatcherHandler, LinkMatcherValidationCallback, CharData, LineData } from './Types'; import { CustomKeyEventHandler, LinkMatcherHandler, LinkMatcherValidationCallback, CharData, LineData } from './Types';
import { ITerminal, IBrowser, ITerminalOptions, IInputHandlingTerminal, ILinkMatcherOptions, IViewport, ICompositionHelper, ITheme, ILinkifier } from './Interfaces'; import { ITerminal, IBrowser, ICharset, ITerminalOptions, IInputHandlingTerminal, ILinkMatcherOptions, IViewport, ICompositionHelper, ITheme, ILinkifier } from './Interfaces';
import { BellSound } from './utils/Sounds'; import { BELL_SOUND } from './utils/Sounds';
import { DEFAULT_ANSI_COLORS } from './renderer/ColorManager'; import { DEFAULT_ANSI_COLORS } from './renderer/ColorManager';
import { IMouseZoneManager } from './input/Interfaces'; import { IMouseZoneManager } from './input/Interfaces';
import { MouseZoneManager } from './input/MouseZoneManager'; import { MouseZoneManager } from './input/MouseZoneManager';
@@ -70,7 +70,7 @@ const DEFAULT_OPTIONS: ITerminalOptions = {
termName: 'xterm', termName: 'xterm',
cursorBlink: false, cursorBlink: false,
cursorStyle: 'block', cursorStyle: 'block',
bellSound: BellSound, bellSound: BELL_SOUND,
bellStyle: 'none', bellStyle: 'none',
enableBold: true, enableBold: true,
fontFamily: 'courier-new, courier, monospace', fontFamily: 'courier-new, courier, monospace',
@@ -131,10 +131,10 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
// charset // charset
// The current charset // The current charset
public charset: Charset; public charset: ICharset;
public gcharset: number; public gcharset: number;
public glevel: number; public glevel: number;
public charsets: Charset[]; public charsets: ICharset[];
// mouse properties // mouse properties
private decLocator: boolean; // This is unstable and never set private decLocator: boolean; // This is unstable and never set
@@ -181,7 +181,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
private writeStopped: boolean; private writeStopped: boolean;
// leftover surrogate high from previous write invocation // leftover surrogate high from previous write invocation
private surrogate_high: string; private surrogateHigh: string;
// Store if user went browsing history in scrollback // Store if user went browsing history in scrollback
private userScrolling: boolean; private userScrolling: boolean;
@@ -280,7 +280,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
this.xoffSentToCatchUp = false; this.xoffSentToCatchUp = false;
this.writeStopped = false; this.writeStopped = false;
this.surrogate_high = ''; this.surrogateHigh = '';
this.userScrolling = false; this.userScrolling = false;
this.inputHandler = new InputHandler(this); this.inputHandler = new InputHandler(this);
@@ -443,7 +443,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
this.element.classList.add('focus'); this.element.classList.add('focus');
this.showCursor(); this.showCursor();
this.emit('focus'); this.emit('focus');
}; }
/** /**
* Blur the terminal, calling the blur function on the terminal's underlying * Blur the terminal, calling the blur function on the terminal's underlying
@@ -1732,7 +1732,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
* @param g * @param g
* @param charset * @param charset
*/ */
public setgCharset(g: number, charset: Charset): void { public setgCharset(g: number, charset: ICharset): void {
this.charsets[g] = charset; this.charsets[g] = charset;
if (this.glevel === g) { if (this.glevel === g) {
this.charset = charset; this.charset = charset;
@@ -2224,7 +2224,7 @@ function matchColorDistance(r1: number, g1: number, b1: number, r2: number, g2:
return Math.pow(30 * (r1 - r2), 2) return Math.pow(30 * (r1 - r2), 2)
+ Math.pow(59 * (g1 - g2), 2) + Math.pow(59 * (g1 - g2), 2)
+ Math.pow(11 * (b1 - b2), 2); + Math.pow(11 * (b1 - b2), 2);
}; }
function matchColor_(r1: number, g1: number, b1: number): number { function matchColor_(r1: number, g1: number, b1: number): number {
+1 -18
View File
@@ -3,33 +3,16 @@
* @license MIT * @license MIT
*/ */
export type LinkMatcher = {
id: number,
regex: RegExp,
handler: LinkMatcherHandler,
hoverTooltipCallback?: LinkMatcherHandler,
hoverLeaveCallback?: () => void,
matchIndex?: number,
validationCallback?: LinkMatcherValidationCallback,
priority?: number
};
export type LinkMatcherHandler = (event: MouseEvent, uri: string) => boolean | void; export type LinkMatcherHandler = (event: MouseEvent, uri: string) => boolean | void;
export type LinkMatcherValidationCallback = (uri: string, callback: (isValid: boolean) => void) => void; export type LinkMatcherValidationCallback = (uri: string, callback: (isValid: boolean) => void) => void;
export type CustomKeyEventHandler = (event: KeyboardEvent) => boolean; export type CustomKeyEventHandler = (event: KeyboardEvent) => boolean;
export type Charset = {[key: string]: string};
export type CharData = [number, string, number, number]; export type CharData = [number, string, number, number];
export type LineData = CharData[]; export type LineData = CharData[];
export type LinkHoverEvent = {
x: number,
y: number,
length: number
};
export enum LinkHoverEventTypes { export enum LinkHoverEventTypes {
HOVER = 'linkhover', HOVER = 'linkhover',
TOOLTIP = 'linktooltip', TOOLTIP = 'linktooltip',
LEAVE = 'linkleave' LEAVE = 'linkleave'
}; }
+3 -3
View File
@@ -119,7 +119,7 @@ export class Viewport implements IViewport {
this.viewportElement.scrollTop += ev.deltaY * multiplier; this.viewportElement.scrollTop += ev.deltaY * multiplier;
// Prevent the page from scrolling when the terminal scrolls // Prevent the page from scrolling when the terminal scrolls
ev.preventDefault(); ev.preventDefault();
}; }
/** /**
* Handles the touchstart event, recording the touch occurred. * Handles the touchstart event, recording the touch occurred.
@@ -127,7 +127,7 @@ export class Viewport implements IViewport {
*/ */
public onTouchStart(ev: TouchEvent): void { public onTouchStart(ev: TouchEvent): void {
this.lastTouchY = ev.touches[0].pageY; this.lastTouchY = ev.touches[0].pageY;
}; }
/** /**
* Handles the touchmove event, scrolling the viewport if the position shifted. * Handles the touchmove event, scrolling the viewport if the position shifted.
@@ -141,5 +141,5 @@ export class Viewport implements IViewport {
} }
this.viewportElement.scrollTop += deltaY; this.viewportElement.scrollTop += deltaY;
ev.preventDefault(); ev.preventDefault();
}; }
} }
+1 -1
View File
@@ -5,7 +5,7 @@
import { assert, expect } from 'chai'; import { assert, expect } from 'chai';
import * as attach from './attach' import * as attach from './attach';
class MockTerminal {} class MockTerminal {}
+20 -21
View File
@@ -16,16 +16,16 @@
* should happen instantly or at a maximum * should happen instantly or at a maximum
* frequency of 1 rendering per 10ms. * frequency of 1 rendering per 10ms.
*/ */
export function attach(term, socket, bidirectional, buffered) { export function attach(term: any, socket: WebSocket, bidirectional: boolean, buffered: boolean): void {
bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional; bidirectional = (typeof bidirectional === 'undefined') ? true : bidirectional;
term.socket = socket; term.socket = socket;
term._flushBuffer = function() { term._flushBuffer = () => {
term.write(term._attachSocketBuffer); term.write(term._attachSocketBuffer);
term._attachSocketBuffer = null; term._attachSocketBuffer = null;
}; };
term._pushToBuffer = function(data) { term._pushToBuffer = (data: string) => {
if (term._attachSocketBuffer) { if (term._attachSocketBuffer) {
term._attachSocketBuffer += data; term._attachSocketBuffer += data;
} else { } else {
@@ -34,20 +34,19 @@ export function attach(term, socket, bidirectional, buffered) {
} }
}; };
var myTextDecoder; let myTextDecoder;
term._getMessage = function(ev) { term._getMessage = function(ev: MessageEvent): void {
var str; let str;
if (typeof ev.data === "object") { if (typeof ev.data === 'object') {
if (ev.data instanceof ArrayBuffer) { if (ev.data instanceof ArrayBuffer) {
if (!myTextDecoder) { if (!myTextDecoder) {
myTextDecoder = new TextDecoder(); myTextDecoder = new TextDecoder();
} }
str = myTextDecoder.decode( ev.data ); str = myTextDecoder.decode( ev.data );
} } else {
else { throw 'TODO: handle Blob?';
throw "TODO: handle Blob?";
} }
} }
@@ -58,7 +57,7 @@ export function attach(term, socket, bidirectional, buffered) {
} }
}; };
term._sendData = function(data) { term._sendData = (data: string) => {
if (socket.readyState !== 1) { if (socket.readyState !== 1) {
return; return;
} }
@@ -73,7 +72,7 @@ export function attach(term, socket, bidirectional, buffered) {
socket.addEventListener('close', term.detach.bind(term, socket)); socket.addEventListener('close', term.detach.bind(term, socket));
socket.addEventListener('error', term.detach.bind(term, socket)); socket.addEventListener('error', term.detach.bind(term, socket));
}; }
/** /**
* Detaches the given terminal from the given socket * Detaches the given terminal from the given socket
@@ -82,20 +81,20 @@ export function attach(term, socket, bidirectional, buffered) {
* @param {WebSocket} socket - The socket from which to detach the current * @param {WebSocket} socket - The socket from which to detach the current
* terminal. * terminal.
*/ */
export function detach(term, socket) { export function detach(term: any, socket: WebSocket): void {
term.off('data', term._sendData); term.off('data', term._sendData);
socket = (typeof socket == 'undefined') ? term.socket : socket; socket = (typeof socket === 'undefined') ? term.socket : socket;
if (socket) { if (socket) {
socket.removeEventListener('message', term._getMessage); socket.removeEventListener('message', term._getMessage);
} }
delete term.socket; delete term.socket;
}; }
export function apply(terminalConstructor) { export function apply(terminalConstructor: any): void {
/** /**
* Attaches the current terminal to the given socket * Attaches the current terminal to the given socket
* *
@@ -106,8 +105,8 @@ export function apply(terminalConstructor) {
* should happen instantly or at a maximum * should happen instantly or at a maximum
* frequency of 1 rendering per 10ms. * frequency of 1 rendering per 10ms.
*/ */
terminalConstructor.prototype.attach = function(socket, bidirectional, buffered) { terminalConstructor.prototype.attach = function (socket: WebSocket, bidirectional: boolean, buffered: boolean): void {
return attach(this, socket, bidirectional, buffered); attach(this, socket, bidirectional, buffered);
}; };
/** /**
@@ -116,7 +115,7 @@ export function apply(terminalConstructor) {
* @param {WebSocket} socket - The socket from which to detach the current * @param {WebSocket} socket - The socket from which to detach the current
* terminal. * terminal.
*/ */
terminalConstructor.prototype.detach = function(socket) { terminalConstructor.prototype.detach = function (socket: WebSocket): void {
return detach(this, socket); detach(this, socket);
}; };
} }
+1 -1
View File
@@ -5,7 +5,7 @@
import { assert, expect } from 'chai'; import { assert, expect } from 'chai';
import * as fit from './fit' import * as fit from './fit';
class MockTerminal {} class MockTerminal {}
+28 -23
View File
@@ -13,28 +13,33 @@
* row and truncate its width with the current number of columns). * row and truncate its width with the current number of columns).
*/ */
export function proposeGeometry(term) { export interface IGeometry {
rows: number;
cols: number;
}
export function proposeGeometry(term: any): IGeometry {
if (!term.element.parentElement) { if (!term.element.parentElement) {
return null; return null;
} }
var parentElementStyle = window.getComputedStyle(term.element.parentElement); const parentElementStyle = window.getComputedStyle(term.element.parentElement);
var parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')); const parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height'));
var parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')) - 17); const parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')) - 17);
var elementStyle = window.getComputedStyle(term.element); const elementStyle = window.getComputedStyle(term.element);
var elementPaddingVer = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom')); const elementPaddingVer = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom'));
var elementPaddingHor = parseInt(elementStyle.getPropertyValue('padding-right')) + parseInt(elementStyle.getPropertyValue('padding-left')); const elementPaddingHor = parseInt(elementStyle.getPropertyValue('padding-right')) + parseInt(elementStyle.getPropertyValue('padding-left'));
var availableHeight = parentElementHeight - elementPaddingVer; const availableHeight = parentElementHeight - elementPaddingVer;
var availableWidth = parentElementWidth - elementPaddingHor; const availableWidth = parentElementWidth - elementPaddingHor;
var geometry = { const geometry = {
cols: Math.floor(availableWidth / term.renderer.dimensions.actualCellWidth), cols: Math.floor(availableWidth / term.renderer.dimensions.actualCellWidth),
rows: Math.floor(availableHeight / term.renderer.dimensions.actualCellHeight) rows: Math.floor(availableHeight / term.renderer.dimensions.actualCellHeight)
}; };
return geometry; return geometry;
}; }
export function fit(term) { export function fit(term: any): void {
var geometry = proposeGeometry(term); const geometry = proposeGeometry(term);
if (geometry) { if (geometry) {
// Force a full render // Force a full render
if (term.rows !== geometry.rows || term.cols !== geometry.cols) { if (term.rows !== geometry.rows || term.cols !== geometry.cols) {
@@ -42,14 +47,14 @@ export function fit(term) {
term.resize(geometry.cols, geometry.rows); term.resize(geometry.cols, geometry.rows);
} }
} }
}; }
export function apply(terminalConstructor) { export function apply(terminalConstructor: any): void {
terminalConstructor.prototype.proposeGeometry = function() { terminalConstructor.prototype.proposeGeometry = function (): IGeometry {
return proposeGeometry(this); return proposeGeometry(this);
} };
terminalConstructor.prototype.fit = function() { terminalConstructor.prototype.fit = function (): void {
return fit(this); fit(this);
} };
} }
+1 -1
View File
@@ -5,7 +5,7 @@
import { assert, expect } from 'chai'; import { assert, expect } from 'chai';
import * as fullscreen from './fullscreen' import * as fullscreen from './fullscreen';
class MockTerminal {} class MockTerminal {}
+7 -7
View File
@@ -8,10 +8,10 @@
* @param {Terminal} term - The terminal to toggle full screen mode * @param {Terminal} term - The terminal to toggle full screen mode
* @param {boolean} fullscreen - Toggle fullscreen on (true) or off (false) * @param {boolean} fullscreen - Toggle fullscreen on (true) or off (false)
*/ */
export function toggleFullScreen(term, fullscreen) { export function toggleFullScreen(term: any, fullscreen: boolean): void {
var fn; let fn;
if (typeof fullscreen == 'undefined') { if (typeof fullscreen === 'undefined') {
fn = (term.element.classList.contains('fullscreen')) ? 'remove' : 'add'; fn = (term.element.classList.contains('fullscreen')) ? 'remove' : 'add';
} else if (!fullscreen) { } else if (!fullscreen) {
fn = 'remove'; fn = 'remove';
@@ -20,10 +20,10 @@ export function toggleFullScreen(term, fullscreen) {
} }
term.element.classList[fn]('fullscreen'); term.element.classList[fn]('fullscreen');
}; }
export function apply(terminalConstructor) { export function apply(terminalConstructor: any): void {
terminalConstructor.prototype.toggleFullScreen = function (fullscreen) { terminalConstructor.prototype.toggleFullScreen = function (fullscreen: boolean): void {
return toggleFullScreen(this, fullscreen); toggleFullScreen(this, fullscreen);
}; };
} }
+11 -11
View File
@@ -17,7 +17,7 @@ export function findNext(terminal: any, term: string): boolean {
terminal.searchHelper = new SearchHelper(terminal); terminal.searchHelper = new SearchHelper(terminal);
} }
return (<SearchHelper>terminal.searchHelper).findNext(term); return (<SearchHelper>terminal.searchHelper).findNext(term);
}; }
/** /**
* Find the previous instance of the term, then scroll to and select it. If it * Find the previous instance of the term, then scroll to and select it. If it
@@ -30,14 +30,14 @@ export function findPrevious(terminal: any, term: string): boolean {
terminal.searchHelper = new SearchHelper(terminal); terminal.searchHelper = new SearchHelper(terminal);
} }
return (<SearchHelper>terminal.searchHelper).findPrevious(term); return (<SearchHelper>terminal.searchHelper).findPrevious(term);
}; }
export function apply(terminalConstructor) { export function apply(terminalConstructor: any): void {
terminalConstructor.prototype.findNext = function(term) { terminalConstructor.prototype.findNext = function(term: any): boolean {
return findNext(this, term); return findNext(this, term);
} };
terminalConstructor.prototype.findPrevious = function(term) { terminalConstructor.prototype.findPrevious = function(term: any): boolean {
return findPrevious(this, term); return findPrevious(this, term);
} };
} }
+1 -1
View File
@@ -5,7 +5,7 @@
import { assert, expect } from 'chai'; import { assert, expect } from 'chai';
import * as terminado from './terminado' import * as terminado from './terminado';
class MockTerminal {} class MockTerminal {}
+16 -16
View File
@@ -17,16 +17,16 @@
* should happen instantly or at a maximum * should happen instantly or at a maximum
* frequency of 1 rendering per 10ms. * frequency of 1 rendering per 10ms.
*/ */
export function terminadoAttach(term, socket, bidirectional, buffered) { export function terminadoAttach(term: any, socket: WebSocket, bidirectional: boolean, buffered: boolean): void {
bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional; bidirectional = (typeof bidirectional === 'undefined') ? true : bidirectional;
term.socket = socket; term.socket = socket;
term._flushBuffer = function() { term._flushBuffer = () => {
term.write(term._attachSocketBuffer); term.write(term._attachSocketBuffer);
term._attachSocketBuffer = null; term._attachSocketBuffer = null;
}; };
term._pushToBuffer = function(data) { term._pushToBuffer = (data) => {
if (term._attachSocketBuffer) { if (term._attachSocketBuffer) {
term._attachSocketBuffer += data; term._attachSocketBuffer += data;
} else { } else {
@@ -35,9 +35,9 @@ export function terminadoAttach(term, socket, bidirectional, buffered) {
} }
}; };
term._getMessage = function(ev) { term._getMessage = (ev: MessageEvent) => {
var data = JSON.parse(ev.data) const data = JSON.parse(ev.data);
if( data[0] == "stdout" ) { if (data[0] === 'stdout') {
if (buffered) { if (buffered) {
term._pushToBuffer(data[1]); term._pushToBuffer(data[1]);
} else { } else {
@@ -46,11 +46,11 @@ export function terminadoAttach(term, socket, bidirectional, buffered) {
} }
}; };
term._sendData = function(data) { term._sendData = (data: string) => {
socket.send(JSON.stringify(['stdin', data])); socket.send(JSON.stringify(['stdin', data]));
}; };
term._setSize = function(size) { term._setSize = (size: {rows: number, cols: number}) => {
socket.send(JSON.stringify(['set_size', size.rows, size.cols])); socket.send(JSON.stringify(['set_size', size.rows, size.cols]));
}; };
@@ -63,7 +63,7 @@ export function terminadoAttach(term, socket, bidirectional, buffered) {
socket.addEventListener('close', term.terminadoDetach.bind(term, socket)); socket.addEventListener('close', term.terminadoDetach.bind(term, socket));
socket.addEventListener('error', term.terminadoDetach.bind(term, socket)); socket.addEventListener('error', term.terminadoDetach.bind(term, socket));
}; }
/** /**
* Detaches the given terminal from the given socket * Detaches the given terminal from the given socket
@@ -72,19 +72,19 @@ export function terminadoAttach(term, socket, bidirectional, buffered) {
* @param {WebSocket} socket - The socket from which to detach the current * @param {WebSocket} socket - The socket from which to detach the current
* terminal. * terminal.
*/ */
export function terminadoDetach(term, socket) { export function terminadoDetach(term: any, socket: WebSocket): void {
term.off('data', term._sendData); term.off('data', term._sendData);
socket = (typeof socket == 'undefined') ? term.socket : socket; socket = (typeof socket === 'undefined') ? term.socket : socket;
if (socket) { if (socket) {
socket.removeEventListener('message', term._getMessage); socket.removeEventListener('message', term._getMessage);
} }
delete term.socket; delete term.socket;
}; }
export function apply(terminalConstructor) { export function apply(terminalConstructor: any): void {
/** /**
* Attaches the current terminal to the given socket * Attaches the current terminal to the given socket
* *
@@ -95,7 +95,7 @@ export function apply(terminalConstructor) {
* should happen instantly or at a maximum * should happen instantly or at a maximum
* frequency of 1 rendering per 10ms. * frequency of 1 rendering per 10ms.
*/ */
terminalConstructor.prototype.terminadoAttach = function(socket, bidirectional, buffered) { terminalConstructor.prototype.terminadoAttach = function(socket: WebSocket, bidirectional: boolean, buffered: boolean): void {
return terminadoAttach(this, socket, bidirectional, buffered); return terminadoAttach(this, socket, bidirectional, buffered);
}; };
@@ -105,7 +105,7 @@ export function apply(terminalConstructor) {
* @param {WebSocket} socket - The socket from which to detach the current * @param {WebSocket} socket - The socket from which to detach the current
* terminal. * terminal.
*/ */
terminalConstructor.prototype.terminadoDetach = function(socket) { terminalConstructor.prototype.terminadoDetach = function(socket: WebSocket): void {
return terminadoDetach(this, socket); return terminadoDetach(this, socket);
}; };
} }
+1 -1
View File
@@ -5,7 +5,7 @@
import { assert, expect } from 'chai'; import { assert, expect } from 'chai';
import * as winptyCompat from './winptyCompat' import * as winptyCompat from './winptyCompat';
class MockTerminal {} class MockTerminal {}
+2 -2
View File
@@ -3,7 +3,7 @@
* @license MIT * @license MIT
*/ */
export function winptyCompatInit(terminal): void { export function winptyCompatInit(terminal: any): void {
// Don't do anything when the platform is not Windows // Don't do anything when the platform is not Windows
const isWindows = ['Windows', 'Win16', 'Win32', 'WinCE'].indexOf(navigator.platform) >= 0; const isWindows = ['Windows', 'Win16', 'Win32', 'WinCE'].indexOf(navigator.platform) >= 0;
if (!isWindows) { if (!isWindows) {
@@ -31,7 +31,7 @@ export function winptyCompatInit(terminal): void {
}); });
} }
export function apply(terminalConstructor) { export function apply(terminalConstructor: any): void {
terminalConstructor.prototype.winptyCompatInit = function(): void { terminalConstructor.prototype.winptyCompatInit = function(): void {
winptyCompatInit(this); winptyCompatInit(this);
}; };
+1 -1
View File
@@ -5,7 +5,7 @@
import { assert, expect } from 'chai'; import { assert, expect } from 'chai';
import * as zmodem from './zmodem' import * as zmodem from './zmodem';
class MockTerminal {} class MockTerminal {}
+21 -28
View File
@@ -27,47 +27,40 @@
* via `detach()` and a re-`attach()`.) * via `detach()` and a re-`attach()`.)
*/ */
let Zmodem; let zmodem;
export function zmodemAttach(term, ws, opts) { export interface IZModemOptions {
if (!opts) opts = {}; noTerminalWriteOutsideSession?: boolean;
}
var senderFunc = function _ws_sender_func(octets) { export function zmodemAttach(term: any, ws: WebSocket, opts: IZModemOptions = {}): void {
ws.send(new Uint8Array(octets)); const senderFunc = (octets: ArrayLike<number>) => ws.send(new Uint8Array(octets));
};
var zsentry; let zsentry;
function _shouldWrite() { function _shouldWrite(): boolean {
return !!zsentry.get_confirmed_session() || !opts.noTerminalWriteOutsideSession; return !!zsentry.get_confirmed_session() || !opts.noTerminalWriteOutsideSession;
} }
zsentry = new Zmodem.Sentry( { zsentry = new zmodem.Sentry({
to_terminal: function _to_terminal(octets) { to_terminal: (octets: ArrayLike<number>) => {
if (_shouldWrite()) { if (_shouldWrite()) {
term.write( term.write(
String.fromCharCode.apply(String, octets) String.fromCharCode.apply(String, octets)
); );
} }
}, },
sender: senderFunc, sender: senderFunc,
on_retract: () => term.emit('zmodemRetract'),
on_detect: (detection: any) => term.emit('zmodemDetect', detection)
});
on_retract: function _on_retract() { function handleWSMessage(evt: MessageEvent): void {
term.emit('zmodemRetract');
},
on_detect: function _on_detect(detection) { // In testing with xterm.js’s demo the first message was
term.emit('zmodemDetect', detection); // always text even if the rest were binary. While that
}, // may be specific to xterm.js’s demo, ultimately we
} ); // should reject anything that isn’t binary.
function handleWSMessage(evt) {
//In testing with xterm.js’s demo the first message was
//always text even if the rest were binary. While that
//may be specific to xterm.js’s demo, ultimately we
//should reject anything that isn’t binary.
if (typeof evt.data === 'string') { if (typeof evt.data === 'string') {
if (_shouldWrite()) { if (_shouldWrite()) {
term.write(evt.data); term.write(evt.data);
@@ -82,9 +75,9 @@ export function zmodemAttach(term, ws, opts) {
ws.addEventListener('message', handleWSMessage); ws.addEventListener('message', handleWSMessage);
} }
export function apply(terminalConstructor) { export function apply(terminalConstructor: any): void {
Zmodem = (typeof window == 'object') ? (<any>window).ZModem : {Browser: null}; // Nullify browser for tests zmodem = (typeof window === 'object') ? (<any>window).ZModem : {Browser: null}; // Nullify browser for tests
terminalConstructor.prototype.zmodemAttach = zmodemAttach.bind(this, this); terminalConstructor.prototype.zmodemAttach = zmodemAttach.bind(this, this);
terminalConstructor.prototype.zmodemBrowser = Zmodem.Browser terminalConstructor.prototype.zmodemBrowser = zmodem.Browser;
} }
+1 -1
View File
@@ -178,7 +178,7 @@ export class MouseZoneManager implements IMouseZoneManager {
if (zone.y === coords[1] && zone.x1 <= coords[0] && zone.x2 > coords[0]) { if (zone.y === coords[1] && zone.x1 <= coords[0] && zone.x2 > coords[0]) {
return zone; return zone;
} }
}; }
return null; return null;
} }
} }
+2 -2
View File
@@ -11,7 +11,7 @@ import { FLAGS } from './Types';
import { BaseRenderLayer } from './BaseRenderLayer'; import { BaseRenderLayer } from './BaseRenderLayer';
import { CharData } from '../Types'; import { CharData } from '../Types';
interface CursorState { interface ICursorState {
x: number; x: number;
y: number; y: number;
isFocused: boolean; isFocused: boolean;
@@ -25,7 +25,7 @@ interface CursorState {
const BLINK_INTERVAL = 600; const BLINK_INTERVAL = 600;
export class CursorRenderLayer extends BaseRenderLayer { export class CursorRenderLayer extends BaseRenderLayer {
private _state: CursorState; private _state: ICursorState;
private _cursorRenderers: {[key: string]: (terminal: ITerminal, x: number, y: number, charData: CharData) => void}; private _cursorRenderers: {[key: string]: (terminal: ITerminal, x: number, y: number, charData: CharData) => void};
private _cursorBlinkStateManager: CursorBlinkStateManager; private _cursorBlinkStateManager: CursorBlinkStateManager;
private _isFocused: boolean; private _isFocused: boolean;
+7 -7
View File
@@ -4,20 +4,20 @@
*/ */
import { IColorSet, IRenderDimensions } from './Interfaces'; import { IColorSet, IRenderDimensions } from './Interfaces';
import { IBuffer, ICharMeasure, ITerminal, ILinkifierAccessor } from '../Interfaces'; import { IBuffer, ICharMeasure, ILinkHoverEvent, ITerminal, ILinkifierAccessor } from '../Interfaces';
import { CHAR_DATA_ATTR_INDEX } from '../Buffer'; import { CHAR_DATA_ATTR_INDEX } from '../Buffer';
import { GridCache } from './GridCache'; import { GridCache } from './GridCache';
import { FLAGS } from './Types'; import { FLAGS } from './Types';
import { BaseRenderLayer, INVERTED_DEFAULT_COLOR } from './BaseRenderLayer'; import { BaseRenderLayer, INVERTED_DEFAULT_COLOR } from './BaseRenderLayer';
import { LinkHoverEvent, LinkHoverEventTypes } from '../Types'; import { LinkHoverEventTypes } from '../Types';
export class LinkRenderLayer extends BaseRenderLayer { export class LinkRenderLayer extends BaseRenderLayer {
private _state: LinkHoverEvent = null; private _state: ILinkHoverEvent = null;
constructor(container: HTMLElement, zIndex: number, colors: IColorSet, terminal: ILinkifierAccessor) { constructor(container: HTMLElement, zIndex: number, colors: IColorSet, terminal: ILinkifierAccessor) {
super(container, 'link', zIndex, true, colors); super(container, 'link', zIndex, true, colors);
terminal.linkifier.on(LinkHoverEventTypes.HOVER, (e: LinkHoverEvent) => this._onLinkHover(e)); terminal.linkifier.on(LinkHoverEventTypes.HOVER, (e: ILinkHoverEvent) => this._onLinkHover(e));
terminal.linkifier.on(LinkHoverEventTypes.LEAVE, (e: LinkHoverEvent) => this._onLinkLeave(e)); terminal.linkifier.on(LinkHoverEventTypes.LEAVE, (e: ILinkHoverEvent) => this._onLinkLeave(e));
} }
public resize(terminal: ITerminal, dim: IRenderDimensions, charSizeChanged: boolean): void { public resize(terminal: ITerminal, dim: IRenderDimensions, charSizeChanged: boolean): void {
@@ -37,13 +37,13 @@ export class LinkRenderLayer extends BaseRenderLayer {
} }
} }
private _onLinkHover(e: LinkHoverEvent): void { private _onLinkHover(e: ILinkHoverEvent): void {
this._ctx.fillStyle = this._colors.foreground; this._ctx.fillStyle = this._colors.foreground;
this.fillBottomLineAtCells(e.x, e.y, e.length); this.fillBottomLineAtCells(e.x, e.y, e.length);
this._state = e; this._state = e;
} }
private _onLinkLeave(e: LinkHoverEvent): void { private _onLinkLeave(e: ILinkHoverEvent): void {
this._clearCurrentLink(); this._clearCurrentLink();
} }
} }
+3 -3
View File
@@ -192,9 +192,9 @@ export class TextRenderLayer extends BaseRenderLayer {
} }
} }
/** /**
* Whether a character is overlapping to the next cell. * Whether a character is overlapping to the next cell.
*/ */
private _isOverlapping(charData: CharData): boolean { private _isOverlapping(charData: CharData): boolean {
// Only single cell characters can be overlapping, rendering issues can // Only single cell characters can be overlapping, rendering issues can
// occur without this check // occur without this check
+1 -1
View File
@@ -13,4 +13,4 @@ export enum FLAGS {
INVERSE = 8, INVERSE = 8,
INVISIBLE = 16, INVISIBLE = 16,
DIM = 32 DIM = 32
}; }
+1 -1
View File
@@ -10,4 +10,4 @@
*/ */
export function contains(arr: any[], el: any): boolean { export function contains(arr: any[], el: any): boolean {
return arr.indexOf(el) >= 0; return arr.indexOf(el) >= 0;
}; }
+1 -1
View File
@@ -7,4 +7,4 @@
// This sound is released under the Creative Commons Attribution 3.0 Unported // This sound is released under the Creative Commons Attribution 3.0 Unported
// (CC BY 3.0) license. It was created by 'altemark'. No modifications have been // (CC BY 3.0) license. It was created by 'altemark'. No modifications have been
// made, apart from the conversion to base64. // made, apart from the conversion to base64.
export const BellSound = 'data:audio/wav;base64,UklGRigBAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQQBAADpAFgCwAMlBZoG/wdmCcoKRAypDQ8PbRDBEQQTOxRtFYcWlBePGIUZXhoiG88bcBz7HHIdzh0WHlMeZx51HmkeUx4WHs8dah0AHXwc3hs9G4saxRnyGBIYGBcQFv8U4RPAEoYRQBACD70NWwwHC6gJOwjWBloF7gOBAhABkf8b/qv8R/ve+Xf4Ife79W/0JfPZ8Z/wde9N7ijtE+wU6xvqM+lb6H7nw+YX5mrlxuQz5Mzje+Ma49fioeKD4nXiYeJy4pHitOL04j/jn+MN5IPkFOWs5U3mDefM55/ogOl36m7rdOyE7abuyu8D8Unyj/Pg9D/2qfcb+Yn6/vuK/Qj/lAAlAg=='; export const BELL_SOUND = 'data:audio/wav;base64,UklGRigBAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQQBAADpAFgCwAMlBZoG/wdmCcoKRAypDQ8PbRDBEQQTOxRtFYcWlBePGIUZXhoiG88bcBz7HHIdzh0WHlMeZx51HmkeUx4WHs8dah0AHXwc3hs9G4saxRnyGBIYGBcQFv8U4RPAEoYRQBACD70NWwwHC6gJOwjWBloF7gOBAhABkf8b/qv8R/ve+Xf4Ife79W/0JfPZ8Z/wde9N7ijtE+wU6xvqM+lb6H7nw+YX5mrlxuQz5Mzje+Ma49fioeKD4nXiYeJy4pHitOL04j/jn+MN5IPkFOWs5U3mDefM55/ogOl36m7rdOyE7abuyu8D8Unyj/Pg9D/2qfcb+Yn6/vuK/Qj/lAAlAg==';
+18 -6
View File
@@ -1,5 +1,9 @@
{ {
"rules": { "rules": {
"array-type": [
true,
"array"
],
"class-name": true, "class-name": true,
"comment-format": [ "comment-format": [
true, true,
@@ -9,6 +13,11 @@
true, true,
"spaces" "spaces"
], ],
"interface-name": [
true,
"always-prefix"
],
"interface-over-type-literal": true,
"typedef": [ "typedef": [
true, true,
"call-signature", "call-signature",
@@ -18,10 +27,7 @@
"no-eval": true, "no-eval": true,
"no-internal-module": true, "no-internal-module": true,
"no-trailing-whitespace": true, "no-trailing-whitespace": true,
"one-variable-per-declaration": [ "one-variable-per-declaration": true,
true,
true
],
"no-unsafe-finally": true, "no-unsafe-finally": true,
"no-var-keyword": true, "no-var-keyword": true,
"quotemark": [ "quotemark": [
@@ -48,15 +54,21 @@
], ],
"variable-name": [ "variable-name": [
true, true,
"ban-keywords" "ban-keywords",
"check-format",
"allow-leading-underscore"
], ],
"whitespace": [ "whitespace": [
true, true,
"check-branch", "check-branch",
"check-decl", "check-decl",
"check-module",
"check-operator", "check-operator",
"check-rest-spread",
"check-separator", "check-separator",
"check-type" "check-type",
"check-type-operator",
"check-preblock"
] ]
} }
} }