Move color parsing from Terminal to InputHandler
This commit is contained in:
+6
-13
@@ -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 } from 'common/Types';
|
import { IKeyboardEvent, KeyboardResultType, CoreMouseEventType, CoreMouseButton, CoreMouseAction, ITerminalOptions, IColorRGB } 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,7 +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 { css } from 'browser/Color';
|
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;
|
||||||
@@ -151,7 +151,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
|
|||||||
this.register(this._inputHandler.onRequestWindowsOptionsReport(type => this._reportWindowsOptions(type)));
|
this.register(this._inputHandler.onRequestWindowsOptionsReport(type => this._reportWindowsOptions(type)));
|
||||||
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(this._inputHandler.onAnsiColorChange((index, color) => this.changeAnsiColor(index, color)));
|
this.register(this._inputHandler.onAnsiColorChange((index, color) => this._changeAnsiColor(index, color)));
|
||||||
this.register(forwardEvent(this._inputHandler.onA11yChar, this._onA11yCharEmitter));
|
this.register(forwardEvent(this._inputHandler.onA11yChar, this._onA11yCharEmitter));
|
||||||
this.register(forwardEvent(this._inputHandler.onA11yTab, this._onA11yTabEmitter));
|
this.register(forwardEvent(this._inputHandler.onA11yTab, this._onA11yTabEmitter));
|
||||||
|
|
||||||
@@ -159,17 +159,10 @@ 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(colorIndex: number, colorValue: string): void {
|
private _changeAnsiColor(colorIndex: number, colorRGB: IColorRGB): void {
|
||||||
// colorValue = rgb:xx/yy/zz
|
const color = rgba.toColor(colorRGB[0], colorRGB[1], colorRGB[2]);
|
||||||
const r = colorValue.substring(4, 6);
|
|
||||||
const g = colorValue.substring(7, 9);
|
|
||||||
const b = colorValue.substring(10, 12);
|
|
||||||
const color = `#${r}${g}${b}`;
|
|
||||||
|
|
||||||
//TODO: remove debug
|
this._colorManager!.colors.ansi[colorIndex] = color;
|
||||||
console.log(`Change ANSI color[${colorIndex}]=${colorValue} (${color})`);
|
|
||||||
|
|
||||||
this._colorManager!.colors.ansi[colorIndex] = css.toColor(color);
|
|
||||||
this._renderService?.setColors(this._colorManager!.colors);
|
this._renderService?.setColors(this._colorManager!.colors);
|
||||||
this.viewport?.onThemeChange(this._colorManager!.colors);
|
this.viewport?.onThemeChange(this._colorManager!.colors);
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-13
@@ -4,7 +4,7 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { IInputHandler, IAttributeData, IDisposable, IWindowOptions } from 'common/Types';
|
import { IInputHandler, IAttributeData, IDisposable, IWindowOptions, IColorRGB } 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,8 +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<number, string>();
|
private _onAnsiColorChange = new EventEmitter<number, IColorRGB>();
|
||||||
public get onAnsiColorChange(): IEvent<number, string> { return this._onAnsiColorChange.event; }
|
public get onAnsiColorChange(): IEvent<number, IColorRGB> { return this._onAnsiColorChange.event; }
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _bufferService: IBufferService,
|
private readonly _bufferService: IBufferService,
|
||||||
@@ -374,12 +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._parser.setOscHandler(4, new OscHandler((data: string) => this.setAnsiColor(data)));
|
||||||
const ansiColor = data.split(';');
|
|
||||||
const colorIndex = parseInt(ansiColor[0]);
|
|
||||||
const colorValue = ansiColor[1];
|
|
||||||
this.setAnsiColor(colorIndex, colorValue);
|
|
||||||
}));
|
|
||||||
// 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)
|
||||||
@@ -2721,11 +2716,29 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* OSC 4; <num> ; <text> ST (set ANSI color <num> to <text>)
|
* OSC 4; <num> ; <text> ST (set ANSI color <num> to <text>)
|
||||||
|
*
|
||||||
|
* The expected content of data is: <number>;rgb:<rr>/<gg>/<bb> where rr, gg, bb are hex numbers.
|
||||||
*/
|
*/
|
||||||
public setAnsiColor(colorIndex: number, colorData: string): void {
|
public setAnsiColor(data: string): void {
|
||||||
//TODO: remove debug
|
// example data: 5;rgb:aa/bb/cc
|
||||||
console.log(`Setting ANSI color ${colorIndex} to value ${colorData}`);
|
const regex = /(\d+);rgb:([0-9a-fA-F]{2})\/([0-9a-fA-F]{2})\/([0-9a-fA-F]{2})/;
|
||||||
this._onAnsiColorChange.fire(colorIndex, colorData);
|
const match = data.match(regex);
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
const colorIndex = parseInt(match[1]);
|
||||||
|
const color: IColorRGB = [
|
||||||
|
parseInt(match[2], 16),
|
||||||
|
parseInt(match[3], 16),
|
||||||
|
parseInt(match[4], 16)
|
||||||
|
];
|
||||||
|
|
||||||
|
//TODO: remove debug
|
||||||
|
console.log(`Setting ANSI color ${colorIndex} to RGB value ${color}`);
|
||||||
|
this._onAnsiColorChange.fire(colorIndex, color);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this._logService.warn(`Expected format <num>;rgb:<rr>/<gg>/<bb> but got data: ${data}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Vendored
+1
-1
@@ -389,7 +389,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(colorIndex: number, colorData: 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user