@@ -6,7 +6,7 @@
|
||||
import { IOptionsService, ITerminalOptions, FontWeight } from 'common/services/Services';
|
||||
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
||||
import { isMac } from 'common/Platform';
|
||||
import { CursorStyle } from 'common/Types';
|
||||
import { CursorStyle, IDisposable } from 'common/Types';
|
||||
import { Disposable } from 'common/Lifecycle';
|
||||
|
||||
export const DEFAULT_OPTIONS: Readonly<Required<ITerminalOptions>> = {
|
||||
@@ -58,7 +58,7 @@ export class OptionsService extends Disposable implements IOptionsService {
|
||||
public readonly rawOptions: Required<ITerminalOptions>;
|
||||
public options: Required<ITerminalOptions>;
|
||||
|
||||
private readonly _onOptionChange = this.register(new EventEmitter<string>());
|
||||
private readonly _onOptionChange = this.register(new EventEmitter<keyof ITerminalOptions>());
|
||||
public readonly onOptionChange = this._onOptionChange.event;
|
||||
|
||||
constructor(options: Partial<ITerminalOptions>) {
|
||||
@@ -82,6 +82,15 @@ export class OptionsService extends Disposable implements IOptionsService {
|
||||
this._setupOptions();
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
public onSpecificOptionChange<T extends keyof ITerminalOptions>(key: T, listener: (value: ITerminalOptions[T]) => any): IDisposable {
|
||||
return this.onOptionChange(eventKey => {
|
||||
if (eventKey === key) {
|
||||
listener(this.rawOptions[key]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private _setupOptions(): void {
|
||||
const getter = (propName: string): any => {
|
||||
if (!(propName in DEFAULT_OPTIONS)) {
|
||||
|
||||
@@ -182,9 +182,25 @@ export interface IOptionsService {
|
||||
* internally.
|
||||
*/
|
||||
readonly rawOptions: Required<ITerminalOptions>;
|
||||
|
||||
/**
|
||||
* Options as exposed through the public API, this property uses getters and setters with
|
||||
* validation which makes it safer but slower. {@link rawOptions} should be used for pretty much
|
||||
* all internal usage for performance reasons.
|
||||
*/
|
||||
readonly options: Required<ITerminalOptions>;
|
||||
|
||||
readonly onOptionChange: IEvent<string>;
|
||||
/**
|
||||
* Adds an event listener for when any option changes.
|
||||
*/
|
||||
readonly onOptionChange: IEvent<keyof ITerminalOptions>;
|
||||
|
||||
/**
|
||||
* Adds an event listener for when a specific option changes, this is a convenience method that is
|
||||
* preferred over {@link onOptionChange} when only a single option is being listened to.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
onSpecificOptionChange<T extends keyof ITerminalOptions>(key: T, listener: (arg1: ITerminalOptions[T]) => any): IDisposable;
|
||||
}
|
||||
|
||||
export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | number;
|
||||
|
||||
Reference in New Issue
Block a user