diff --git a/src/InputHandler.ts b/src/InputHandler.ts index cfd2e1ec5..1c9e65747 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -381,7 +381,7 @@ export class InputHandler extends Disposable implements IInputHandler { let code: number; let chWidth: number; const buffer = this._bufferService.buffer; - const charset = this._terminal.charset; + const charset = this._coreService.charsetModes.charset; const screenReaderMode = this._optionsService.options.screenReaderMode; const cols = this._bufferService.cols; const wraparoundMode = this._terminal.wraparoundMode; @@ -608,7 +608,7 @@ export class InputHandler extends Disposable implements IInputHandler { * G1 character set. */ public shiftOut(): void { - this._terminal.setgLevel(1); + this._coreService.setgLevel(1); } /** @@ -617,7 +617,7 @@ export class InputHandler extends Disposable implements IInputHandler { * character set (the default). */ public shiftIn(): void { - this._terminal.setgLevel(0); + this._coreService.setgLevel(0); } /** @@ -1396,10 +1396,10 @@ export class InputHandler extends Disposable implements IInputHandler { this._coreService.decPrivateModes.applicationCursorKeys = true; break; case 2: - this._terminal.setgCharset(0, DEFAULT_CHARSET); - this._terminal.setgCharset(1, DEFAULT_CHARSET); - this._terminal.setgCharset(2, DEFAULT_CHARSET); - this._terminal.setgCharset(3, DEFAULT_CHARSET); + this._coreService.setgCharset(0, DEFAULT_CHARSET); + this._coreService.setgCharset(1, DEFAULT_CHARSET); + this._coreService.setgCharset(2, DEFAULT_CHARSET); + this._coreService.setgCharset(3, DEFAULT_CHARSET); // set VT100 mode here break; case 3: // 132 col mode @@ -1974,9 +1974,7 @@ export class InputHandler extends Disposable implements IInputHandler { this._bufferService.buffer.scrollBottom = this._bufferService.rows - 1; this._terminal.curAttrData = DEFAULT_ATTR_DATA.clone(); this._bufferService.buffer.x = this._bufferService.buffer.y = 0; // ? - this._terminal.charset = null; - this._terminal.glevel = 0; // ?? - this._terminal.charsets = [null]; // ?? + this._coreService.softReset(); } /** @@ -2040,7 +2038,7 @@ export class InputHandler extends Disposable implements IInputHandler { this._bufferService.buffer.savedY = this._bufferService.buffer.ybase + this._bufferService.buffer.y; this._bufferService.buffer.savedCurAttrData.fg = this._terminal.curAttrData.fg; this._bufferService.buffer.savedCurAttrData.bg = this._terminal.curAttrData.bg; - this._bufferService.buffer.savedCharset = this._terminal.charset; + this._bufferService.buffer.savedCharset = this._coreService.charsetModes.charset; } @@ -2054,9 +2052,9 @@ export class InputHandler extends Disposable implements IInputHandler { this._bufferService.buffer.y = Math.max(this._bufferService.buffer.savedY - this._bufferService.buffer.ybase, 0); this._terminal.curAttrData.fg = this._bufferService.buffer.savedCurAttrData.fg; this._terminal.curAttrData.bg = this._bufferService.buffer.savedCurAttrData.bg; - this._terminal.charset = (this as any)._savedCharset; + this._coreService.charsetModes.charset = (this as any)._savedCharset; if (this._bufferService.buffer.savedCharset) { - this._terminal.charset = this._bufferService.buffer.savedCharset; + this._coreService.charsetModes.charset = this._bufferService.buffer.savedCharset; } this._restrictCursor(); } @@ -2115,8 +2113,8 @@ export class InputHandler extends Disposable implements IInputHandler { * therefore ESC % G does the same. */ public selectDefaultCharset(): void { - this._terminal.setgLevel(0); - this._terminal.setgCharset(0, DEFAULT_CHARSET); // US (default) + this._coreService.setgLevel(0); + this._coreService.setgCharset(0, DEFAULT_CHARSET); // US (default) } /** @@ -2143,7 +2141,7 @@ export class InputHandler extends Disposable implements IInputHandler { if (collectAndFlag[0] === '/') { return; // TODO: Is this supported? } - this._terminal.setgCharset(GLEVEL[collectAndFlag[0]], CHARSETS[collectAndFlag[1]] || DEFAULT_CHARSET); + this._coreService.setgCharset(GLEVEL[collectAndFlag[0]], CHARSETS[collectAndFlag[1]] || DEFAULT_CHARSET); return; } @@ -2222,7 +2220,7 @@ export class InputHandler extends Disposable implements IInputHandler { * you use another locking shift. (partly supported) */ public setgLevel(level: number): void { - this._terminal.setgLevel(level); // TODO: save to move from terminal? + this._coreService.setgLevel(level); } /** diff --git a/src/Terminal.ts b/src/Terminal.ts index bb67ac1f1..eb199ea11 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -39,7 +39,7 @@ import { MouseZoneManager } from 'browser/MouseZoneManager'; import { AccessibilityManager } from './AccessibilityManager'; import { ITheme, IMarker, IDisposable, ISelectionPosition } from 'xterm'; import { DomRenderer } from 'browser/renderer/dom/DomRenderer'; -import { IKeyboardEvent, KeyboardResultType, ICharset, IBufferLine, IAttributeData, CoreMouseEventType, CoreMouseButton, CoreMouseAction } from 'common/Types'; +import { IKeyboardEvent, KeyboardResultType, IBufferLine, IAttributeData, CoreMouseEventType, CoreMouseButton, CoreMouseAction } from 'common/Types'; import { evaluateKeyboardEvent } from 'common/input/Keyboard'; import { EventEmitter, IEvent } from 'common/EventEmitter'; import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine'; @@ -116,13 +116,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp public wraparoundMode: boolean; // defaults: xterm - true, vt100 - false public bracketedPasteMode: boolean; - // charset - // The current charset - public charset: ICharset; - public gcharset: number; - public glevel: number; - public charsets: ICharset[]; - // mouse properties public mouseEvents: CoreMouseEventType = CoreMouseEventType.NONE; public sendFocus: boolean; @@ -261,11 +254,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp this.bracketedPasteMode = false; // charset - this.charset = null; - this.gcharset = null; - this.glevel = 0; - // TODO: Can this be just []? - this.charsets = [null]; + this._coreService.softReset(); this.curAttrData = DEFAULT_ATTR_DATA.clone(); this._eraseAttrData = DEFAULT_ATTR_DATA.clone(); @@ -1307,27 +1296,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp return thirdLevelKey && (!ev.keyCode || ev.keyCode > 47); } - /** - * Set the G level of the terminal - * @param g - */ - public setgLevel(g: number): void { - this.glevel = g; - this.charset = this.charsets[g]; - } - - /** - * Set the charset for the given G level of the terminal - * @param g - * @param charset - */ - public setgCharset(g: number, charset: ICharset): void { - this.charsets[g] = charset; - if (this.glevel === g) { - this.charset = charset; - } - } - protected _keyUp(ev: KeyboardEvent): void { if (this._customKeyEventHandler && this._customKeyEventHandler(ev) === false) { return; diff --git a/src/TestUtils.test.ts b/src/TestUtils.test.ts index 84c0d0b75..8954ae838 100644 --- a/src/TestUtils.test.ts +++ b/src/TestUtils.test.ts @@ -201,10 +201,6 @@ export class MockInputHandlingTerminal implements IInputHandlingTerminal { options: ITerminalOptions = {}; cols: number; rows: number; - charset: { [key: string]: string; }; - gcharset: number; - glevel: number; - charsets: { [key: string]: string; }[]; applicationKeypad: boolean; applicationCursor: boolean; originMode: boolean; @@ -243,9 +239,6 @@ export class MockInputHandlingTerminal implements IInputHandlingTerminal { nextStop(x?: number): number { throw new Error('Method not implemented.'); } - setgLevel(g: number): void { - throw new Error('Method not implemented.'); - } eraseAttrData(): IAttributeData { throw new Error('Method not implemented.'); } @@ -264,9 +257,6 @@ export class MockInputHandlingTerminal implements IInputHandlingTerminal { is(term: string): boolean { throw new Error('Method not implemented.'); } - setgCharset(g: number, charset: { [key: string]: string; }): void { - throw new Error('Method not implemented.'); - } resize(x: number, y: number): void { throw new Error('Method not implemented.'); } @@ -279,9 +269,6 @@ export class MockInputHandlingTerminal implements IInputHandlingTerminal { showCursor(): void { throw new Error('Method not implemented.'); } - refresh(start: number, end: number): void { - throw new Error('Method not implemented.'); - } matchColor(r1: number, g1: number, b1: number): number { throw new Error('Method not implemented.'); } diff --git a/src/Types.d.ts b/src/Types.d.ts index 063331dde..3a3aef624 100644 --- a/src/Types.d.ts +++ b/src/Types.d.ts @@ -25,10 +25,6 @@ export interface IInputHandlingTerminal { options: ITerminalOptions; cols: number; rows: number; - charset: ICharset; - gcharset: number; - glevel: number; - charsets: ICharset[]; applicationKeypad: boolean; originMode: boolean; insertMode: boolean; @@ -49,10 +45,8 @@ export interface IInputHandlingTerminal { bell(): void; focus(): void; scroll(isWrapped?: boolean): void; - setgLevel(g: number): void; eraseAttrData(): IAttributeData; is(term: string): boolean; - setgCharset(g: number, charset: ICharset): void; resize(x: number, y: number): void; reset(): void; showCursor(): void; diff --git a/src/common/TestUtils.test.ts b/src/common/TestUtils.test.ts index 7e47d4b0a..96027804c 100644 --- a/src/common/TestUtils.test.ts +++ b/src/common/TestUtils.test.ts @@ -9,7 +9,7 @@ import { clone } from 'common/Clone'; import { DEFAULT_OPTIONS } from 'common/services/OptionsService'; import { IBufferSet, IBuffer } from 'common/buffer/Types'; import { BufferSet } from 'common/buffer/BufferSet'; -import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEventType } from 'common/Types'; +import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEventType, ICharsetModes, ICharset } from 'common/Types'; export class MockBufferService implements IBufferService { serviceBrand: any; @@ -47,11 +47,19 @@ export class MockCoreService implements ICoreService { isCursorHidden: boolean = false; isFocused: boolean = false; serviceBrand: any; + charsetModes: ICharsetModes = { + charset: undefined, + charsets: [], + glevel: 0 + }; decPrivateModes: IDecPrivateModes = {} as any; onData: IEvent = new EventEmitter().event; onUserInput: IEvent = new EventEmitter().event; onBinary: IEvent = new EventEmitter().event; reset(): void {} + softReset(): void {} + setgLevel(g: number): void {} + setgCharset(g: number, charset: ICharset): void {} triggerDataEvent(data: string, wasUserInput?: boolean): void {} triggerBinaryEvent(data: string): void {} } diff --git a/src/common/Types.d.ts b/src/common/Types.d.ts index 2dcc704bd..b8cb9b802 100644 --- a/src/common/Types.d.ts +++ b/src/common/Types.d.ts @@ -65,6 +65,12 @@ export interface ICharset { [key: string]: string; } +export interface ICharsetModes { + charset: ICharset | undefined; + glevel: number; + charsets: ICharset[]; +} + export type CharData = [number, string, number, number]; export type IColorRGB = [number, number, number]; diff --git a/src/common/services/CoreService.ts b/src/common/services/CoreService.ts index 35b61e847..af0d5f63e 100644 --- a/src/common/services/CoreService.ts +++ b/src/common/services/CoreService.ts @@ -5,7 +5,7 @@ import { ICoreService, ILogService, IOptionsService, IBufferService } from 'common/services/Services'; import { EventEmitter, IEvent } from 'common/EventEmitter'; -import { IDecPrivateModes } from 'common/Types'; +import { IDecPrivateModes, ICharset, ICharsetModes } from 'common/Types'; import { clone } from 'common/Clone'; const DEFAULT_DEC_PRIVATE_MODES: IDecPrivateModes = Object.freeze({ @@ -18,6 +18,11 @@ export class CoreService implements ICoreService { public isCursorInitialized: boolean = false; public isCursorHidden: boolean = false; public decPrivateModes: IDecPrivateModes; + public charsetModes: ICharsetModes = { + charset: undefined, + charsets: [], + glevel: 0 + }; private _onData = new EventEmitter(); public get onData(): IEvent { return this._onData.event; } @@ -40,6 +45,12 @@ export class CoreService implements ICoreService { this.decPrivateModes = clone(DEFAULT_DEC_PRIVATE_MODES); } + public softReset(): void { + this.charsetModes.charset = undefined; + this.charsetModes.charsets = []; + this.charsetModes.glevel = 0; + } + public triggerDataEvent(data: string, wasUserInput: boolean = false): void { // Prevents all events to pty process if stdin is disabled if (this._optionsService.options.disableStdin) { @@ -69,4 +80,16 @@ export class CoreService implements ICoreService { this._logService.debug(`sending binary "${data}"`, () => data.split('').map(e => e.charCodeAt(0))); this._onBinary.fire(data); } + + public setgLevel(g: number): void { + this.charsetModes.glevel = g; + this.charsetModes.charset = this.charsetModes.charsets[g]; + } + + public setgCharset(g: number, charset: ICharset): void { + this.charsetModes.charsets[g] = charset; + if (this.charsetModes.glevel === g) { + this.charsetModes.charset = charset; + } + } } diff --git a/src/common/services/Services.ts b/src/common/services/Services.ts index 2b284cd28..9e47be263 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -5,7 +5,7 @@ import { IEvent } from 'common/EventEmitter'; import { IBuffer, IBufferSet } from 'common/buffer/Types'; -import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEncoding, ICoreMouseProtocol, CoreMouseEventType } from 'common/Types'; +import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEncoding, ICoreMouseProtocol, CoreMouseEventType, ICharsetModes, ICharset } from 'common/Types'; import { createDecorator } from 'common/services/ServiceRegistry'; export const IBufferService = createDecorator('BufferService'); @@ -64,6 +64,9 @@ export interface ICoreService { */ isCursorInitialized: boolean; isCursorHidden: boolean; + + charsetModes: ICharsetModes; + readonly decPrivateModes: IDecPrivateModes; readonly onData: IEvent; @@ -71,6 +74,7 @@ export interface ICoreService { readonly onBinary: IEvent; reset(): void; + softReset(): void; /** * Triggers the onData event in the public API. @@ -87,6 +91,19 @@ export interface ICoreService { * @param data The data that is being emitted. */ triggerBinaryEvent(data: string): void; + + /** + * Set the G level of the terminal. + * @param g + */ + setgLevel(g: number): void; + + /** + * Set the charset for the given G level of the terminal. + * @param g + * @param charset + */ + setgCharset(g: number, charset: ICharset): void; } export const IDirtyRowService = createDecorator('DirtyRowService');