Merge branch 'master' into fix/scroll-events
This commit is contained in:
@@ -169,6 +169,7 @@ Xterm.js is used in several world-class applications to provide great terminal e
|
|||||||
- [**TeleType**](https://github.com/akshaykmr/TeleType): cli tool that allows you to share your terminal online conveniently. Show off mad cli-fu, help a colleague, teach, or troubleshoot.
|
- [**TeleType**](https://github.com/akshaykmr/TeleType): cli tool that allows you to share your terminal online conveniently. Show off mad cli-fu, help a colleague, teach, or troubleshoot.
|
||||||
- [**Intervue**](https://www.intervue.io): Pair programming for interviews. Multiple programming languages supported, with results displayed by xterm.js.
|
- [**Intervue**](https://www.intervue.io): Pair programming for interviews. Multiple programming languages supported, with results displayed by xterm.js.
|
||||||
- [**TRASA**](https://trasa.io): Zero trust access to Web, SSH, RDP and Database services.
|
- [**TRASA**](https://trasa.io): Zero trust access to Web, SSH, RDP and Database services.
|
||||||
|
- [**Commas**](https://github.com/CyanSalt/commas): Commas is a hackable terminal and command runner.
|
||||||
[And much more...](https://github.com/xtermjs/xterm.js/network/dependents)
|
[And much more...](https://github.com/xtermjs/xterm.js/network/dependents)
|
||||||
|
|
||||||
Do you use xterm.js in your application as well? Please [open a Pull Request](https://github.com/sourcelair/xterm.js/pulls) to include it here. We would love to have it in our list. Note: Please add any new contributions to the end of the list only.
|
Do you use xterm.js in your application as well? Please [open a Pull Request](https://github.com/sourcelair/xterm.js/pulls) to include it here. We would love to have it in our list. Note: Please add any new contributions to the end of the list only.
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"font-finder": "^1.0.4",
|
"font-finder": "^1.1.0",
|
||||||
"font-ligatures": "^1.3.3"
|
"font-ligatures": "^1.3.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -78,13 +78,21 @@ follow-redirects@1.5.10:
|
|||||||
dependencies:
|
dependencies:
|
||||||
debug "=3.1.0"
|
debug "=3.1.0"
|
||||||
|
|
||||||
font-finder@^1.0.3, font-finder@^1.0.4:
|
font-finder@^1.0.3:
|
||||||
version "1.0.4"
|
version "1.0.4"
|
||||||
resolved "https://registry.yarnpkg.com/font-finder/-/font-finder-1.0.4.tgz#2ca944954dd8d0e1b5bdc4c596cc08607761d89b"
|
resolved "https://registry.yarnpkg.com/font-finder/-/font-finder-1.0.4.tgz#2ca944954dd8d0e1b5bdc4c596cc08607761d89b"
|
||||||
dependencies:
|
dependencies:
|
||||||
get-system-fonts "^2.0.0"
|
get-system-fonts "^2.0.0"
|
||||||
promise-stream-reader "^1.0.1"
|
promise-stream-reader "^1.0.1"
|
||||||
|
|
||||||
|
font-finder@^1.1.0:
|
||||||
|
version "1.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/font-finder/-/font-finder-1.1.0.tgz#2bff2b2762acba720239c8bec898a96daae90858"
|
||||||
|
integrity sha512-wpCL2uIbi6GurJbU7ZlQ3nGd61Ho+dSU6U83/xJT5UPFfN35EeCW/rOtS+5k+IuEZu2SYmHzDIPL9eA5tSYRAw==
|
||||||
|
dependencies:
|
||||||
|
get-system-fonts "^2.0.0"
|
||||||
|
promise-stream-reader "^1.0.1"
|
||||||
|
|
||||||
font-ligatures@^1.3.3:
|
font-ligatures@^1.3.3:
|
||||||
version "1.3.3"
|
version "1.3.3"
|
||||||
resolved "https://registry.yarnpkg.com/font-ligatures/-/font-ligatures-1.3.3.tgz#63fff18dc8adb3a11fe5eec1f4e8d7edfa8075b9"
|
resolved "https://registry.yarnpkg.com/font-ligatures/-/font-ligatures-1.3.3.tgz#63fff18dc8adb3a11fe5eec1f4e8d7edfa8075b9"
|
||||||
|
|||||||
@@ -158,8 +158,15 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (incremental) {
|
if (incremental) {
|
||||||
|
// Try to expand selection to right first.
|
||||||
result = this._findInLine(term, searchPosition, searchOptions, false);
|
result = this._findInLine(term, searchPosition, searchOptions, false);
|
||||||
if (!(result && result.row === startRow && result.col === startCol)) {
|
const isOldResultHighlighted = result && result.row === startRow && result.col === startCol;
|
||||||
|
if (!isOldResultHighlighted) {
|
||||||
|
// If selection was not able to be expanded to the right, then try reverse search
|
||||||
|
if (currentSelection) {
|
||||||
|
searchPosition.startRow = currentSelection.endRow;
|
||||||
|
searchPosition.startCol = currentSelection.endColumn;
|
||||||
|
}
|
||||||
result = this._findInLine(term, searchPosition, searchOptions, true);
|
result = this._findInLine(term, searchPosition, searchOptions, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -245,6 +252,7 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
* @param term The search term.
|
* @param term The search term.
|
||||||
* @param position The position to start the search.
|
* @param position The position to start the search.
|
||||||
* @param searchOptions Search options.
|
* @param searchOptions Search options.
|
||||||
|
* @param isReverseSearch Whether the search should start from the right side of the terminal and search to the left.
|
||||||
* @return The search result if it was found.
|
* @return The search result if it was found.
|
||||||
*/
|
*/
|
||||||
protected _findInLine(term: string, searchPosition: ISearchPosition, searchOptions: ISearchOptions = {}, isReverseSearch: boolean = false): ISearchResult | undefined {
|
protected _findInLine(term: string, searchPosition: ISearchPosition, searchOptions: ISearchOptions = {}, isReverseSearch: boolean = false): ISearchResult | undefined {
|
||||||
|
|||||||
+9
-9
@@ -43,15 +43,15 @@ function startServer() {
|
|||||||
const env = Object.assign({}, process.env);
|
const env = Object.assign({}, process.env);
|
||||||
env['COLORTERM'] = 'truecolor';
|
env['COLORTERM'] = 'truecolor';
|
||||||
var cols = parseInt(req.query.cols),
|
var cols = parseInt(req.query.cols),
|
||||||
rows = parseInt(req.query.rows),
|
rows = parseInt(req.query.rows),
|
||||||
term = pty.spawn(process.platform === 'win32' ? 'cmd.exe' : 'bash', [], {
|
term = pty.spawn(process.platform === 'win32' ? 'cmd.exe' : 'bash', [], {
|
||||||
name: 'xterm-256color',
|
name: 'xterm-256color',
|
||||||
cols: cols || 80,
|
cols: cols || 80,
|
||||||
rows: rows || 24,
|
rows: rows || 24,
|
||||||
cwd: env.PWD,
|
cwd: process.platform === 'win32' ? undefined : env.PWD,
|
||||||
env: env,
|
env: env,
|
||||||
encoding: USE_BINARY ? null : 'utf8'
|
encoding: USE_BINARY ? null : 'utf8'
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Created terminal with PID: ' + term.pid);
|
console.log('Created terminal with PID: ' + term.pid);
|
||||||
terminals[term.pid] = term;
|
terminals[term.pid] = term;
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ export class AccessibilityManager extends Disposable {
|
|||||||
const element = this._rowElements[i];
|
const element = this._rowElements[i];
|
||||||
if (element) {
|
if (element) {
|
||||||
if (lineData.length === 0) {
|
if (lineData.length === 0) {
|
||||||
element.innerHTML = ' ';
|
element.innerText = '\u00a0';
|
||||||
} else {
|
} else {
|
||||||
element.textContent = lineData;
|
element.textContent = lineData;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,8 @@ const DEFAULT_SELECTION = {
|
|||||||
rgba: 0xFFFFFF4D
|
rgba: 0xFFFFFF4D
|
||||||
};
|
};
|
||||||
|
|
||||||
// An IIFE to generate DEFAULT_ANSI_COLORS. Do not mutate DEFAULT_ANSI_COLORS, instead make a copy
|
// An IIFE to generate DEFAULT_ANSI_COLORS.
|
||||||
// and mutate that.
|
export const DEFAULT_ANSI_COLORS = Object.freeze((() => {
|
||||||
export const DEFAULT_ANSI_COLORS = (() => {
|
|
||||||
const colors = [
|
const colors = [
|
||||||
// dark:
|
// dark:
|
||||||
css.toColor('#2e3436'),
|
css.toColor('#2e3436'),
|
||||||
@@ -64,7 +63,7 @@ export const DEFAULT_ANSI_COLORS = (() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return colors;
|
return colors;
|
||||||
})();
|
})());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the source of truth for a terminal's colors.
|
* Manages the source of truth for a terminal's colors.
|
||||||
|
|||||||
+16
-1
@@ -39,7 +39,7 @@ import { MouseZoneManager } from 'browser/MouseZoneManager';
|
|||||||
import { AccessibilityManager } from './AccessibilityManager';
|
import { AccessibilityManager } from './AccessibilityManager';
|
||||||
import { ITheme, IMarker, IDisposable, ISelectionPosition, ILinkProvider } from 'xterm';
|
import { ITheme, IMarker, IDisposable, ISelectionPosition, ILinkProvider } from 'xterm';
|
||||||
import { DomRenderer } from 'browser/renderer/dom/DomRenderer';
|
import { DomRenderer } from 'browser/renderer/dom/DomRenderer';
|
||||||
import { IKeyboardEvent, KeyboardResultType, CoreMouseEventType, CoreMouseButton, CoreMouseAction, ITerminalOptions, ScrollSource } from 'common/Types';
|
import { IKeyboardEvent, KeyboardResultType, CoreMouseEventType, CoreMouseButton, CoreMouseAction, ITerminalOptions, ScrollSource, IAnsiColorChangeEvent } from 'common/Types';
|
||||||
import { evaluateKeyboardEvent } from 'common/input/Keyboard';
|
import { evaluateKeyboardEvent } from 'common/input/Keyboard';
|
||||||
import { EventEmitter, IEvent, forwardEvent } from 'common/EventEmitter';
|
import { EventEmitter, IEvent, forwardEvent } from 'common/EventEmitter';
|
||||||
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
|
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
|
||||||
@@ -53,6 +53,7 @@ import { Linkifier2 } from 'browser/Linkifier2';
|
|||||||
import { CoreBrowserService } from 'browser/services/CoreBrowserService';
|
import { CoreBrowserService } from 'browser/services/CoreBrowserService';
|
||||||
import { CoreTerminal } from 'common/CoreTerminal';
|
import { CoreTerminal } from 'common/CoreTerminal';
|
||||||
import { ITerminalOptions as IInitializedTerminalOptions } from 'common/services/Services';
|
import { ITerminalOptions as IInitializedTerminalOptions } from 'common/services/Services';
|
||||||
|
import { rgba } from 'browser/Color';
|
||||||
|
|
||||||
// Let it work inside Node.js for automated testing purposes.
|
// Let it work inside Node.js for automated testing purposes.
|
||||||
const document: Document = (typeof window !== 'undefined') ? window.document : null as any;
|
const document: Document = (typeof window !== 'undefined') ? window.document : null as any;
|
||||||
@@ -148,6 +149,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
|
|||||||
this.register(this._inputHandler.onRequestReset(() => this.reset()));
|
this.register(this._inputHandler.onRequestReset(() => this.reset()));
|
||||||
this.register(this._inputHandler.onRequestScroll((eraseAttr, isWrapped) => this.scroll(eraseAttr, isWrapped || undefined)));
|
this.register(this._inputHandler.onRequestScroll((eraseAttr, isWrapped) => this.scroll(eraseAttr, isWrapped || undefined)));
|
||||||
this.register(this._inputHandler.onRequestWindowsOptionsReport(type => this._reportWindowsOptions(type)));
|
this.register(this._inputHandler.onRequestWindowsOptionsReport(type => this._reportWindowsOptions(type)));
|
||||||
|
this.register(this._inputHandler.onAnsiColorChange((event) => this._changeAnsiColor(event)));
|
||||||
this.register(forwardEvent(this._inputHandler.onCursorMove, this._onCursorMove));
|
this.register(forwardEvent(this._inputHandler.onCursorMove, this._onCursorMove));
|
||||||
this.register(forwardEvent(this._inputHandler.onTitleChange, this._onTitleChange));
|
this.register(forwardEvent(this._inputHandler.onTitleChange, this._onTitleChange));
|
||||||
this.register(forwardEvent(this._inputHandler.onA11yChar, this._onA11yCharEmitter));
|
this.register(forwardEvent(this._inputHandler.onA11yChar, this._onA11yCharEmitter));
|
||||||
@@ -157,6 +159,19 @@ export class Terminal extends CoreTerminal implements ITerminal {
|
|||||||
this.register(this._bufferService.onResize(e => this._afterResize(e.cols, e.rows)));
|
this.register(this._bufferService.onResize(e => this._afterResize(e.cols, e.rows)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _changeAnsiColor(event: IAnsiColorChangeEvent): void {
|
||||||
|
if (!this._colorManager) { return; }
|
||||||
|
|
||||||
|
event.colors.forEach(ansiColor => {
|
||||||
|
const color = rgba.toColor(ansiColor.red, ansiColor.green, ansiColor.blue);
|
||||||
|
|
||||||
|
this._colorManager!.colors.ansi[ansiColor.colorIndex] = color;
|
||||||
|
});
|
||||||
|
|
||||||
|
this._renderService?.setColors(this._colorManager!.colors);
|
||||||
|
this.viewport?.onThemeChange(this._colorManager!.colors);
|
||||||
|
}
|
||||||
|
|
||||||
public dispose(): void {
|
public dispose(): void {
|
||||||
if (this._isDisposed) {
|
if (this._isDisposed) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ export class CompositionHelper {
|
|||||||
*/
|
*/
|
||||||
private _isSendingComposition: boolean;
|
private _isSendingComposition: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data already sent due to keydown event.
|
||||||
|
*/
|
||||||
|
private _dataAlreadySent: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _textarea: HTMLTextAreaElement,
|
private readonly _textarea: HTMLTextAreaElement,
|
||||||
private readonly _compositionView: HTMLElement,
|
private readonly _compositionView: HTMLElement,
|
||||||
@@ -46,6 +51,7 @@ export class CompositionHelper {
|
|||||||
this._isComposing = false;
|
this._isComposing = false;
|
||||||
this._isSendingComposition = false;
|
this._isSendingComposition = false;
|
||||||
this._compositionPosition = { start: 0, end: 0 };
|
this._compositionPosition = { start: 0, end: 0 };
|
||||||
|
this._dataAlreadySent = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,6 +61,7 @@ export class CompositionHelper {
|
|||||||
this._isComposing = true;
|
this._isComposing = true;
|
||||||
this._compositionPosition.start = this._textarea.value.length;
|
this._compositionPosition.start = this._textarea.value.length;
|
||||||
this._compositionView.textContent = '';
|
this._compositionView.textContent = '';
|
||||||
|
this._dataAlreadySent = '';
|
||||||
this._compositionView.classList.add('active');
|
this._compositionView.classList.add('active');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,6 +154,9 @@ export class CompositionHelper {
|
|||||||
if (this._isSendingComposition) {
|
if (this._isSendingComposition) {
|
||||||
this._isSendingComposition = false;
|
this._isSendingComposition = false;
|
||||||
let input;
|
let input;
|
||||||
|
// Add length of data already sent due to keydown event,
|
||||||
|
// otherwise input characters can be duplicated. (Issue #3191)
|
||||||
|
currentCompositionPosition.start += this._dataAlreadySent.length;
|
||||||
if (this._isComposing) {
|
if (this._isComposing) {
|
||||||
// Use the end position to get the string if a new composition has started.
|
// Use the end position to get the string if a new composition has started.
|
||||||
input = this._textarea.value.substring(currentCompositionPosition.start, currentCompositionPosition.end);
|
input = this._textarea.value.substring(currentCompositionPosition.start, currentCompositionPosition.end);
|
||||||
@@ -156,7 +166,9 @@ export class CompositionHelper {
|
|||||||
// (eg. 2) after a composition character.
|
// (eg. 2) after a composition character.
|
||||||
input = this._textarea.value.substring(currentCompositionPosition.start);
|
input = this._textarea.value.substring(currentCompositionPosition.start);
|
||||||
}
|
}
|
||||||
this._coreService.triggerDataEvent(input, true);
|
if (input.length > 0) {
|
||||||
|
this._coreService.triggerDataEvent(input, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
@@ -176,6 +188,7 @@ export class CompositionHelper {
|
|||||||
const newValue = this._textarea.value;
|
const newValue = this._textarea.value;
|
||||||
const diff = newValue.replace(oldValue, '');
|
const diff = newValue.replace(oldValue, '');
|
||||||
if (diff.length > 0) {
|
if (diff.length > 0) {
|
||||||
|
this._dataAlreadySent = diff;
|
||||||
this._coreService.triggerDataEvent(diff, true);
|
this._coreService.triggerDataEvent(diff, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,11 +13,13 @@ import * as Strings from '../LocalizableStrings';
|
|||||||
import { IEvent, EventEmitter } from 'common/EventEmitter';
|
import { IEvent, EventEmitter } from 'common/EventEmitter';
|
||||||
import { AddonManager } from './AddonManager';
|
import { AddonManager } from './AddonManager';
|
||||||
import { IParams } from 'common/parser/Types';
|
import { IParams } from 'common/parser/Types';
|
||||||
|
import { BufferSet } from 'common/buffer/BufferSet';
|
||||||
|
|
||||||
export class Terminal implements ITerminalApi {
|
export class Terminal implements ITerminalApi {
|
||||||
private _core: ITerminal;
|
private _core: ITerminal;
|
||||||
private _addonManager: AddonManager;
|
private _addonManager: AddonManager;
|
||||||
private _parser: IParser | undefined;
|
private _parser: IParser | undefined;
|
||||||
|
private _buffer: BufferNamespaceApi | undefined;
|
||||||
|
|
||||||
constructor(options?: ITerminalOptions) {
|
constructor(options?: ITerminalOptions) {
|
||||||
this._core = new TerminalCore(options);
|
this._core = new TerminalCore(options);
|
||||||
@@ -58,7 +60,10 @@ export class Terminal implements ITerminalApi {
|
|||||||
public get cols(): number { return this._core.cols; }
|
public get cols(): number { return this._core.cols; }
|
||||||
public get buffer(): IBufferNamespaceApi {
|
public get buffer(): IBufferNamespaceApi {
|
||||||
this._checkProposedApi();
|
this._checkProposedApi();
|
||||||
return new BufferNamespaceApi(this._core.buffers);
|
if (!this._buffer) {
|
||||||
|
this._buffer = new BufferNamespaceApi(this._core);
|
||||||
|
}
|
||||||
|
return this._buffer;
|
||||||
}
|
}
|
||||||
public get markers(): ReadonlyArray<IMarker> {
|
public get markers(): ReadonlyArray<IMarker> {
|
||||||
this._checkProposedApi();
|
this._checkProposedApi();
|
||||||
@@ -245,21 +250,21 @@ class BufferNamespaceApi implements IBufferNamespaceApi {
|
|||||||
private _onBufferChange = new EventEmitter<IBufferApi>();
|
private _onBufferChange = new EventEmitter<IBufferApi>();
|
||||||
public get onBufferChange(): IEvent<IBufferApi> { return this._onBufferChange.event; }
|
public get onBufferChange(): IEvent<IBufferApi> { return this._onBufferChange.event; }
|
||||||
|
|
||||||
constructor(private _buffers: IBufferSet) {
|
constructor(private _core: ITerminal) {
|
||||||
this._normal = new BufferApiView(this._buffers.normal, 'normal');
|
this._normal = new BufferApiView(this._core.buffers.normal, 'normal');
|
||||||
this._alternate = new BufferApiView(this._buffers.alt, 'alternate');
|
this._alternate = new BufferApiView(this._core.buffers.alt, 'alternate');
|
||||||
this._buffers.onBufferActivate(() => this._onBufferChange.fire(this.active));
|
this._core.buffers.onBufferActivate(() => this._onBufferChange.fire(this.active));
|
||||||
}
|
}
|
||||||
public get active(): IBufferApi {
|
public get active(): IBufferApi {
|
||||||
if (this._buffers.active === this._buffers.normal) { return this.normal; }
|
if (this._core.buffers.active === this._core.buffers.normal) { return this.normal; }
|
||||||
if (this._buffers.active === this._buffers.alt) { return this.alternate; }
|
if (this._core.buffers.active === this._core.buffers.alt) { return this.alternate; }
|
||||||
throw new Error('Active buffer is neither normal nor alternate');
|
throw new Error('Active buffer is neither normal nor alternate');
|
||||||
}
|
}
|
||||||
public get normal(): IBufferApi {
|
public get normal(): IBufferApi {
|
||||||
return this._normal.init(this._buffers.normal);
|
return this._normal.init(this._core.buffers.normal);
|
||||||
}
|
}
|
||||||
public get alternate(): IBufferApi {
|
public get alternate(): IBufferApi {
|
||||||
return this._alternate.init(this._buffers.alt);
|
return this._alternate.init(this._core.buffers.alt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,7 @@ export function generateConfig(scaledCharWidth: number, scaledCharHeight: number
|
|||||||
cursor: undefined,
|
cursor: undefined,
|
||||||
cursorAccent: undefined,
|
cursorAccent: undefined,
|
||||||
selection: undefined,
|
selection: undefined,
|
||||||
// For the static char atlas, we only use the first 16 colors, but we need all 256 for the
|
ansi: colors.ansi
|
||||||
// dynamic character atlas.
|
|
||||||
ansi: colors.ansi.slice(0, 16)
|
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
devicePixelRatio: window.devicePixelRatio,
|
devicePixelRatio: window.devicePixelRatio,
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ export class DomRenderer extends Disposable implements IRenderer {
|
|||||||
` width: ${this.dimensions.actualCellWidth}px` +
|
` width: ${this.dimensions.actualCellWidth}px` +
|
||||||
`}`;
|
`}`;
|
||||||
|
|
||||||
this._dimensionsStyleElement.innerHTML = styles;
|
this._dimensionsStyleElement.textContent = styles;
|
||||||
|
|
||||||
this._selectionContainer.style.height = this._viewportElement.style.height;
|
this._selectionContainer.style.height = this._viewportElement.style.height;
|
||||||
this._screenElement.style.width = `${this.dimensions.canvasWidth}px`;
|
this._screenElement.style.width = `${this.dimensions.canvasWidth}px`;
|
||||||
@@ -237,7 +237,7 @@ export class DomRenderer extends Disposable implements IRenderer {
|
|||||||
`${this._terminalSelector} .${FG_CLASS_PREFIX}${INVERTED_DEFAULT_COLOR} { color: ${color.opaque(this._colors.background).css}; }` +
|
`${this._terminalSelector} .${FG_CLASS_PREFIX}${INVERTED_DEFAULT_COLOR} { color: ${color.opaque(this._colors.background).css}; }` +
|
||||||
`${this._terminalSelector} .${BG_CLASS_PREFIX}${INVERTED_DEFAULT_COLOR} { background-color: ${this._colors.foreground.css}; }`;
|
`${this._terminalSelector} .${BG_CLASS_PREFIX}${INVERTED_DEFAULT_COLOR} { background-color: ${this._colors.foreground.css}; }`;
|
||||||
|
|
||||||
this._themeStyleElement.innerHTML = styles;
|
this._themeStyleElement.textContent = styles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public onDevicePixelRatioChange(): void {
|
public onDevicePixelRatioChange(): void {
|
||||||
@@ -348,7 +348,7 @@ export class DomRenderer extends Disposable implements IRenderer {
|
|||||||
|
|
||||||
public clear(): void {
|
public clear(): void {
|
||||||
for (const e of this._rowElements) {
|
for (const e of this._rowElements) {
|
||||||
e.innerHTML = '';
|
e.innerText = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,7 +359,7 @@ export class DomRenderer extends Disposable implements IRenderer {
|
|||||||
|
|
||||||
for (let y = start; y <= end; y++) {
|
for (let y = start; y <= end; y++) {
|
||||||
const rowElement = this._rowElements[y];
|
const rowElement = this._rowElements[y];
|
||||||
rowElement.innerHTML = '';
|
rowElement.innerText = '';
|
||||||
|
|
||||||
const row = y + this._bufferService.buffer.ydisp;
|
const row = y + this._bufferService.buffer.ydisp;
|
||||||
const lineData = this._bufferService.buffer.lines.get(row);
|
const lineData = this._bufferService.buffer.lines.get(row);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import { assert, expect } from 'chai';
|
import { assert, expect } from 'chai';
|
||||||
import { InputHandler } from 'common/InputHandler';
|
import { InputHandler } from 'common/InputHandler';
|
||||||
import { IBufferLine, IAttributeData } from 'common/Types';
|
import { IBufferLine, IAttributeData, IAnsiColorChangeEvent } from 'common/Types';
|
||||||
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
|
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
|
||||||
import { CellData } from 'common/buffer/CellData';
|
import { CellData } from 'common/buffer/CellData';
|
||||||
import { Attributes, UnderlineStyle } from 'common/buffer/Constants';
|
import { Attributes, UnderlineStyle } from 'common/buffer/Constants';
|
||||||
@@ -40,6 +40,7 @@ class TestInputHandler extends InputHandler {
|
|||||||
public get curAttrData(): IAttributeData { return (this as any)._curAttrData; }
|
public get curAttrData(): IAttributeData { return (this as any)._curAttrData; }
|
||||||
public get windowTitleStack(): string[] { return this._windowTitleStack; }
|
public get windowTitleStack(): string[] { return this._windowTitleStack; }
|
||||||
public get iconNameStack(): string[] { return this._iconNameStack; }
|
public get iconNameStack(): string[] { return this._iconNameStack; }
|
||||||
|
public parseAnsiColorChange(data: string): IAnsiColorChangeEvent | null { return this._parseAnsiColorChange(data); }
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('InputHandler', () => {
|
describe('InputHandler', () => {
|
||||||
@@ -1692,4 +1693,55 @@ describe('InputHandler', () => {
|
|||||||
assert.equal(coreService.decPrivateModes.origin, false);
|
assert.equal(coreService.decPrivateModes.origin, false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('OSC', () => {
|
||||||
|
it('4: should parse correct Ansi color change data', () => {
|
||||||
|
// this is testing a private method
|
||||||
|
const event = inputHandler.parseAnsiColorChange('19;rgb:a1/b2/c3');
|
||||||
|
|
||||||
|
assert.isNotNull(event);
|
||||||
|
assert.deepEqual(event!.colors[0], { colorIndex: 19, red: 0xa1, green: 0xb2, blue: 0xc3 });
|
||||||
|
}),
|
||||||
|
it('4: should ignore incorrect Ansi color change data', () => {
|
||||||
|
// this is testing a private method
|
||||||
|
assert.isNull(inputHandler.parseAnsiColorChange('17;rgb:a/b/c'));
|
||||||
|
assert.isNull(inputHandler.parseAnsiColorChange('17;rgb:#aabbcc'));
|
||||||
|
assert.isNull(inputHandler.parseAnsiColorChange('17;rgba:aa/bb/cc'));
|
||||||
|
assert.isNull(inputHandler.parseAnsiColorChange('rgb:aa/bb/cc'));
|
||||||
|
});
|
||||||
|
it('4: should parse a list of Ansi color changes', () => {
|
||||||
|
// this is testing a private method
|
||||||
|
const event = inputHandler.parseAnsiColorChange('19;rgb:a1/b2/c3;17;rgb:00/11/22;255;rgb:01/ef/2d');
|
||||||
|
|
||||||
|
assert.isNotNull(event);
|
||||||
|
assert.equal(event!.colors.length, 3);
|
||||||
|
assert.deepEqual(event!.colors[0], { colorIndex: 19, red: 0xa1, green: 0xb2, blue: 0xc3 });
|
||||||
|
assert.deepEqual(event!.colors[1], { colorIndex: 17, red: 0x00, green: 0x11, blue: 0x22 });
|
||||||
|
assert.deepEqual(event!.colors[2], { colorIndex: 255, red: 0x01, green: 0xef, blue: 0x2d });
|
||||||
|
});
|
||||||
|
it('4: should ignore incorrect colors in a list of Ansi color changes', () => {
|
||||||
|
// this is testing a private method
|
||||||
|
const event = inputHandler.parseAnsiColorChange('19;rgb:a1/b2/c3;17;rgb:WR/ON/G;255;rgb:01/ef/2d');
|
||||||
|
|
||||||
|
assert.equal(event!.colors.length, 2);
|
||||||
|
assert.deepEqual(event!.colors[0], { colorIndex: 19, red: 0xa1, green: 0xb2, blue: 0xc3 });
|
||||||
|
assert.deepEqual(event!.colors[1], { colorIndex: 255, red: 0x01, green: 0xef, blue: 0x2d });
|
||||||
|
});
|
||||||
|
it('4: should be case insensitive when parsing Ansi color changes', () => {
|
||||||
|
// this is testing a private method
|
||||||
|
const event = inputHandler.parseAnsiColorChange('19;rGb:A1/b2/C3');
|
||||||
|
|
||||||
|
assert.equal(event!.colors.length, 1);
|
||||||
|
assert.deepEqual(event!.colors[0], { colorIndex: 19, red: 0xa1, green: 0xb2, blue: 0xc3 });
|
||||||
|
});
|
||||||
|
it('4: should fire event on Ansi color change', (done) => {
|
||||||
|
inputHandler.onAnsiColorChange(e => {
|
||||||
|
assert.isNotNull(e);
|
||||||
|
assert.isNotNull(e!.colors);
|
||||||
|
assert.deepEqual(e!.colors[0], { colorIndex: 17, red: 0x1a, green: 0x2b, blue: 0x3c });
|
||||||
|
assert.deepEqual(e!.colors[1], { colorIndex: 12, red: 0x11, green: 0x22, blue: 0x33 });
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
inputHandler.parse('\x1b]4;17;rgb:1a/2b/3c;12;rgb:11/22/33\x1b\\');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { IInputHandler, IAttributeData, IDisposable, IWindowOptions } from 'common/Types';
|
import { IInputHandler, IAttributeData, IDisposable, IWindowOptions, IAnsiColorChangeEvent } from 'common/Types';
|
||||||
import { C0, C1 } from 'common/data/EscapeSequences';
|
import { C0, C1 } from 'common/data/EscapeSequences';
|
||||||
import { CHARSETS, DEFAULT_CHARSET } from 'common/data/Charsets';
|
import { CHARSETS, DEFAULT_CHARSET } from 'common/data/Charsets';
|
||||||
import { EscapeSequenceParser } from 'common/parser/EscapeSequenceParser';
|
import { EscapeSequenceParser } from 'common/parser/EscapeSequenceParser';
|
||||||
@@ -250,6 +250,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
public get onScroll(): IEvent<number> { return this._onScroll.event; }
|
public get onScroll(): IEvent<number> { return this._onScroll.event; }
|
||||||
private _onTitleChange = new EventEmitter<string>();
|
private _onTitleChange = new EventEmitter<string>();
|
||||||
public get onTitleChange(): IEvent<string> { return this._onTitleChange.event; }
|
public get onTitleChange(): IEvent<string> { return this._onTitleChange.event; }
|
||||||
|
private _onAnsiColorChange = new EventEmitter<IAnsiColorChangeEvent>();
|
||||||
|
public get onAnsiColorChange(): IEvent<IAnsiColorChangeEvent> { return this._onAnsiColorChange.event; }
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _bufferService: IBufferService,
|
private readonly _bufferService: IBufferService,
|
||||||
@@ -372,6 +374,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
this._parser.setOscHandler(2, new OscHandler((data: string) => this.setTitle(data)));
|
this._parser.setOscHandler(2, new OscHandler((data: string) => this.setTitle(data)));
|
||||||
// 3 - set property X in the form "prop=value"
|
// 3 - set property X in the form "prop=value"
|
||||||
// 4 - Change Color Number
|
// 4 - Change Color Number
|
||||||
|
this._parser.setOscHandler(4, new OscHandler((data: string) => this.setAnsiColor(data)));
|
||||||
// 5 - Change Special Color Number
|
// 5 - Change Special Color Number
|
||||||
// 6 - Enable/disable Special Color Number c
|
// 6 - Enable/disable Special Color Number c
|
||||||
// 7 - current directory? (not in xterm spec, see https://gitlab.com/gnachman/iterm2/issues/3939)
|
// 7 - current directory? (not in xterm spec, see https://gitlab.com/gnachman/iterm2/issues/3939)
|
||||||
@@ -2711,6 +2714,45 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
this._iconName = data;
|
this._iconName = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected _parseAnsiColorChange(data: string): IAnsiColorChangeEvent | null {
|
||||||
|
const result: IAnsiColorChangeEvent = { colors: [] };
|
||||||
|
// example data: 5;rgb:aa/bb/cc
|
||||||
|
const regex = /(\d+);rgb:([0-9a-f]{2})\/([0-9a-f]{2})\/([0-9a-f]{2})/gi;
|
||||||
|
let match;
|
||||||
|
|
||||||
|
while ((match = regex.exec(data)) !== null) {
|
||||||
|
result.colors.push({
|
||||||
|
colorIndex: parseInt(match[1]),
|
||||||
|
red: parseInt(match[2], 16),
|
||||||
|
green: parseInt(match[3], 16),
|
||||||
|
blue: parseInt(match[4], 16)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.colors.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OSC 4; <num> ; <text> ST (set ANSI color <num> to <text>)
|
||||||
|
*
|
||||||
|
* @vt: #Y OSC 4 "Set ANSI color" "OSC 4 ; c ; spec BEL" "Change color number `c` to the color specified by `spec`."
|
||||||
|
* `c` is the color index between 0 and 255. `spec` color format is 'rgb:hh/hh/hh' where `h` are hexadecimal digits.
|
||||||
|
* There may be multipe c ; spec elements present in the same instruction, e.g. 1;rgb:10/20/30;2;rgb:a0/b0/c0.
|
||||||
|
*/
|
||||||
|
public setAnsiColor(data: string): void {
|
||||||
|
const event = this._parseAnsiColorChange(data);
|
||||||
|
if (event) {
|
||||||
|
this._onAnsiColorChange.fire(event);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this._logService.warn(`Expected format <num>;rgb:<rr>/<gg>/<bb> but got data: ${data}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ESC E
|
* ESC E
|
||||||
* C1.NEL
|
* C1.NEL
|
||||||
|
|||||||
Vendored
+15
@@ -338,6 +338,20 @@ export interface IWindowOptions {
|
|||||||
setWinLines?: boolean;
|
setWinLines?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IAnsiColorChangeEventColor {
|
||||||
|
colorIndex: number;
|
||||||
|
red: number;
|
||||||
|
green: number;
|
||||||
|
blue: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event fired for OSC 4 command - to change ANSI color based on its index.
|
||||||
|
*/
|
||||||
|
export interface IAnsiColorChangeEvent {
|
||||||
|
colors: IAnsiColorChangeEventColor[];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls the parser and handles actions generated by the parser.
|
* Calls the parser and handles actions generated by the parser.
|
||||||
*/
|
*/
|
||||||
@@ -399,6 +413,7 @@ export interface IInputHandler {
|
|||||||
/** CSI ' ~ */ deleteColumns(params: IParams): void;
|
/** CSI ' ~ */ deleteColumns(params: IParams): void;
|
||||||
/** OSC 0
|
/** OSC 0
|
||||||
OSC 2 */ setTitle(data: string): void;
|
OSC 2 */ setTitle(data: string): void;
|
||||||
|
/** OSC 4 */ setAnsiColor(data: string): void;
|
||||||
/** ESC E */ nextLine(): void;
|
/** ESC E */ nextLine(): void;
|
||||||
/** ESC = */ keypadApplicationMode(): void;
|
/** ESC = */ keypadApplicationMode(): void;
|
||||||
/** ESC > */ keypadNumericMode(): void;
|
/** ESC > */ keypadNumericMode(): void;
|
||||||
|
|||||||
@@ -15,10 +15,9 @@ import { Disposable } from 'common/Lifecycle';
|
|||||||
* provides also utilities for working with them.
|
* provides also utilities for working with them.
|
||||||
*/
|
*/
|
||||||
export class BufferSet extends Disposable implements IBufferSet {
|
export class BufferSet extends Disposable implements IBufferSet {
|
||||||
private _normal: Buffer;
|
private _normal!: Buffer;
|
||||||
private _alt: Buffer;
|
private _alt!: Buffer;
|
||||||
private _activeBuffer: Buffer;
|
private _activeBuffer!: Buffer;
|
||||||
|
|
||||||
|
|
||||||
private _onBufferActivate = this.register(new EventEmitter<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>());
|
private _onBufferActivate = this.register(new EventEmitter<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>());
|
||||||
public get onBufferActivate(): IEvent<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}> { return this._onBufferActivate.event; }
|
public get onBufferActivate(): IEvent<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}> { return this._onBufferActivate.event; }
|
||||||
@@ -28,17 +27,20 @@ export class BufferSet extends Disposable implements IBufferSet {
|
|||||||
* @param _terminal - The terminal the BufferSet will belong to
|
* @param _terminal - The terminal the BufferSet will belong to
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
optionsService: IOptionsService,
|
private readonly _optionsService: IOptionsService,
|
||||||
bufferService: IBufferService
|
private readonly _bufferService: IBufferService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
this.reset();
|
||||||
|
}
|
||||||
|
|
||||||
this._normal = new Buffer(true, optionsService, bufferService);
|
public reset(): void {
|
||||||
|
this._normal = new Buffer(true, this._optionsService, this._bufferService);
|
||||||
this._normal.fillViewportRows();
|
this._normal.fillViewportRows();
|
||||||
|
|
||||||
// The alt buffer should never have scrollback.
|
// The alt buffer should never have scrollback.
|
||||||
// See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
|
// See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
|
||||||
this._alt = new Buffer(false, optionsService, bufferService);
|
this._alt = new Buffer(false, this._optionsService, this._bufferService);
|
||||||
this._activeBuffer = this._normal;
|
this._activeBuffer = this._normal;
|
||||||
|
|
||||||
this.setupTabStops();
|
this.setupTabStops();
|
||||||
|
|||||||
Vendored
+1
@@ -56,6 +56,7 @@ export interface IBufferSet extends IDisposable {
|
|||||||
|
|
||||||
activateNormalBuffer(): void;
|
activateNormalBuffer(): void;
|
||||||
activateAltBuffer(fillAttr?: IAttributeData): void;
|
activateAltBuffer(fillAttr?: IAttributeData): void;
|
||||||
|
reset(): void;
|
||||||
resize(newCols: number, newRows: number): void;
|
resize(newCols: number, newRows: number): void;
|
||||||
setupTabStops(i?: number): void;
|
setupTabStops(i?: number): void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -356,7 +356,7 @@ export function evaluateKeyboardEvent(
|
|||||||
const keyCode = ev.ctrlKey ? ev.keyCode - 64 : ev.keyCode + 32;
|
const keyCode = ev.ctrlKey ? ev.keyCode - 64 : ev.keyCode + 32;
|
||||||
result.key = C0.ESC + String.fromCharCode(keyCode);
|
result.key = C0.ESC + String.fromCharCode(keyCode);
|
||||||
}
|
}
|
||||||
} else if (isMac && !ev.altKey && !ev.ctrlKey && ev.metaKey) {
|
} else if (isMac && !ev.altKey && !ev.ctrlKey && !ev.shiftKey && ev.metaKey) {
|
||||||
if (ev.keyCode === 65) { // cmd + a
|
if (ev.keyCode === 65) { // cmd + a
|
||||||
result.type = KeyboardResultType.SELECT_ALL;
|
result.type = KeyboardResultType.SELECT_ALL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,7 @@ export class BufferService extends Disposable implements IBufferService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public reset(): void {
|
public reset(): void {
|
||||||
this.buffers.dispose();
|
this.buffers.reset();
|
||||||
this.buffers = new BufferSet(this._optionsService, this);
|
|
||||||
this.isUserScrolling = false;
|
this.isUserScrolling = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user