From 4443ed69c7947d3623b7eafc0faa7fb06c523399 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 8 Mar 2018 10:56:10 -0800 Subject: [PATCH 1/4] Add noUnusedLocals tsconfig flag, fix issues Two parts were commented out: - _writeStopped: This is because _xoffSentToCatchUp references this variable and the feature is sort of half implemented/disabled. - _clearChar: This is because some comments still reference this, it's part of the work needed to do better line redrawing. --- package-lock.json | 2 +- src/AccessibilityManager.ts | 2 -- src/InputHandler.ts | 2 +- src/Linkifier.test.ts | 13 +--------- src/Linkifier.ts | 5 +--- src/Parser.ts | 5 ++-- src/SelectionManager.test.ts | 5 +--- src/SelectionManager.ts | 3 +-- src/SelectionModel.test.ts | 3 --- src/Terminal.ts | 39 +++++++--------------------- src/Types.ts | 3 ++- src/handlers/AltClickHandler.ts | 3 --- src/handlers/Clipboard.test.ts | 1 - src/renderer/BaseRenderLayer.ts | 4 +-- src/renderer/CursorRenderLayer.ts | 8 +++--- src/renderer/LinkRenderLayer.ts | 7 ++--- src/renderer/Renderer.ts | 2 -- src/renderer/SelectionRenderLayer.ts | 6 ++--- src/renderer/TextRenderLayer.ts | 22 ++++++++-------- src/renderer/atlas/CharAtlas.ts | 1 - src/renderer/atlas/CharAtlasUtils.ts | 1 - src/utils/CharMeasure.test.ts | 2 +- src/utils/CharMeasure.ts | 2 +- src/utils/CircularList.test.ts | 4 --- src/utils/CircularList.ts | 1 - src/utils/TestUtils.test.ts | 3 +++ tsconfig.json | 3 ++- 27 files changed, 46 insertions(+), 106 deletions(-) diff --git a/package-lock.json b/package-lock.json index 03bbd115..59522f3d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "xterm", - "version": "3.1.0-master", + "version": "3.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/AccessibilityManager.ts b/src/AccessibilityManager.ts index cb915516..67031cb7 100644 --- a/src/AccessibilityManager.ts +++ b/src/AccessibilityManager.ts @@ -11,7 +11,6 @@ import { addDisposableListener } from './utils/Dom'; import { IDisposable } from 'xterm'; const MAX_ROWS_TO_READ = 20; -const ACTIVE_ITEM_ID_PREFIX = 'xterm-active-item-'; enum BoundaryPosition { Top, @@ -265,7 +264,6 @@ export class AccessibilityManager implements IDisposable { if (!this._terminal.renderer.dimensions.actualCellHeight) { return; } - const buffer: IBuffer = this._terminal.buffer; for (let i = 0; i < this._terminal.rows; i++) { this._refreshRowDimensions(this._rowElements[i]); } diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 18338ae7..acf7af1f 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -4,7 +4,7 @@ * @license MIT */ -import { CharData, IInputHandler, IInputHandlingTerminal, ITerminal } from './Types'; +import { CharData, IInputHandler, IInputHandlingTerminal } from './Types'; import { C0 } from './EscapeSequences'; import { DEFAULT_CHARSET } from './Charsets'; import { CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX } from './Buffer'; diff --git a/src/Linkifier.test.ts b/src/Linkifier.test.ts index ce1635a3..1aaf02c9 100644 --- a/src/Linkifier.test.ts +++ b/src/Linkifier.test.ts @@ -5,7 +5,7 @@ import { assert } from 'chai'; import { IMouseZoneManager, IMouseZone } from './input/Types'; -import { ILinkMatcher, LineData, ITerminal, ILinkifier, IBuffer, IBufferAccessor, IElementAccessor } from './Types'; +import { ILinkMatcher, LineData, IBufferAccessor, IElementAccessor } from './Types'; import { Linkifier } from './Linkifier'; import { MockBuffer } from './utils/TestUtils.test'; import { CircularList } from './utils/CircularList'; @@ -59,17 +59,6 @@ describe('Linkifier', () => { terminal.buffer.lines.push(stringToRow(text)); } - function assertLinkifiesEntireRow(uri: string, done: MochaDone): void { - addRow(uri); - linkifier.linkifyRows(); - setTimeout(() => { - assert.equal(mouseZoneManager.zones[0].x1, 1); - assert.equal(mouseZoneManager.zones[0].x2, uri.length + 1); - assert.equal(mouseZoneManager.zones[0].y, terminal.buffer.lines.length); - done(); - }, 0); - } - function assertLinkifiesRow(rowText: string, linkMatcherRegex: RegExp, links: {x: number, length: number}[], done: MochaDone): void { addRow(rowText); linkifier.registerLinkMatcher(linkMatcherRegex, () => {}); diff --git a/src/Linkifier.ts b/src/Linkifier.ts index 92a6ca9f..8dc27cc2 100644 --- a/src/Linkifier.ts +++ b/src/Linkifier.ts @@ -4,7 +4,7 @@ */ import { IMouseZoneManager } from './input/Types'; -import { ILinkHoverEvent, ILinkMatcher, LinkMatcherHandler, LinkMatcherValidationCallback, LineData, LinkHoverEventTypes, ILinkMatcherOptions, ITerminal, IBufferAccessor, ILinkifier, IElementAccessor } from './Types'; +import { ILinkHoverEvent, ILinkMatcher, LinkMatcherHandler, LinkHoverEventTypes, ILinkMatcherOptions, IBufferAccessor, ILinkifier, IElementAccessor } from './Types'; import { MouseZone } from './input/MouseZoneManager'; import { EventEmitter } from './EventEmitter'; @@ -177,9 +177,6 @@ export class Linkifier extends EventEmitter implements ILinkifier { * @return The link element(s) that were added. */ private _doLinkifyRow(rowIndex: number, text: string, matcher: ILinkMatcher, offset: number = 0): void { - // Iterate over nodes as we want to consider text nodes - let result = []; - // Find the first match let match = text.match(matcher.regex); if (!match || match.length === 0) { diff --git a/src/Parser.ts b/src/Parser.ts index 03b4a39e..21e5a612 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -5,7 +5,7 @@ */ import { C0 } from './EscapeSequences'; -import { IInputHandler } from './Types'; +import { IInputHandler, IInputHandlingTerminal } from './Types'; import { CHARSETS, DEFAULT_CHARSET } from './Charsets'; const normalStateHandler: {[key: string]: (parser: Parser, handler: IInputHandler) => void} = {}; @@ -185,7 +185,6 @@ export class Parser { */ public parse(data: string): ParserState { const l = data.length; - let j; let cs; let ch; let code; @@ -346,7 +345,7 @@ export class Parser { // ESC H Tab Set (HTS is 0x88). case 'H': - this._terminal.tabSet(); + (this._terminal).tabSet(); this._state = ParserState.NORMAL; break; diff --git a/src/SelectionManager.test.ts b/src/SelectionManager.test.ts index a76947e5..4738bc02 100644 --- a/src/SelectionManager.test.ts +++ b/src/SelectionManager.test.ts @@ -6,11 +6,10 @@ import jsdom = require('jsdom'); import { assert } from 'chai'; import { CharMeasure } from './utils/CharMeasure'; -import { CircularList } from './utils/CircularList'; import { SelectionManager } from './SelectionManager'; import { SelectionModel } from './SelectionModel'; import { BufferSet } from './BufferSet'; -import { LineData, CharData, ITerminal, ICircularList, IBuffer } from './Types'; +import { LineData, CharData, ITerminal, IBuffer } from './Types'; import { MockTerminal } from './utils/TestUtils.test'; class TestMockTerminal extends MockTerminal { @@ -39,11 +38,9 @@ class TestSelectionManager extends SelectionManager { describe('SelectionManager', () => { let dom: jsdom.JSDOM; let window: Window; - let document: Document; let terminal: ITerminal; let buffer: IBuffer; - let rowContainer: HTMLElement; let selectionManager: TestSelectionManager; beforeEach(() => { diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index 93957fa8..506e87d4 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -3,11 +3,10 @@ * @license MIT */ -import { ITerminal, ICircularList, ISelectionManager, IBuffer, LineData, CharData, XtermListener } from './Types'; +import { ITerminal, ISelectionManager, IBuffer, CharData, XtermListener } from './Types'; import { MouseHelper } from './utils/MouseHelper'; import * as Browser from './shared/utils/Browser'; import { CharMeasure } from './utils/CharMeasure'; -import { CircularList } from './utils/CircularList'; import { EventEmitter } from './EventEmitter'; import { SelectionModel } from './SelectionModel'; import { CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX } from './Buffer'; diff --git a/src/SelectionModel.test.ts b/src/SelectionModel.test.ts index ed483dbe..85486bab 100644 --- a/src/SelectionModel.test.ts +++ b/src/SelectionModel.test.ts @@ -18,9 +18,6 @@ class TestSelectionModel extends SelectionModel { } describe('SelectionManager', () => { - let window: Window; - let document: Document; - let terminal: ITerminal; let model: TestSelectionModel; diff --git a/src/Terminal.ts b/src/Terminal.ts index 735711d0..924260ca 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -21,7 +21,7 @@ * http://linux.die.net/man/7/urxvt */ -import { ICharset, IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminalOptions, ITerminal, IBrowser, ILinkifier, ILinkMatcherOptions, CustomKeyEventHandler, LinkMatcherHandler, LinkMatcherValidationCallback, CharData, LineData } from './Types'; +import { ICharset, IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminalOptions, ITerminal, IBrowser, ILinkifier, ILinkMatcherOptions, CustomKeyEventHandler, LinkMatcherHandler, CharData, LineData } from './Types'; import { IMouseZoneManager } from './input/Types'; import { IRenderer } from './renderer/Types'; import { BufferSet } from './BufferSet'; @@ -30,7 +30,6 @@ import { CompositionHelper } from './CompositionHelper'; import { EventEmitter } from './EventEmitter'; import { Viewport } from './Viewport'; import { rightClickHandler, moveTextAreaUnderMouseCursor, pasteHandler, copyHandler } from './handlers/Clipboard'; -import { CircularList } from './utils/CircularList'; import { C0 } from './EscapeSequences'; import { InputHandler } from './InputHandler'; import { Parser } from './Parser'; @@ -41,7 +40,6 @@ import { CharMeasure } from './utils/CharMeasure'; import * as Browser from './shared/utils/Browser'; import * as Strings from './Strings'; import { MouseHelper } from './utils/MouseHelper'; -import { CHARSETS } from './Charsets'; import { DEFAULT_BELL_SOUND, SoundManager } from './SoundManager'; import { DEFAULT_ANSI_COLORS } from './renderer/ColorManager'; import { MouseZoneManager } from './input/MouseZoneManager'; @@ -136,7 +134,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT private _parent: HTMLElement; private _context: Window; private _document: Document; - private _body: HTMLBodyElement; private _viewportScrollArea: HTMLElement; private _viewportElement: HTMLElement; private _helperContainer: HTMLElement; @@ -148,7 +145,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT public browser: IBrowser = Browser; 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 public cursorState: number; @@ -190,10 +186,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT private _refreshEnd: number; public savedCols: number; - // stream - private _readable: boolean; - private _writable: boolean; - public defAttr: number; public curAttr: number; @@ -215,10 +207,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT private _xoffSentToCatchUp: boolean; /** Whether writing has been stopped as a result of XOFF */ - private _writeStopped: boolean; - - // leftover surrogate high from previous write invocation - private _surrogateHigh: string; + // private _writeStopped: boolean; // Store if user went browsing history in scrollback private _userScrolling: boolean; @@ -302,9 +291,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT // TODO: Can this be just []? this.charsets = [null]; - this._readable = true; - this._writable = true; - this.defAttr = (0 << 18) | (257 << 9) | (256 << 0); this.curAttr = (0 << 18) | (257 << 9) | (256 << 0); @@ -318,8 +304,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this._writeInProgress = false; this._xoffSentToCatchUp = false; - this._writeStopped = false; - this._surrogateHigh = ''; + // this._writeStopped = false; this._userScrolling = false; this._inputHandler = new InputHandler(this); @@ -622,9 +607,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT * @param {HTMLElement} parent The element to create the terminal within. */ public open(parent: HTMLElement): void { - let i = 0; - let div; - this._parent = parent || this._parent; if (!this._parent) { @@ -634,7 +616,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT // Grab global elements this._context = this._parent.ownerDocument.defaultView; this._document = this._parent.ownerDocument; - this._body = this._document.body; this._screenDprMonitor = new ScreenDprMonitor(); this._screenDprMonitor.setListener(() => this.emit('dprchange', window.devicePixelRatio)); @@ -1104,8 +1085,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT */ public destroy(): void { super.destroy(); - this._readable = false; - this._writable = false; this.handler = () => {}; this.write = () => {}; if (this.element && this.element.parentNode) { @@ -1423,11 +1402,11 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT const result = this._evaluateKeyEscapeSequence(ev); - if (result.key === C0.DC3) { // XOFF - this._writeStopped = true; - } else if (result.key === C0.DC1) { // XON - this._writeStopped = false; - } + // if (result.key === C0.DC3) { // XOFF + // this._writeStopped = true; + // } else if (result.key === C0.DC1) { // XON + // this._writeStopped = false; + // } if (result.scrollLines) { this.scrollLines(result.scrollLines); @@ -2167,7 +2146,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT /** * ESC H Tab Set (HTS is 0x88). */ - private tabSet(): void { + public tabSet(): void { this.buffer.tabs[this.buffer.x] = true; } diff --git a/src/Types.ts b/src/Types.ts index 2751d266..8f0cf380 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { Terminal as PublicTerminal, ITerminalOptions as IPublicTerminalOptions, IEventEmitter as IPublicEventEmitter, IEventEmitter } from 'xterm'; +import { Terminal as PublicTerminal, ITerminalOptions as IPublicTerminalOptions, IEventEmitter } from 'xterm'; import { IColorSet, IRenderer } from './renderer/Types'; import { IMouseZoneManager } from './input/Types'; @@ -84,6 +84,7 @@ export interface IInputHandlingTerminal extends IEventEmitter { matchColor(r1: number, g1: number, b1: number): number; error(text: string, data?: any): void; setOption(key: string, value: any): void; + tabSet(): void; } export interface IViewport { diff --git a/src/handlers/AltClickHandler.ts b/src/handlers/AltClickHandler.ts index 7af32ee6..f77637ea 100644 --- a/src/handlers/AltClickHandler.ts +++ b/src/handlers/AltClickHandler.ts @@ -71,9 +71,6 @@ export class AltClickHandler { * positioning. */ private _resetStartingRow(): string { - let startRow = this._endRow - this._wrappedRowsForRow(this._endRow); - let endRow = this._endRow; - if (this._moveToRequestedRow().length === 0) { return ''; } else { diff --git a/src/handlers/Clipboard.test.ts b/src/handlers/Clipboard.test.ts index 174f6efb..07c0f66e 100644 --- a/src/handlers/Clipboard.test.ts +++ b/src/handlers/Clipboard.test.ts @@ -4,7 +4,6 @@ */ import { assert } from 'chai'; -import * as Terminal from '../Terminal'; import * as Clipboard from './Clipboard'; describe('evaluatePastedTextProcessing', () => { diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index 4d626e4b..281b3ee9 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -4,11 +4,11 @@ */ import { IRenderLayer, IColorSet, IRenderDimensions } from './Types'; -import { CharData, ITerminal, ITerminalOptions } from '../Types'; +import { CharData, ITerminal } from '../Types'; import { DIM_OPACITY, INVERTED_DEFAULT_COLOR } from './atlas/Types'; import { CHAR_ATLAS_CELL_SPACING } from '../shared/atlas/Types'; import { acquireCharAtlas } from './atlas/CharAtlas'; -import { CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX } from '../Buffer'; +import { CHAR_DATA_CHAR_INDEX } from '../Buffer'; export abstract class BaseRenderLayer implements IRenderLayer { private _canvas: HTMLCanvasElement; diff --git a/src/renderer/CursorRenderLayer.ts b/src/renderer/CursorRenderLayer.ts index 691f17d8..bfd215ad 100644 --- a/src/renderer/CursorRenderLayer.ts +++ b/src/renderer/CursorRenderLayer.ts @@ -3,11 +3,10 @@ * @license MIT */ -import { CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CODE_INDEX, CHAR_DATA_CHAR_INDEX } from '../Buffer'; -import { GridCache } from './GridCache'; -import { FLAGS, IColorSet, IRenderDimensions } from './Types'; +import { CHAR_DATA_WIDTH_INDEX } from '../Buffer'; +import { IColorSet, IRenderDimensions } from './Types'; import { BaseRenderLayer } from './BaseRenderLayer'; -import { CharData, IBuffer, ICharMeasure, ITerminal, ITerminalOptions } from '../Types'; +import { CharData, ITerminal } from '../Types'; interface ICursorState { x: number; @@ -26,7 +25,6 @@ export class CursorRenderLayer extends BaseRenderLayer { private _state: ICursorState; private _cursorRenderers: {[key: string]: (terminal: ITerminal, x: number, y: number, charData: CharData) => void}; private _cursorBlinkStateManager: CursorBlinkStateManager; - private _isFocused: boolean; constructor(container: HTMLElement, zIndex: number, colors: IColorSet) { super(container, 'cursor', zIndex, true, colors); diff --git a/src/renderer/LinkRenderLayer.ts b/src/renderer/LinkRenderLayer.ts index 10a33d11..f94a47f8 100644 --- a/src/renderer/LinkRenderLayer.ts +++ b/src/renderer/LinkRenderLayer.ts @@ -3,11 +3,8 @@ * @license MIT */ -import { ILinkHoverEvent, ITerminal, ILinkifierAccessor, IBuffer, ICharMeasure, LinkHoverEventTypes } from '../Types'; -import { CHAR_DATA_ATTR_INDEX } from '../Buffer'; -import { GridCache } from './GridCache'; -import { FLAGS, IColorSet, IRenderDimensions } from './Types'; -import { INVERTED_DEFAULT_COLOR } from './atlas/Types'; +import { ILinkHoverEvent, ITerminal, ILinkifierAccessor, LinkHoverEventTypes } from '../Types'; +import { IColorSet, IRenderDimensions } from './Types'; import { BaseRenderLayer } from './BaseRenderLayer'; export class LinkRenderLayer extends BaseRenderLayer { diff --git a/src/renderer/Renderer.ts b/src/renderer/Renderer.ts index db639c66..1ce2c9b4 100644 --- a/src/renderer/Renderer.ts +++ b/src/renderer/Renderer.ts @@ -3,12 +3,10 @@ * @license MIT */ -import { CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX } from '../Buffer'; import { TextRenderLayer } from './TextRenderLayer'; import { SelectionRenderLayer } from './SelectionRenderLayer'; import { CursorRenderLayer } from './CursorRenderLayer'; import { ColorManager } from './ColorManager'; -import { BaseRenderLayer } from './BaseRenderLayer'; import { IRenderLayer, IColorSet, IRenderer, IRenderDimensions } from './Types'; import { ITerminal } from '../Types'; import { LinkRenderLayer } from './LinkRenderLayer'; diff --git a/src/renderer/SelectionRenderLayer.ts b/src/renderer/SelectionRenderLayer.ts index 7a5557fa..7a6a5af8 100644 --- a/src/renderer/SelectionRenderLayer.ts +++ b/src/renderer/SelectionRenderLayer.ts @@ -3,10 +3,8 @@ * @license MIT */ -import { IBuffer, ICharMeasure, ITerminal } from '../Types'; -import { CHAR_DATA_ATTR_INDEX } from '../Buffer'; -import { GridCache } from './GridCache'; -import { FLAGS, IColorSet, IRenderDimensions } from './Types'; +import { ITerminal } from '../Types'; +import { IColorSet, IRenderDimensions } from './Types'; import { BaseRenderLayer } from './BaseRenderLayer'; export class SelectionRenderLayer extends BaseRenderLayer { diff --git a/src/renderer/TextRenderLayer.ts b/src/renderer/TextRenderLayer.ts index df65ef8b..27ce9f79 100644 --- a/src/renderer/TextRenderLayer.ts +++ b/src/renderer/TextRenderLayer.ts @@ -5,7 +5,7 @@ import { CHAR_DATA_ATTR_INDEX, CHAR_DATA_CODE_INDEX, CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX } from '../Buffer'; import { FLAGS, IColorSet, IRenderDimensions } from './Types'; -import { CharData, IBuffer, ICharMeasure, ITerminal } from '../Types'; +import { CharData, ITerminal } from '../Types'; import { INVERTED_DEFAULT_COLOR } from './atlas/Types'; import { GridCache } from './GridCache'; import { BaseRenderLayer } from './BaseRenderLayer'; @@ -15,7 +15,7 @@ import { BaseRenderLayer } from './BaseRenderLayer'; * when the character changes (a regular space ' ' character may not as it's * drawn state is a cleared cell). */ -const OVERLAP_OWNED_CHAR_DATA: CharData = [null, '', 0, -1]; +// const OVERLAP_OWNED_CHAR_DATA: CharData = [null, '', 0, -1]; export class TextRenderLayer extends BaseRenderLayer { private _state: GridCache; @@ -239,13 +239,13 @@ export class TextRenderLayer extends BaseRenderLayer { * @param x The column of the char. * @param y The row of the char. */ - private _clearChar(x: number, y: number): void { - let colsToClear = 1; - // Clear the adjacent character if it was wide - const state = this._state.cache[x][y]; - if (state && state[CHAR_DATA_WIDTH_INDEX] === 2) { - colsToClear = 2; - } - this.clearCells(x, y, colsToClear, 1); - } + // private _clearChar(x: number, y: number): void { + // let colsToClear = 1; + // // Clear the adjacent character if it was wide + // const state = this._state.cache[x][y]; + // if (state && state[CHAR_DATA_WIDTH_INDEX] === 2) { + // colsToClear = 2; + // } + // this.clearCells(x, y, colsToClear, 1); + // } } diff --git a/src/renderer/atlas/CharAtlas.ts b/src/renderer/atlas/CharAtlas.ts index d688d328..8c529242 100644 --- a/src/renderer/atlas/CharAtlas.ts +++ b/src/renderer/atlas/CharAtlas.ts @@ -6,7 +6,6 @@ import { ITerminal } from '../../Types'; import { IColorSet } from '../Types'; import { ICharAtlasConfig } from './Types'; -import { isFirefox } from '../../shared/utils/Browser'; import { generateCharAtlas, ICharAtlasRequest } from '../../shared/atlas/CharAtlasGenerator'; import { generateConfig, configEquals } from './CharAtlasUtils'; diff --git a/src/renderer/atlas/CharAtlasUtils.ts b/src/renderer/atlas/CharAtlasUtils.ts index 57e362af..13a75dc1 100644 --- a/src/renderer/atlas/CharAtlasUtils.ts +++ b/src/renderer/atlas/CharAtlasUtils.ts @@ -4,7 +4,6 @@ */ import { ITerminal } from '../../Types'; -import { ITheme } from 'xterm'; import { IColorSet } from '../Types'; import { ICharAtlasConfig } from './Types'; diff --git a/src/utils/CharMeasure.test.ts b/src/utils/CharMeasure.test.ts index e4f4e1d6..a3cb3b3b 100644 --- a/src/utils/CharMeasure.test.ts +++ b/src/utils/CharMeasure.test.ts @@ -4,7 +4,7 @@ */ import jsdom = require('jsdom'); -import { ICharMeasure, ITerminal } from '../Types'; +import { ICharMeasure } from '../Types'; import { assert } from 'chai'; import { CharMeasure } from './CharMeasure'; diff --git a/src/utils/CharMeasure.ts b/src/utils/CharMeasure.ts index 91cfce5f..b9f267e8 100644 --- a/src/utils/CharMeasure.ts +++ b/src/utils/CharMeasure.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { ICharMeasure, ITerminal, ITerminalOptions } from '../Types'; +import { ICharMeasure, ITerminalOptions } from '../Types'; import { EventEmitter } from '../EventEmitter'; /** diff --git a/src/utils/CircularList.test.ts b/src/utils/CircularList.test.ts index 6bb35113..4c07b16c 100644 --- a/src/utils/CircularList.test.ts +++ b/src/utils/CircularList.test.ts @@ -6,10 +6,6 @@ import { assert } from 'chai'; import { CircularList } from './CircularList'; -class TestCircularList extends CircularList { - public get array(): T[] { return this._array; } -} - describe('CircularList', () => { describe('push', () => { it('should push values onto the array', () => { diff --git a/src/utils/CircularList.ts b/src/utils/CircularList.ts index 6b74971b..7fc5dcbf 100644 --- a/src/utils/CircularList.ts +++ b/src/utils/CircularList.ts @@ -60,7 +60,6 @@ export class CircularList extends EventEmitter implements ICircularList { public get forEach(): (callbackfn: (value: T, index: number) => void) => void { return (callbackfn: (value: T, index: number) => void) => { - let i = 0; let length = this.length; for (let i = 0; i < length; i++) { callbackfn(this.get(i), i); diff --git a/src/utils/TestUtils.test.ts b/src/utils/TestUtils.test.ts index c1ab2115..3c60d695 100644 --- a/src/utils/TestUtils.test.ts +++ b/src/utils/TestUtils.test.ts @@ -269,6 +269,9 @@ export class MockInputHandlingTerminal implements IInputHandlingTerminal { addDisposableListener(type: string, handler: XtermListener): IDisposable { throw new Error('Method not implemented.'); } + tabSet(): void { + throw new Error('Method not implemented.'); + } } export class MockBuffer implements IBuffer { diff --git a/tsconfig.json b/tsconfig.json index 38bfd2fa..ffd9ab68 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,8 @@ "rootDir": "src", "outDir": "lib", "sourceMap": true, - "removeComments": true + "removeComments": true, + "noUnusedLocals": true }, "include": [ "src/**/*" From b794dc017ddb304f830a5b770b6ebecb97ac555d Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 8 Mar 2018 11:08:51 -0800 Subject: [PATCH 2/4] Fix test --- src/SelectionManager.test.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/SelectionManager.test.ts b/src/SelectionManager.test.ts index 4738bc02..3dae2c31 100644 --- a/src/SelectionManager.test.ts +++ b/src/SelectionManager.test.ts @@ -3,7 +3,6 @@ * @license MIT */ -import jsdom = require('jsdom'); import { assert } from 'chai'; import { CharMeasure } from './utils/CharMeasure'; import { SelectionManager } from './SelectionManager'; @@ -36,17 +35,11 @@ class TestSelectionManager extends SelectionManager { } describe('SelectionManager', () => { - let dom: jsdom.JSDOM; - let window: Window; - let terminal: ITerminal; let buffer: IBuffer; let selectionManager: TestSelectionManager; beforeEach(() => { - dom = new jsdom.JSDOM(''); - window = dom.window; - document = window.document; terminal = new TestMockTerminal(); terminal.cols = 80; terminal.rows = 2; From cfe936a0b486c32735fbc6edd50d7b80b88102d4 Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Wed, 7 Mar 2018 23:15:37 -0800 Subject: [PATCH 3/4] Merge ICharAtlasRequest with ICharAtlasConfig ICharAtlasRequest and ICharAtlasConfig need almost exactly the same set of information, so it's simpler if we just merge the two types. As an added bonus, this also adds devicePixelRatio to the config, which helps guarantee that we won't ever accidentally end up with an atlas using a different pixel ratio than we need. --- src/renderer/Types.ts | 11 ++---- src/renderer/atlas/CharAtlas.ts | 20 ++--------- src/renderer/atlas/CharAtlasUtils.ts | 6 ++-- src/renderer/atlas/Types.ts | 14 -------- src/shared/Types.ts | 13 +++++++ src/shared/atlas/CharAtlasGenerator.ts | 48 +++++++++----------------- src/shared/atlas/Types.ts | 15 ++++++++ 7 files changed, 55 insertions(+), 72 deletions(-) create mode 100644 src/shared/Types.ts diff --git a/src/renderer/Types.ts b/src/renderer/Types.ts index 1885d059..8c464bec 100644 --- a/src/renderer/Types.ts +++ b/src/renderer/Types.ts @@ -5,6 +5,7 @@ import { ITerminal } from '../Types'; import { IEventEmitter, ITheme } from 'xterm'; +import { IColorSet } from '../shared/Types'; /** * Flags used to render terminal text properly. @@ -39,14 +40,8 @@ export interface IColorManager { colors: IColorSet; } -export interface IColorSet { - foreground: string; - background: string; - cursor: string; - cursorAccent: string; - selection: string; - ansi: string[]; -} +// TODO: We should probably rewrite the imports for IColorSet, but there's a lot of them +export { IColorSet }; export interface IRenderDimensions { scaledCharWidth: number; diff --git a/src/renderer/atlas/CharAtlas.ts b/src/renderer/atlas/CharAtlas.ts index d688d328..2ad6c6fc 100644 --- a/src/renderer/atlas/CharAtlas.ts +++ b/src/renderer/atlas/CharAtlas.ts @@ -5,9 +5,9 @@ import { ITerminal } from '../../Types'; import { IColorSet } from '../Types'; -import { ICharAtlasConfig } from './Types'; +import { ICharAtlasConfig } from '../../shared/atlas/Types'; import { isFirefox } from '../../shared/utils/Browser'; -import { generateCharAtlas, ICharAtlasRequest } from '../../shared/atlas/CharAtlasGenerator'; +import { generateCharAtlas } from '../../shared/atlas/CharAtlasGenerator'; import { generateConfig, configEquals } from './CharAtlasUtils'; interface ICharAtlasCacheEntry { @@ -63,22 +63,8 @@ export function acquireCharAtlas(terminal: ITerminal, colors: IColorSet, scaledC return canvas; }; - const charAtlasConfig: ICharAtlasRequest = { - scaledCharWidth, - scaledCharHeight, - fontSize: terminal.options.fontSize, - fontFamily: terminal.options.fontFamily, - fontWeight: terminal.options.fontWeight, - fontWeightBold: terminal.options.fontWeightBold, - background: colors.background, - foreground: colors.foreground, - ansiColors: colors.ansi, - devicePixelRatio: window.devicePixelRatio, - allowTransparency: terminal.options.allowTransparency - }; - const newEntry: ICharAtlasCacheEntry = { - bitmap: generateCharAtlas(window, canvasFactory, charAtlasConfig), + bitmap: generateCharAtlas(window, canvasFactory, newConfig), config: newConfig, ownedBy: [terminal] }; diff --git a/src/renderer/atlas/CharAtlasUtils.ts b/src/renderer/atlas/CharAtlasUtils.ts index 57e362af..5b9a2838 100644 --- a/src/renderer/atlas/CharAtlasUtils.ts +++ b/src/renderer/atlas/CharAtlasUtils.ts @@ -6,7 +6,7 @@ import { ITerminal } from '../../Types'; import { ITheme } from 'xterm'; import { IColorSet } from '../Types'; -import { ICharAtlasConfig } from './Types'; +import { ICharAtlasConfig } from '../../shared/atlas/Types'; export function generateConfig(scaledCharWidth: number, scaledCharHeight: number, terminal: ITerminal, colors: IColorSet): ICharAtlasConfig { const clonedColors = { @@ -18,6 +18,7 @@ export function generateConfig(scaledCharWidth: number, scaledCharHeight: number ansi: colors.ansi.slice(0, 16) }; return { + devicePixelRatio: window.devicePixelRatio, scaledCharWidth, scaledCharHeight, fontFamily: terminal.options.fontFamily, @@ -35,7 +36,8 @@ export function configEquals(a: ICharAtlasConfig, b: ICharAtlasConfig): boolean return false; } } - return a.fontFamily === b.fontFamily && + return a.devicePixelRatio === b.devicePixelRatio && + a.fontFamily === b.fontFamily && a.fontSize === b.fontSize && a.fontWeight === b.fontWeight && a.fontWeightBold === b.fontWeightBold && diff --git a/src/renderer/atlas/Types.ts b/src/renderer/atlas/Types.ts index a79cb327..34f01d39 100644 --- a/src/renderer/atlas/Types.ts +++ b/src/renderer/atlas/Types.ts @@ -3,19 +3,5 @@ * @license MIT */ -import { FontWeight } from 'xterm'; -import { IColorSet } from '../Types'; - export const INVERTED_DEFAULT_COLOR = -1; export const DIM_OPACITY = 0.5; - -export interface ICharAtlasConfig { - fontSize: number; - fontFamily: string; - fontWeight: FontWeight; - fontWeightBold: FontWeight; - scaledCharWidth: number; - scaledCharHeight: number; - allowTransparency: boolean; - colors: IColorSet; -} diff --git a/src/shared/Types.ts b/src/shared/Types.ts new file mode 100644 index 00000000..0407c2ef --- /dev/null +++ b/src/shared/Types.ts @@ -0,0 +1,13 @@ +/** + * Copyright (c) 2017 The xterm.js authors. All rights reserved. + * @license MIT + */ + +export interface IColorSet { + foreground: string; + background: string; + cursor: string; + cursorAccent: string; + selection: string; + ansi: string[]; +} diff --git a/src/shared/atlas/CharAtlasGenerator.ts b/src/shared/atlas/CharAtlasGenerator.ts index cf17bbb8..10112efa 100644 --- a/src/shared/atlas/CharAtlasGenerator.ts +++ b/src/shared/atlas/CharAtlasGenerator.ts @@ -4,7 +4,7 @@ */ import { FontWeight } from 'xterm'; -import { CHAR_ATLAS_CELL_SPACING } from './Types'; +import { CHAR_ATLAS_CELL_SPACING, ICharAtlasConfig } from './Types'; import { isFirefox } from '../utils/Browser'; declare const Promise: any; @@ -16,41 +16,27 @@ export interface IOffscreenCanvas { transferToImageBitmap(): ImageBitmap; } -export interface ICharAtlasRequest { - scaledCharWidth: number; - scaledCharHeight: number; - fontSize: number; - fontFamily: string; - fontWeight: FontWeight; - fontWeightBold: FontWeight; - background: string; - foreground: string; - ansiColors: string[]; - devicePixelRatio: number; - allowTransparency: boolean; -} - /** * Generates a char atlas. * @param context The window or worker context. * @param canvasFactory A function to generate a canvas with a width or height. * @param request The config for the new char atlas. */ -export function generateCharAtlas(context: Window, canvasFactory: (width: number, height: number) => HTMLCanvasElement | IOffscreenCanvas, request: ICharAtlasRequest): HTMLCanvasElement | Promise { - const cellWidth = request.scaledCharWidth + CHAR_ATLAS_CELL_SPACING; - const cellHeight = request.scaledCharHeight + CHAR_ATLAS_CELL_SPACING; +export function generateCharAtlas(context: Window, canvasFactory: (width: number, height: number) => HTMLCanvasElement | IOffscreenCanvas, config: ICharAtlasConfig): HTMLCanvasElement | Promise { + const cellWidth = config.scaledCharWidth + CHAR_ATLAS_CELL_SPACING; + const cellHeight = config.scaledCharHeight + CHAR_ATLAS_CELL_SPACING; const canvas = canvasFactory( /*255 ascii chars*/255 * cellWidth, (/*default+default bold*/2 + /*0-15*/16) * cellHeight ); - const ctx = canvas.getContext('2d', {alpha: request.allowTransparency}); + const ctx = canvas.getContext('2d', {alpha: config.allowTransparency}); - ctx.fillStyle = request.background; + ctx.fillStyle = config.colors.background; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.save(); - ctx.fillStyle = request.foreground; - ctx.font = getFont(request.fontWeight, request); + ctx.fillStyle = config.colors.foreground; + ctx.font = getFont(config.fontWeight, config); ctx.textBaseline = 'top'; // Default color @@ -64,7 +50,7 @@ export function generateCharAtlas(context: Window, canvasFactory: (width: number } // Default color bold ctx.save(); - ctx.font = getFont(request.fontWeightBold, request); + ctx.font = getFont(config.fontWeightBold, config); for (let i = 0; i < 256; i++) { ctx.save(); ctx.beginPath(); @@ -76,11 +62,11 @@ export function generateCharAtlas(context: Window, canvasFactory: (width: number ctx.restore(); // Colors 0-15 - ctx.font = getFont(request.fontWeight, request); + ctx.font = getFont(config.fontWeight, config); for (let colorIndex = 0; colorIndex < 16; colorIndex++) { // colors 8-15 are bold if (colorIndex === 8) { - ctx.font = getFont(request.fontWeightBold, request); + ctx.font = getFont(config.fontWeightBold, config); } const y = (colorIndex + 2) * cellHeight; // Draw ascii characters @@ -89,7 +75,7 @@ export function generateCharAtlas(context: Window, canvasFactory: (width: number ctx.beginPath(); ctx.rect(i * cellWidth, y, cellWidth, cellHeight); ctx.clip(); - ctx.fillStyle = request.ansiColors[colorIndex]; + ctx.fillStyle = config.colors.ansi[colorIndex]; ctx.fillText(String.fromCharCode(i), i * cellWidth, y); ctx.restore(); } @@ -114,9 +100,9 @@ export function generateCharAtlas(context: Window, canvasFactory: (width: number const charAtlasImageData = ctx.getImageData(0, 0, canvas.width, canvas.height); // Remove the background color from the image so characters may overlap - const r = parseInt(request.background.substr(1, 2), 16); - const g = parseInt(request.background.substr(3, 2), 16); - const b = parseInt(request.background.substr(5, 2), 16); + const r = parseInt(config.colors.background.substr(1, 2), 16); + const g = parseInt(config.colors.background.substr(3, 2), 16); + const b = parseInt(config.colors.background.substr(5, 2), 16); clearColor(charAtlasImageData, r, g, b); return context.createImageBitmap(charAtlasImageData); @@ -135,6 +121,6 @@ function clearColor(imageData: ImageData, r: number, g: number, b: number): void } } -function getFont(fontWeight: FontWeight, request: ICharAtlasRequest): string { - return `${fontWeight} ${request.fontSize * request.devicePixelRatio}px ${request.fontFamily}`; +function getFont(fontWeight: FontWeight, config: ICharAtlasConfig): string { + return `${fontWeight} ${config.fontSize * config.devicePixelRatio}px ${config.fontFamily}`; } diff --git a/src/shared/atlas/Types.ts b/src/shared/atlas/Types.ts index e8bb6b0a..4a66d554 100644 --- a/src/shared/atlas/Types.ts +++ b/src/shared/atlas/Types.ts @@ -3,4 +3,19 @@ * @license MIT */ +import { FontWeight } from 'xterm'; +import { IColorSet } from '../Types'; + export const CHAR_ATLAS_CELL_SPACING = 1; + +export interface ICharAtlasConfig { + devicePixelRatio: number; + fontSize: number; + fontFamily: string; + fontWeight: FontWeight; + fontWeightBold: FontWeight; + scaledCharWidth: number; + scaledCharHeight: number; + allowTransparency: boolean; + colors: IColorSet; +} From efb67edc36d4f3baa2bc5bd6901dba745a555dc7 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 9 Mar 2018 07:11:53 -0800 Subject: [PATCH 4/4] Remove unused CSS rule With #1316, this will resolve Microsoft/vscode#45145 --- src/xterm.css | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/xterm.css b/src/xterm.css index 16eb283e..3d2e9b62 100644 --- a/src/xterm.css +++ b/src/xterm.css @@ -144,10 +144,6 @@ color: transparent; } -.xterm .xterm-accessibility-tree:focus [id^="xterm-active-item-"] { - outline: 1px solid #F80; -} - .xterm .live-region { position: absolute; left: -9999px;