Move charset into own service

This commit is contained in:
Daniel Imms
2019-12-18 10:53:05 +11:00
parent 05e1cd8478
commit 224fb5c6a2
8 changed files with 94 additions and 75 deletions
+33
View File
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/
import { ICharsetService } from 'common/services/Services';
import { ICharset } from 'common/Types';
export class CharsetService implements ICharsetService {
serviceBrand: any;
public charset: ICharset | undefined;
public charsets: ICharset[] = [];
public glevel: number = 0;
public reset(): void {
this.charset = undefined;
this.charsets = [];
this.glevel = 0;
}
public setgLevel(g: number): void {
this.glevel = g;
this.charset = this.charsets[g];
}
public setgCharset(g: number, charset: ICharset): void {
this.charsets[g] = charset;
if (this.glevel === g) {
this.charset = charset;
}
}
}
+1 -24
View File
@@ -5,7 +5,7 @@
import { ICoreService, ILogService, IOptionsService, IBufferService } from 'common/services/Services';
import { EventEmitter, IEvent } from 'common/EventEmitter';
import { IDecPrivateModes, ICharset, ICharsetModes } from 'common/Types';
import { IDecPrivateModes, ICharset } from 'common/Types';
import { clone } from 'common/Clone';
const DEFAULT_DEC_PRIVATE_MODES: IDecPrivateModes = Object.freeze({
@@ -18,11 +18,6 @@ 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; }
@@ -45,12 +40,6 @@ 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) {
@@ -80,16 +69,4 @@ 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;
}
}
}
+12 -4
View File
@@ -5,7 +5,7 @@
import { IEvent } from 'common/EventEmitter';
import { IBuffer, IBufferSet } from 'common/buffer/Types';
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEncoding, ICoreMouseProtocol, CoreMouseEventType, ICharsetModes, ICharset } from 'common/Types';
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEncoding, ICoreMouseProtocol, CoreMouseEventType, ICharset } from 'common/Types';
import { createDecorator } from 'common/services/ServiceRegistry';
export const IBufferService = createDecorator<IBufferService>('BufferService');
@@ -65,8 +65,6 @@ export interface ICoreService {
isCursorInitialized: boolean;
isCursorHidden: boolean;
charsetModes: ICharsetModes;
readonly decPrivateModes: IDecPrivateModes;
readonly onData: IEvent<string>;
@@ -74,7 +72,6 @@ export interface ICoreService {
readonly onBinary: IEvent<string>;
reset(): void;
softReset(): void;
/**
* Triggers the onData event in the public API.
@@ -91,6 +88,17 @@ export interface ICoreService {
* @param data The data that is being emitted.
*/
triggerBinaryEvent(data: string): void;
}
export const ICharsetService = createDecorator<ICharsetService>('CharsetService');
export interface ICharsetService {
serviceBrand: any;
charset: ICharset | undefined;
readonly glevel: number;
readonly charsets: ReadonlyArray<ICharset>;
reset(): void;
/**
* Set the G level of the terminal.