From a622b97a9454324e8bb6aa5f1b4baa6de591ea62 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 13 Oct 2017 13:13:38 -0700 Subject: [PATCH 1/7] Support enableBold option --- src/Interfaces.ts | 1 + src/Terminal.ts | 2 ++ src/renderer/BaseRenderLayer.ts | 18 +++++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Interfaces.ts b/src/Interfaces.ts index 2c77e8d3..c6faf373 100644 --- a/src/Interfaces.ts +++ b/src/Interfaces.ts @@ -135,6 +135,7 @@ export interface ITerminalOptions { cursorStyle?: string; debug?: boolean; disableStdin?: boolean; + enableBold?: boolean; fontSize?: number; fontFamily?: string; geometry?: [number, number]; diff --git a/src/Terminal.ts b/src/Terminal.ts index 8486f265..da4bdc54 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -77,6 +77,7 @@ const DEFAULT_OPTIONS: ITerminalOptions = { cursorStyle: 'block', bellSound: BellSound, bellStyle: 'none', + enableBold: true, fontFamily: 'courier-new, courier, monospace', fontSize: 15, lineHeight: 1.0, @@ -410,6 +411,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.renderer.clear(); this.charMeasure.measure(this.options); break; + case 'enableBold': case 'lineHeight': // When the font changes the size of the cells may change which requires a renderer clear this.renderer.clear(); diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index fa1846b6..232a58f2 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -230,14 +230,14 @@ export abstract class BaseRenderLayer implements IRenderLayer { colorIndex = fg + 2; } else { // If default color and bold - if (bold) { + if (bold && terminal.options.enableBold) { colorIndex = 1; } } const isAscii = code < 256; // A color is basic if it is one of the standard normal or bold weight // colors of the characters held in the char atlas. Note that this excludes - // the normal weight light color characters + // the normal weight _light_ color characters. const isBasicColor = (colorIndex > 1 && fg < 16) && (fg < 8 || bold); const isDefaultColor = fg >= 256; const isDefaultBackground = bg >= 256; @@ -245,10 +245,22 @@ export abstract class BaseRenderLayer implements IRenderLayer { // ImageBitmap's draw about twice as fast as from a canvas const charAtlasCellWidth = this._scaledCharWidth + CHAR_ATLAS_CELL_SPACING; const charAtlasCellHeight = this._scaledCharHeight + CHAR_ATLAS_CELL_SPACING; + // Apply alpha to dim the character if (dim) { this._ctx.globalAlpha = DIM_OPACITY; } + + // Draw the non-bold version of the same color if bold is not enabled + if (bold && !terminal.options.enableBold) { + if (colorIndex === 1) { + // The default color + colorIndex = 0; + } else { + colorIndex -= 8; + } + } + this._ctx.drawImage(this._charAtlas, code * charAtlasCellWidth, colorIndex * charAtlasCellHeight, charAtlasCellWidth, this._scaledCharHeight, x * this._scaledCharWidth, y * this._scaledLineHeight + this._scaledLineDrawY, charAtlasCellWidth, this._scaledCharHeight); @@ -274,7 +286,7 @@ export abstract class BaseRenderLayer implements IRenderLayer { private _drawUncachedChar(terminal: ITerminal, char: string, width: number, fg: number, x: number, y: number, bold: boolean, dim: boolean): void { this._ctx.save(); this._ctx.font = `${terminal.options.fontSize * window.devicePixelRatio}px ${terminal.options.fontFamily}`; - if (bold) { + if (bold && terminal.options.enableBold) { this._ctx.font = `bold ${this._ctx.font}`; } this._ctx.textBaseline = 'top'; From a1fcafd50ce86a12340c95a4a824a4df3bbe7ab2 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 13 Oct 2017 13:20:22 -0700 Subject: [PATCH 2/7] Fix default color with bold disabled --- src/renderer/BaseRenderLayer.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index 232a58f2..58517dbc 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -253,10 +253,8 @@ export abstract class BaseRenderLayer implements IRenderLayer { // Draw the non-bold version of the same color if bold is not enabled if (bold && !terminal.options.enableBold) { - if (colorIndex === 1) { - // The default color - colorIndex = 0; - } else { + // Ignore default color as it's not touched above + if (colorIndex > 1) { colorIndex -= 8; } } From 899929afc69fad8cfcee277e80994b11e05bd812 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 13 Oct 2017 13:30:12 -0700 Subject: [PATCH 3/7] Add enableBold typings --- fixtures/typings-test/typings-test.ts | 2 ++ typings/xterm.d.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/fixtures/typings-test/typings-test.ts b/fixtures/typings-test/typings-test.ts index 928ca238..9b8e4da2 100644 --- a/fixtures/typings-test/typings-test.ts +++ b/fixtures/typings-test/typings-test.ts @@ -140,6 +140,7 @@ namespace methods_core { const r18: (data: string) => void = t.getOption('handler'); const r19: string = t.getOption('bellSound'); const r20: string = t.getOption('bellStyle'); + const r21: boolean = t.getOption('enableBold'); } { const t: Terminal = new Terminal(); @@ -152,6 +153,7 @@ namespace methods_core { t.setOption('cursorBlink', true); t.setOption('debug', true); t.setOption('disableStdin', true); + t.setOption('enableBold', true); t.setOption('popOnBell', true); t.setOption('screenKeys', true); t.setOption('useFlowControl', true); diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index de2a261b..d1fd14de 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -41,6 +41,11 @@ interface ITerminalOptions { */ disableStdin?: boolean; + /** + * Whether to enable the rendering of bold text. + */ + enableBold?: boolean; + /** * The font size used to render text. */ @@ -397,7 +402,7 @@ declare module 'xterm' { * Retrieves an option's value from the terminal. * @param key The option key. */ - getOption(key: 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell'): boolean; + getOption(key: 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'enableBold' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell'): boolean; /** * Retrieves an option's value from the terminal. * @param key The option key. @@ -447,7 +452,7 @@ declare module 'xterm' { * @param key The option key. * @param value The option value. */ - setOption(key: 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell', value: boolean): void; + setOption(key: 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'enableBold' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell', value: boolean): void; /** * Sets an option on the terminal. * @param key The option key. From 5cdd1bee420b793d7d3e1edd72a9069323634940 Mon Sep 17 00:00:00 2001 From: Lukas Drgon Date: Sat, 14 Oct 2017 19:25:42 +0200 Subject: [PATCH 4/7] Add jsDelivr hits badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e7a80bfb..e16d7b87 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # [![xterm.js logo](logo.png)](https://xtermjs.org) -[![xterm.js build status](https://api.travis-ci.org/sourcelair/xterm.js.svg)](https://travis-ci.org/sourcelair/xterm.js) [![Coverage Status](https://coveralls.io/repos/github/sourcelair/xterm.js/badge.svg)](https://coveralls.io/github/sourcelair/xterm.js) [![Gitter](https://badges.gitter.im/sourcelair/xterm.js.svg)](https://gitter.im/sourcelair/xterm.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +[![xterm.js build status](https://api.travis-ci.org/sourcelair/xterm.js.svg)](https://travis-ci.org/sourcelair/xterm.js) [![Coverage Status](https://coveralls.io/repos/github/sourcelair/xterm.js/badge.svg)](https://coveralls.io/github/sourcelair/xterm.js) [![Gitter](https://badges.gitter.im/sourcelair/xterm.js.svg)](https://gitter.im/sourcelair/xterm.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![jsDelivr Hits](https://data.jsdelivr.com/v1/package/npm/xterm/badge?style=rounded)](https://www.jsdelivr.com/package/npm/xterm) Xterm.js is a terminal front-end component written in JavaScript that works in the browser. From 1d76cc921a53f16a0131b99a7a4dd407e343bfbc Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 19 Oct 2017 08:44:00 -0700 Subject: [PATCH 5/7] Use .xterm over .terminal in CSS Fixes #1068 --- src/xterm.css | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/xterm.css b/src/xterm.css index 399f56ce..35e92f63 100644 --- a/src/xterm.css +++ b/src/xterm.css @@ -35,7 +35,7 @@ * Default styles for xterm.js */ -.terminal { +.xterm { font-family: courier-new, courier, monospace; font-feature-settings: "liga" 0; position: relative; @@ -44,12 +44,12 @@ -webkit-user-select: none; } -.terminal.focus, -.terminal:focus { +.xterm.focus, +.xterm:focus { outline: none; } -.terminal .xterm-helpers { +.xterm .xterm-helpers { position: absolute; top: 0; /** @@ -59,7 +59,7 @@ z-index: 10; } -.terminal .xterm-helper-textarea { +.xterm .xterm-helper-textarea { /* * HACK: to fix IE's blinking cursor * Move textarea out of the screen to the far left, so that the cursor is not visible. @@ -77,7 +77,7 @@ resize: none; } -.terminal .composition-view { +.xterm .composition-view { /* TODO: Composition position got messed up somewhere */ background: #000; color: #FFF; @@ -87,38 +87,38 @@ z-index: 1; } -.terminal .composition-view.active { +.xterm .composition-view.active { display: block; } -.terminal .xterm-viewport { +.xterm .xterm-viewport { /* On OS X this is required in order for the scroll bar to appear fully opaque */ background-color: #000; overflow-y: scroll; } -.terminal canvas { +.xterm canvas { position: absolute; left: 0; top: 0; } -.terminal .xterm-scroll-area { +.xterm .xterm-scroll-area { visibility: hidden; } -.terminal .xterm-char-measure-element { +.xterm .xterm-char-measure-element { display: inline-block; visibility: hidden; position: absolute; left: -9999em; } -.terminal.enable-mouse-events { +.xterm.enable-mouse-events { /* When mouse events are enabled (eg. tmux), revert to the standard pointer cursor */ cursor: default; } -.terminal:not(.enable-mouse-events) { +.xterm:not(.enable-mouse-events) { cursor: text; } From 5d49db54eea83f4b11b9083704877b89bf450f6e Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 20 Oct 2017 17:28:34 -0700 Subject: [PATCH 6/7] Move interfaces in types inside module Fixes #1071 --- typings/xterm.d.ts | 328 ++++++++++++++++++++++----------------------- 1 file changed, 164 insertions(+), 164 deletions(-) diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index f20f3502..f0ab9daf 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -7,171 +7,171 @@ * to be stable and consumed by external programs. */ -/** - * An object containing start up options for the terminal. - */ -interface ITerminalOptions { - /** - * A data uri of the sound to use for the bell (needs bellStyle = 'sound'). - */ - bellSound?: string; - - /** - * The type of the bell notification the terminal will use. - */ - bellStyle?: 'none' | 'visual' | 'sound' | 'both'; - - /** - * The number of columns in the terminal. - */ - cols?: number; - - /** - * Whether the cursor blinks. - */ - cursorBlink?: boolean; - - /** - * The style of the cursor. - */ - cursorStyle?: 'block' | 'underline' | 'bar'; - - /** - * Whether input should be disabled. - */ - disableStdin?: boolean; - - /** - * Whether to enable the rendering of bold text. - */ - enableBold?: boolean; - - /** - * The font size used to render text. - */ - fontSize?: number; - - /** - * The font family used to render text. - */ - fontFamily?: string; - - /** - * The spacing in whole pixels between characters.. - */ - letterSpacing?: number; - - /** - * The line height used to render text. - */ - lineHeight?: number; - - /** - * The number of rows in the terminal. - */ - rows?: number; - - /** - * The amount of scrollback in the terminal. Scrollback is the amount of rows - * that are retained when lines are scrolled beyond the initial viewport. - */ - scrollback?: number; - - /** - * The size of tab stops in the terminal. - */ - tabStopWidth?: number; - - /** - * The color theme of the terminal. - */ - theme?: ITheme; -} - -/** - * Contains colors to theme the terminal with. - */ -interface ITheme { - /** The default foreground color */ - foreground?: string, - /** The default background color */ - background?: string, - /** The cursor color */ - cursor?: string, - /** The accent color of the cursor (used as the foreground color for a block cursor) */ - cursorAccent?: string, - /** The selection color (can be transparent) */ - selection?: string, - /** ANSI black (eg. `\x1b[30m`) */ - black?: string, - /** ANSI red (eg. `\x1b[31m`) */ - red?: string, - /** ANSI green (eg. `\x1b[32m`) */ - green?: string, - /** ANSI yellow (eg. `\x1b[33m`) */ - yellow?: string, - /** ANSI blue (eg. `\x1b[34m`) */ - blue?: string, - /** ANSI magenta (eg. `\x1b[35m`) */ - magenta?: string, - /** ANSI cyan (eg. `\x1b[36m`) */ - cyan?: string, - /** ANSI white (eg. `\x1b[37m`) */ - white?: string, - /** ANSI bright black (eg. `\x1b[1;30m`) */ - brightBlack?: string, - /** ANSI bright red (eg. `\x1b[1;31m`) */ - brightRed?: string, - /** ANSI bright green (eg. `\x1b[1;32m`) */ - brightGreen?: string, - /** ANSI bright yellow (eg. `\x1b[1;33m`) */ - brightYellow?: string, - /** ANSI bright blue (eg. `\x1b[1;34m`) */ - brightBlue?: string, - /** ANSI bright magenta (eg. `\x1b[1;35m`) */ - brightMagenta?: string, - /** ANSI bright cyan (eg. `\x1b[1;36m`) */ - brightCyan?: string, - /** ANSI bright white (eg. `\x1b[1;37m`) */ - brightWhite?: string -} - -/** - * An object containing options for a link matcher. - */ -interface ILinkMatcherOptions { - /** - * The index of the link from the regex.match(text) call. This defaults to 0 - * (for regular expressions without capture groups). - */ - matchIndex?: number; - - /** - * A callback that validates an individual link, returning true if valid and - * false if invalid. - */ - validationCallback?: (uri: string, callback: (isValid: boolean) => void) => void; - - /** - * A callback that fires when the mouse hovers over a link for a moment. - */ - tooltipCallback?: (event: MouseEvent, uri: string) => boolean | void; - - /** - * A callback that fires when the mouse leaves a link. Note that this can - * happen even when tooltipCallback hasn't fired for the link yet. - */ - leaveCallback?: (event: MouseEvent, uri: string) => boolean | void; - - /** - * The priority of the link matcher, this defines the order in which the link - * matcher is evaluated relative to others, from highest to lowest. The - * default value is 0. - */ - priority?: number; -} - declare module 'xterm' { + /** + * An object containing start up options for the terminal. + */ + interface ITerminalOptions { + /** + * A data uri of the sound to use for the bell (needs bellStyle = 'sound'). + */ + bellSound?: string; + + /** + * The type of the bell notification the terminal will use. + */ + bellStyle?: 'none' | 'visual' | 'sound' | 'both'; + + /** + * The number of columns in the terminal. + */ + cols?: number; + + /** + * Whether the cursor blinks. + */ + cursorBlink?: boolean; + + /** + * The style of the cursor. + */ + cursorStyle?: 'block' | 'underline' | 'bar'; + + /** + * Whether input should be disabled. + */ + disableStdin?: boolean; + + /** + * Whether to enable the rendering of bold text. + */ + enableBold?: boolean; + + /** + * The font size used to render text. + */ + fontSize?: number; + + /** + * The font family used to render text. + */ + fontFamily?: string; + + /** + * The spacing in whole pixels between characters.. + */ + letterSpacing?: number; + + /** + * The line height used to render text. + */ + lineHeight?: number; + + /** + * The number of rows in the terminal. + */ + rows?: number; + + /** + * The amount of scrollback in the terminal. Scrollback is the amount of rows + * that are retained when lines are scrolled beyond the initial viewport. + */ + scrollback?: number; + + /** + * The size of tab stops in the terminal. + */ + tabStopWidth?: number; + + /** + * The color theme of the terminal. + */ + theme?: ITheme; + } + + /** + * Contains colors to theme the terminal with. + */ + interface ITheme { + /** The default foreground color */ + foreground?: string, + /** The default background color */ + background?: string, + /** The cursor color */ + cursor?: string, + /** The accent color of the cursor (used as the foreground color for a block cursor) */ + cursorAccent?: string, + /** The selection color (can be transparent) */ + selection?: string, + /** ANSI black (eg. `\x1b[30m`) */ + black?: string, + /** ANSI red (eg. `\x1b[31m`) */ + red?: string, + /** ANSI green (eg. `\x1b[32m`) */ + green?: string, + /** ANSI yellow (eg. `\x1b[33m`) */ + yellow?: string, + /** ANSI blue (eg. `\x1b[34m`) */ + blue?: string, + /** ANSI magenta (eg. `\x1b[35m`) */ + magenta?: string, + /** ANSI cyan (eg. `\x1b[36m`) */ + cyan?: string, + /** ANSI white (eg. `\x1b[37m`) */ + white?: string, + /** ANSI bright black (eg. `\x1b[1;30m`) */ + brightBlack?: string, + /** ANSI bright red (eg. `\x1b[1;31m`) */ + brightRed?: string, + /** ANSI bright green (eg. `\x1b[1;32m`) */ + brightGreen?: string, + /** ANSI bright yellow (eg. `\x1b[1;33m`) */ + brightYellow?: string, + /** ANSI bright blue (eg. `\x1b[1;34m`) */ + brightBlue?: string, + /** ANSI bright magenta (eg. `\x1b[1;35m`) */ + brightMagenta?: string, + /** ANSI bright cyan (eg. `\x1b[1;36m`) */ + brightCyan?: string, + /** ANSI bright white (eg. `\x1b[1;37m`) */ + brightWhite?: string + } + + /** + * An object containing options for a link matcher. + */ + interface ILinkMatcherOptions { + /** + * The index of the link from the regex.match(text) call. This defaults to 0 + * (for regular expressions without capture groups). + */ + matchIndex?: number; + + /** + * A callback that validates an individual link, returning true if valid and + * false if invalid. + */ + validationCallback?: (uri: string, callback: (isValid: boolean) => void) => void; + + /** + * A callback that fires when the mouse hovers over a link for a moment. + */ + tooltipCallback?: (event: MouseEvent, uri: string) => boolean | void; + + /** + * A callback that fires when the mouse leaves a link. Note that this can + * happen even when tooltipCallback hasn't fired for the link yet. + */ + leaveCallback?: (event: MouseEvent, uri: string) => boolean | void; + + /** + * The priority of the link matcher, this defines the order in which the link + * matcher is evaluated relative to others, from highest to lowest. The + * default value is 0. + */ + priority?: number; + } + /** * The class that represents an xterm.js terminal. */ From ac71f13361367fe073a07fa9a8bd97b8f6217db9 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 23 Oct 2017 11:54:49 -0700 Subject: [PATCH 7/7] Add null check in MouseZoneManager._findZoneEventAt See Microsoft/vscode#36328 --- src/input/MouseZoneManager.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/input/MouseZoneManager.ts b/src/input/MouseZoneManager.ts index ebb91699..8fae3171 100644 --- a/src/input/MouseZoneManager.ts +++ b/src/input/MouseZoneManager.ts @@ -170,6 +170,9 @@ export class MouseZoneManager implements IMouseZoneManager { private _findZoneEventAt(e: MouseEvent): IMouseZone { const coords = this._terminal.mouseHelper.getCoords(e, this._terminal.element, this._terminal.charMeasure, this._terminal.options.lineHeight, this._terminal.cols, this._terminal.rows); + if (!coords) { + return null; + } for (let i = 0; i < this._zones.length; i++) { const zone = this._zones[i]; if (zone.y === coords[1] && zone.x1 <= coords[0] && zone.x2 > coords[0]) {