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
+13 -11
View File
@@ -3,13 +3,13 @@
* @license MIT
*/
import { IBufferService, ICoreService, ILogService, IOptionsService, ITerminalOptions, IPartialTerminalOptions, IDirtyRowService, ICoreMouseService } from 'common/services/Services';
import { IBufferService, ICoreService, ILogService, IOptionsService, ITerminalOptions, IPartialTerminalOptions, IDirtyRowService, ICoreMouseService, ICharsetService } from 'common/services/Services';
import { IEvent, EventEmitter } from 'common/EventEmitter';
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, ICharsetModes, ICharset } from 'common/Types';
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEventType, ICharset } from 'common/Types';
export class MockBufferService implements IBufferService {
serviceBrand: any;
@@ -42,24 +42,26 @@ export class MockCoreMouseService implements ICoreMouseService {
}
}
export class MockCharsetService implements ICharsetService {
serviceBrand: any;
charset: ICharset | undefined;
glevel: number = 0;
charsets: readonly ICharset[] = [];
reset(): void {}
setgLevel(g: number): void {}
setgCharset(g: number, charset: ICharset): void {}
}
export class MockCoreService implements ICoreService {
serviceBrand: any;
isCursorInitialized: boolean = false;
isCursorHidden: boolean = false;
isFocused: boolean = false;
serviceBrand: any;
charsetModes: ICharsetModes = {
charset: undefined,
charsets: [],
glevel: 0
};
decPrivateModes: IDecPrivateModes = {} as any;
onData: IEvent<string> = new EventEmitter<string>().event;
onUserInput: IEvent<void> = new EventEmitter<void>().event;
onBinary: IEvent<string> = new EventEmitter<string>().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 {}
}
+1 -7
View File
@@ -62,13 +62,7 @@ export interface IKeyboardResult {
}
export interface ICharset {
[key: string]: string;
}
export interface ICharsetModes {
charset: ICharset | undefined;
glevel: number;
charsets: ICharset[];
[key: string]: string | undefined;
}
export type CharData = [number, string, number, number];
+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.