mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
simplify options
This commit is contained in:
+38
-6
@@ -18,11 +18,10 @@ import { IParsingState, IDcsHandler, IEscapeSequenceParser, IParams, IFunctionId
|
||||
import { NULL_CELL_CODE, NULL_CELL_WIDTH, Attributes, FgFlags, BgFlags, Content } from 'common/buffer/Constants';
|
||||
import { CellData } from 'common/buffer/CellData';
|
||||
import { AttributeData } from 'common/buffer/AttributeData';
|
||||
import { IAttributeData, IDisposable } from 'common/Types';
|
||||
import { IAttributeData, IDisposable, IWindowOptions } from 'common/Types';
|
||||
import { ICoreService, IBufferService, IOptionsService, ILogService, IDirtyRowService, ICoreMouseService } from 'common/services/Services';
|
||||
import { OscHandler } from 'common/parser/OscParser';
|
||||
import { DcsHandler } from 'common/parser/DcsParser';
|
||||
import { hasWindowOption, WindowOptions } from 'common/WindowOptions';
|
||||
|
||||
/**
|
||||
* Map collect to glevel. Used in `selectCharset`.
|
||||
@@ -39,6 +38,39 @@ const MAX_PARSEBUFFER_LENGTH = 131072;
|
||||
*/
|
||||
const STACK_LIMIT = 10;
|
||||
|
||||
// map params to window option
|
||||
function paramToWindowOption(n: number, opts: IWindowOptions): boolean {
|
||||
if (n > 24) {
|
||||
return opts.setWinLines || false;
|
||||
}
|
||||
switch (n) {
|
||||
case 1: return opts.restoreWin || false;
|
||||
case 2: return opts.minimizeWin || false;
|
||||
case 3: return opts.setWinPosition || false;
|
||||
case 4: return opts.setWinSizePixels || false;
|
||||
case 5: return opts.raiseWin || false;
|
||||
case 6: return opts.lowerWin || false;
|
||||
case 7: return opts.refreshWin || false;
|
||||
case 8: return opts.setWinSizeChars || false;
|
||||
case 9: return opts.maximizeWin || false;
|
||||
case 10: return opts.fullscreenWin || false;
|
||||
case 11: return opts.getWinState || false;
|
||||
case 13: return opts.getWinPosition || false;
|
||||
case 14: return opts.getWinSizePixels || false;
|
||||
case 15: return opts.getScreenSizePixels || false;
|
||||
case 16: return opts.getCellSizePixels || false;
|
||||
case 18: return opts.getWinSizeChars || false;
|
||||
case 19: return opts.getScreenSizeChars || false;
|
||||
case 20: return opts.getIconTitle || false;
|
||||
case 21: return opts.getWinTitle || false;
|
||||
case 22: return opts.pushTitle || false;
|
||||
case 23: return opts.popTitle || false;
|
||||
case 24: return opts.setWinLines || false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* DCS subparser implementations
|
||||
@@ -521,7 +553,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
if (id.final === 't' && !id.prefix && !id.intermediates) {
|
||||
// security: always check whether window option is allowed
|
||||
return this._parser.addCsiHandler(id, params => {
|
||||
if (!hasWindowOption(params.params[0], this._optionsService.windowOptions)) {
|
||||
if (!paramToWindowOption(params.params[0], this._optionsService.options.windowOptions)) {
|
||||
return true;
|
||||
}
|
||||
return callback(params);
|
||||
@@ -1422,7 +1454,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* This is only active if 'SetWinLines' (24) is listed
|
||||
* in `options.windowsOptions`.
|
||||
*/
|
||||
if (this._optionsService.windowOptions & WindowOptions.setWinLines) {
|
||||
if (this._optionsService.options.windowOptions.setWinLines) {
|
||||
this._terminal.resize(132, this._bufferService.rows);
|
||||
this._terminal.reset();
|
||||
}
|
||||
@@ -1609,7 +1641,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* This is only active if 'SetWinLines' (24) is listed
|
||||
* in `options.windowsOptions`.
|
||||
*/
|
||||
if (this._optionsService.windowOptions & WindowOptions.setWinLines) {
|
||||
if (this._optionsService.options.windowOptions.setWinLines) {
|
||||
this._terminal.resize(80, this._bufferService.rows);
|
||||
this._terminal.reset();
|
||||
}
|
||||
@@ -2083,7 +2115,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Ps >= 24 not implemented
|
||||
*/
|
||||
public windowOptions(params: IParams): void {
|
||||
if (!hasWindowOption(params.params[0], this._optionsService.windowOptions)) {
|
||||
if (!paramToWindowOption(params.params[0], this._optionsService.options.windowOptions)) {
|
||||
return;
|
||||
}
|
||||
const second = (params.length > 1) ? params.params[1] : 0;
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
import { IWindowOptions } from 'common/Types';
|
||||
|
||||
export const enum WindowOptions {
|
||||
restoreWin = 1 << 1,
|
||||
minimizeWin = 1 << 2,
|
||||
setWinPosition = 1 << 3,
|
||||
setWinSizePixels = 1 << 4,
|
||||
raiseWin = 1 << 5,
|
||||
lowerWin = 1 << 6,
|
||||
refreshWin = 1 << 7,
|
||||
setWinSizeChars = 1 << 8,
|
||||
maximizeWin = 1 << 9,
|
||||
fullscreenWin = 1 << 10,
|
||||
getWinState = 1 << 11,
|
||||
getWinPosition = 1 << 13,
|
||||
getWinSizePixels = 1 << 14,
|
||||
getScreenSizePixels = 1 << 15, // note: name not in xterm
|
||||
getCellSizePixels = 1 << 16, // note: name not in xterm
|
||||
getWinSizeChars = 1 << 18,
|
||||
getScreenSizeChars = 1 << 19,
|
||||
getIconTitle = 1 << 20,
|
||||
getWinTitle = 1 << 21,
|
||||
pushTitle = 1 << 22,
|
||||
popTitle = 1 << 23,
|
||||
setWinLines = 1 << 24 // any param >= 24, also handles DECCOLM
|
||||
}
|
||||
|
||||
export function hasWindowOption(n: number, opts: WindowOptions): boolean {
|
||||
return !!(opts & (1 << Math.min(n, 24)));
|
||||
}
|
||||
|
||||
export function getWindowOptions(opts: WindowOptions): IWindowOptions {
|
||||
return {
|
||||
restoreWin: !!(opts & WindowOptions.restoreWin),
|
||||
minimizeWin: !!(opts & WindowOptions.minimizeWin),
|
||||
setWinPosition: !!(opts & WindowOptions.setWinPosition),
|
||||
setWinSizePixels: !!(opts & WindowOptions.setWinSizePixels),
|
||||
raiseWin: !!(opts & WindowOptions.raiseWin),
|
||||
lowerWin: !!(opts & WindowOptions.lowerWin),
|
||||
refreshWin: !!(opts & WindowOptions.refreshWin),
|
||||
setWinSizeChars: !!(opts & WindowOptions.setWinSizeChars),
|
||||
maximizeWin: !!(opts & WindowOptions.maximizeWin),
|
||||
fullscreenWin: !!(opts & WindowOptions.fullscreenWin),
|
||||
getWinState: !!(opts & WindowOptions.getWinState),
|
||||
getWinPosition: !!(opts & WindowOptions.getWinPosition),
|
||||
getWinSizePixels: !!(opts & WindowOptions.getWinSizePixels),
|
||||
getScreenSizePixels: !!(opts & WindowOptions.getScreenSizePixels),
|
||||
getCellSizePixels: !!(opts & WindowOptions.getCellSizePixels),
|
||||
getWinSizeChars: !!(opts & WindowOptions.getWinSizeChars),
|
||||
getScreenSizeChars: !!(opts & WindowOptions.getScreenSizeChars),
|
||||
getIconTitle: !!(opts & WindowOptions.getIconTitle),
|
||||
getWinTitle: !!(opts & WindowOptions.getWinTitle),
|
||||
pushTitle: !!(opts & WindowOptions.pushTitle),
|
||||
popTitle: !!(opts & WindowOptions.popTitle),
|
||||
setWinLines: !!(opts & WindowOptions.setWinLines)
|
||||
};
|
||||
}
|
||||
|
||||
export function setWindowOptions(v: IWindowOptions & {[key: string]: boolean}, opts: WindowOptions): WindowOptions {
|
||||
for (const optionName in v) {
|
||||
const value = v[optionName];
|
||||
switch (optionName) {
|
||||
case 'restoreWin': opts = value ? opts | WindowOptions.restoreWin : opts & ~WindowOptions.restoreWin; break;
|
||||
case 'minimizeWin': opts = value ? opts | WindowOptions.minimizeWin : opts & ~WindowOptions.minimizeWin; break;
|
||||
case 'setWinPosition': opts = value ? opts | WindowOptions.setWinPosition : opts & ~WindowOptions.setWinPosition; break;
|
||||
case 'setWinSizePixels': opts = value ? opts | WindowOptions.setWinSizePixels : opts & ~WindowOptions.setWinSizePixels; break;
|
||||
case 'raiseWin': opts = value ? opts | WindowOptions.raiseWin : opts & ~WindowOptions.raiseWin; break;
|
||||
case 'lowerWin': opts = value ? opts | WindowOptions.lowerWin : opts & ~WindowOptions.lowerWin; break;
|
||||
case 'refreshWin': opts = value ? opts | WindowOptions.refreshWin : opts & ~WindowOptions.refreshWin; break;
|
||||
case 'setWinSizeChars': opts = value ? opts | WindowOptions.setWinSizeChars : opts & ~WindowOptions.setWinSizeChars; break;
|
||||
case 'maximizeWin': opts = value ? opts | WindowOptions.maximizeWin : opts & ~WindowOptions.maximizeWin; break;
|
||||
case 'fullscreenWin': opts = value ? opts | WindowOptions.fullscreenWin : opts & ~WindowOptions.fullscreenWin; break;
|
||||
case 'getWinState': opts = value ? opts | WindowOptions.getWinState : opts & ~WindowOptions.getWinState; break;
|
||||
case 'getWinPosition': opts = value ? opts | WindowOptions.getWinPosition : opts & ~WindowOptions.getWinPosition; break;
|
||||
case 'getWinSizePixels': opts = value ? opts | WindowOptions.getWinSizePixels : opts & ~WindowOptions.getWinSizePixels; break;
|
||||
case 'getScreenSizePixels': opts = value ? opts | WindowOptions.getScreenSizePixels : opts & ~WindowOptions.getScreenSizePixels; break;
|
||||
case 'getCellSizePixels': opts = value ? opts | WindowOptions.getCellSizePixels : opts & ~WindowOptions.getCellSizePixels; break;
|
||||
case 'getWinSizeChars': opts = value ? opts | WindowOptions.getWinSizeChars : opts & ~WindowOptions.getWinSizeChars; break;
|
||||
case 'getScreenSizeChars': opts = value ? opts | WindowOptions.getScreenSizeChars : opts & ~WindowOptions.getScreenSizeChars; break;
|
||||
case 'getIconTitle': opts = value ? opts | WindowOptions.getIconTitle : opts & ~WindowOptions.getIconTitle; break;
|
||||
case 'getWinTitle': opts = value ? opts | WindowOptions.getWinTitle : opts & ~WindowOptions.getWinTitle; break;
|
||||
case 'pushTitle': opts = value ? opts | WindowOptions.pushTitle : opts & ~WindowOptions.pushTitle; break;
|
||||
case 'popTitle': opts = value ? opts | WindowOptions.popTitle : opts & ~WindowOptions.popTitle; break;
|
||||
case 'setWinLines': opts = value ? opts | WindowOptions.setWinLines : opts & ~WindowOptions.setWinLines; break;
|
||||
default: throw new Error(`unknown WindowOption "${optionName}"`);
|
||||
}
|
||||
}
|
||||
return opts;
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import { IOptionsService, ITerminalOptions, IPartialTerminalOptions } from 'comm
|
||||
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
||||
import { isMac } from 'common/Platform';
|
||||
import { clone } from 'common/Clone';
|
||||
import { setWindowOptions, getWindowOptions, WindowOptions } from 'common/WindowOptions';
|
||||
|
||||
// Source: https://freesound.org/people/altemark/sounds/45759/
|
||||
// This sound is released under the Creative Commons Attribution 3.0 Unported
|
||||
@@ -65,7 +64,6 @@ export class OptionsService implements IOptionsService {
|
||||
serviceBrand: any;
|
||||
|
||||
public options: ITerminalOptions;
|
||||
public windowOptions: WindowOptions = 0;
|
||||
|
||||
private _onOptionChange = new EventEmitter<string>();
|
||||
public get onOptionChange(): IEvent<string> { return this._onOptionChange.event; }
|
||||
@@ -78,9 +76,6 @@ export class OptionsService implements IOptionsService {
|
||||
this.options[k] = newValue;
|
||||
}
|
||||
});
|
||||
if (options.windowOptions) {
|
||||
this.windowOptions = setWindowOptions(options.windowOptions as any, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public setOption(key: string, value: any): void {
|
||||
@@ -135,8 +130,6 @@ export class OptionsService implements IOptionsService {
|
||||
throw new Error(`${key} cannot be less than or equal to 0, value: ${value}`);
|
||||
}
|
||||
break;
|
||||
case 'windowOptions':
|
||||
this.windowOptions = setWindowOptions(value, this.windowOptions);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -145,9 +138,6 @@ export class OptionsService implements IOptionsService {
|
||||
if (!(key in DEFAULT_OPTIONS)) {
|
||||
throw new Error(`No option with key "${key}"`);
|
||||
}
|
||||
if (key === 'windowOptions') {
|
||||
return getWindowOptions(this.windowOptions);
|
||||
}
|
||||
return this.options[key];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import { IEvent } from 'common/EventEmitter';
|
||||
import { IBuffer, IBufferSet } from 'common/buffer/Types';
|
||||
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEncoding, ICoreMouseProtocol, CoreMouseEventType, IWindowOptions } from 'common/Types';
|
||||
import { createDecorator } from 'common/services/ServiceRegistry';
|
||||
import { WindowOptions } from 'common/WindowOptions';
|
||||
|
||||
export const IBufferService = createDecorator<IBufferService>('BufferService');
|
||||
export interface IBufferService {
|
||||
@@ -167,7 +166,6 @@ export interface IOptionsService {
|
||||
serviceBrand: any;
|
||||
|
||||
readonly options: ITerminalOptions;
|
||||
readonly windowOptions: WindowOptions;
|
||||
|
||||
readonly onOptionChange: IEvent<string>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user