Move charset logic into core service

This commit is contained in:
Daniel Imms
2019-12-18 10:32:38 +11:00
parent a2297a5fa6
commit 05e1cd8478
8 changed files with 74 additions and 73 deletions
+24 -1
View File
@@ -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<string>();
public get onData(): IEvent<string> { 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;
}
}
}