Move charset logic into core service
This commit is contained in:
@@ -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<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 {}
|
||||
}
|
||||
|
||||
Vendored
+6
@@ -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];
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<IBufferService>('BufferService');
|
||||
@@ -64,6 +64,9 @@ export interface ICoreService {
|
||||
*/
|
||||
isCursorInitialized: boolean;
|
||||
isCursorHidden: boolean;
|
||||
|
||||
charsetModes: ICharsetModes;
|
||||
|
||||
readonly decPrivateModes: IDecPrivateModes;
|
||||
|
||||
readonly onData: IEvent<string>;
|
||||
@@ -71,6 +74,7 @@ export interface ICoreService {
|
||||
readonly onBinary: IEvent<string>;
|
||||
|
||||
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<IDirtyRowService>('DirtyRowService');
|
||||
|
||||
Reference in New Issue
Block a user