Clean up
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
import { assert } from 'chai';
|
||||
import { InputHandler } from 'common/InputHandler';
|
||||
import { IBufferLine, IAttributeData, IColorEvent, ColorIndex, ColorRequestType, SpecialColorIndex, IClipboardEvent, ClipboardEventType } from 'common/Types';
|
||||
import { IBufferLine, IAttributeData, IColorEvent, ColorIndex, ColorRequestType, SpecialColorIndex } from 'common/Types';
|
||||
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
|
||||
import { CellData } from 'common/buffer/CellData';
|
||||
import { Attributes, BgFlags, UnderlineStyle } from 'common/buffer/Constants';
|
||||
@@ -17,7 +17,6 @@ import { DEFAULT_OPTIONS } from 'common/services/OptionsService';
|
||||
import { clone } from 'common/Clone';
|
||||
import { BufferService } from 'common/services/BufferService';
|
||||
import { CoreService } from 'common/services/CoreService';
|
||||
import { ClipboardSelectionType } from '@xterm/xterm';
|
||||
|
||||
function getCursor(bufferService: IBufferService): number[] {
|
||||
return [
|
||||
@@ -1982,88 +1981,6 @@ describe('InputHandler', () => {
|
||||
assert.deepEqual(stack, [[{ type: ColorRequestType.SET, index: 0, color: [170, 187, 204] }, { type: ColorRequestType.SET, index: 123, color: [0, 17, 34] }]]);
|
||||
stack.length = 0;
|
||||
});
|
||||
describe('52: manipulate selection data', async () => {
|
||||
const testDataRaw = 'hello world';
|
||||
const testDataB64 = 'aGVsbG8gd29ybGQ=';
|
||||
optionsService.options.allowClipboardAccess = true;
|
||||
const stack: IClipboardEvent[] = [];
|
||||
inputHandler.onClipboard(ev => stack.push(ev));
|
||||
await inputHandler.parseP(`\x1b]52;c;\x07`);
|
||||
await inputHandler.parseP(`\x1b]52;c;${testDataRaw}\x07`);
|
||||
await inputHandler.parseP(`\x1b]52;c;${testDataB64}\x07`);
|
||||
await inputHandler.parseP(`\x1b]52;c;${testDataB64}invalid\x07`);
|
||||
await inputHandler.parseP(`\x1b]52;c;!\x07`);
|
||||
await inputHandler.parseP(`\x1b]52;c;?\x07`);
|
||||
await inputHandler.parseP(`\x1b]52;p;\x07`);
|
||||
await inputHandler.parseP(`\x1b]52;p;${testDataRaw}\x07`);
|
||||
await inputHandler.parseP(`\x1b]52;p;${testDataB64}\x07`);
|
||||
await inputHandler.parseP(`\x1b]52;p;${testDataB64}invalid\x07`);
|
||||
await inputHandler.parseP(`\x1b]52;p;!\x07`);
|
||||
await inputHandler.parseP(`\x1b]52;p;?\x07`);
|
||||
assert.deepEqual(stack, [
|
||||
{
|
||||
type: ClipboardEventType.SET,
|
||||
selection: ClipboardSelectionType.SYSTEM,
|
||||
data: ''
|
||||
},
|
||||
{
|
||||
type: ClipboardEventType.SET,
|
||||
selection: ClipboardSelectionType.SYSTEM,
|
||||
data: testDataRaw
|
||||
},
|
||||
{
|
||||
type: ClipboardEventType.SET,
|
||||
selection: ClipboardSelectionType.SYSTEM,
|
||||
data: testDataB64
|
||||
},
|
||||
{
|
||||
type: ClipboardEventType.SET,
|
||||
selection: ClipboardSelectionType.SYSTEM,
|
||||
data: testDataB64+'invalid'
|
||||
},
|
||||
{
|
||||
type: ClipboardEventType.SET,
|
||||
selection: ClipboardSelectionType.SYSTEM,
|
||||
data: '!'
|
||||
},
|
||||
{
|
||||
type: ClipboardEventType.REPORT,
|
||||
selection: ClipboardSelectionType.SYSTEM,
|
||||
data: '?'
|
||||
},
|
||||
{
|
||||
type: ClipboardEventType.SET,
|
||||
selection: ClipboardSelectionType.PRIMARY,
|
||||
data: ''
|
||||
},
|
||||
{
|
||||
type: ClipboardEventType.SET,
|
||||
selection: ClipboardSelectionType.PRIMARY,
|
||||
data: testDataRaw
|
||||
},
|
||||
{
|
||||
type: ClipboardEventType.SET,
|
||||
selection: ClipboardSelectionType.PRIMARY,
|
||||
data: testDataB64
|
||||
},
|
||||
{
|
||||
type: ClipboardEventType.SET,
|
||||
selection: ClipboardSelectionType.PRIMARY,
|
||||
data: testDataB64+'invalid'
|
||||
},
|
||||
{
|
||||
type: ClipboardEventType.SET,
|
||||
selection: ClipboardSelectionType.PRIMARY,
|
||||
data: '!'
|
||||
},
|
||||
{
|
||||
type: ClipboardEventType.REPORT,
|
||||
selection: ClipboardSelectionType.PRIMARY,
|
||||
data: '?'
|
||||
}
|
||||
]);
|
||||
stack.length = 0;
|
||||
});
|
||||
it('104: restore events', async () => {
|
||||
const stack: IColorEvent[] = [];
|
||||
inputHandler.onColor(ev => stack.push(ev));
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { IInputHandler, IAttributeData, IDisposable, IWindowOptions, IColorEvent, IParseStack, ColorIndex, ColorRequestType, SpecialColorIndex, IClipboardEvent, ClipboardEventType } from 'common/Types';
|
||||
import { IInputHandler, IAttributeData, IDisposable, IWindowOptions, IColorEvent, IParseStack, ColorIndex, ColorRequestType, SpecialColorIndex } from 'common/Types';
|
||||
import { C0, C1 } from 'common/data/EscapeSequences';
|
||||
import { CHARSETS, DEFAULT_CHARSET } from 'common/data/Charsets';
|
||||
import { EscapeSequenceParser } from 'common/parser/EscapeSequenceParser';
|
||||
@@ -22,7 +22,6 @@ import { OscHandler } from 'common/parser/OscParser';
|
||||
import { DcsHandler } from 'common/parser/DcsParser';
|
||||
import { IBuffer } from 'common/buffer/Types';
|
||||
import { parseColor } from 'common/input/XParseColor';
|
||||
import { ClipboardSelectionType } from '@xterm/xterm';
|
||||
|
||||
/**
|
||||
* Map collect to glevel. Used in `selectCharset`.
|
||||
@@ -160,8 +159,6 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
public readonly onTitleChange = this._onTitleChange.event;
|
||||
private readonly _onColor = this.register(new EventEmitter<IColorEvent>());
|
||||
public readonly onColor = this._onColor.event;
|
||||
private readonly _onClipboard = this.register(new EventEmitter<IClipboardEvent>());
|
||||
public readonly onClipboard = this._onClipboard.event;
|
||||
|
||||
private _parseStack: IParseStack = {
|
||||
paused: false,
|
||||
@@ -323,7 +320,6 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
// 50 - Set Font to Pt.
|
||||
// 51 - reserved for Emacs shell.
|
||||
// 52 - Manipulate Selection Data.
|
||||
this._parser.registerOscHandler(52, new OscHandler(data => this.setOrReportClipboard(data)));
|
||||
// 104 ; c - Reset Color Number c.
|
||||
this._parser.registerOscHandler(104, new OscHandler(data => this.restoreIndexedColor(data)));
|
||||
// 105 ; c - Reset Special Color Number c.
|
||||
@@ -3081,60 +3077,6 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
return this._setOrReportSpecialColor(data, 2);
|
||||
}
|
||||
|
||||
private _setOrReportClipboard(data: string): boolean {
|
||||
if (!this._optionsService.options.allowClipboardAccess) {
|
||||
return true;
|
||||
}
|
||||
const args = data.split(';');
|
||||
if (args.length < 2) {
|
||||
return true;
|
||||
}
|
||||
const pc = args[0];
|
||||
const pd = args[1];
|
||||
if (pd.length === 0) {
|
||||
return true;
|
||||
}
|
||||
switch (pc) {
|
||||
case ClipboardSelectionType.SYSTEM:
|
||||
case ClipboardSelectionType.PRIMARY:
|
||||
this._onClipboard.fire({
|
||||
type: pd === '?' ? ClipboardEventType.REPORT : ClipboardEventType.SET,
|
||||
selection: pc,
|
||||
data: pd
|
||||
});
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* OSC 52 ; <selection name> ; <base64 data>|<?> ST - set or query selection and clipboard data
|
||||
*
|
||||
* Test case:
|
||||
*
|
||||
* ```sh
|
||||
* printf "\e]52;c;%s\a" "$(echo -n "Hello, World" | base64)"
|
||||
* ```
|
||||
*
|
||||
* @vt: #Y OSC 52 "Manipulate Selection Data" "OSC 52 ; Pc ; Pd BEL" "Set or query selection and clipboard data."
|
||||
* Pc is the selection name. Can be one of:
|
||||
* - `c` - clipboard
|
||||
* - `p` - primary
|
||||
* - `q` - secondary
|
||||
* - `s` - select
|
||||
* - `0-7` - cut-buffers 0-7
|
||||
*
|
||||
* Only the `c` selection (clipboard) is supported by xterm.js. The browser
|
||||
* Clipboard API only supports the clipboard selection.
|
||||
*
|
||||
* Pd is the base64 encoded data.
|
||||
* If Pd is `?`, the terminal returns the current clipboard contents.
|
||||
* If Pd is neither base64 encoded nor `?`, then the clipboard is cleared.
|
||||
*/
|
||||
public setOrReportClipboard(data: string): boolean {
|
||||
return this._setOrReportClipboard(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* OSC 104 ; <num> ST - restore ANSI color <num>
|
||||
*
|
||||
|
||||
Vendored
+1
-13
@@ -9,7 +9,7 @@ import { Attributes, UnderlineStyle } from 'common/buffer/Constants'; // eslint-
|
||||
import { IBufferSet } from 'common/buffer/Types';
|
||||
import { IParams } from 'common/parser/Types';
|
||||
import { ICoreMouseService, ICoreService, IOptionsService, IUnicodeService } from 'common/services/Services';
|
||||
import { ClipboardSelectionType as ClipboardSelectionType, IFunctionIdentifier, ITerminalOptions as IPublicTerminalOptions } from '@xterm/xterm';
|
||||
import { IFunctionIdentifier, ITerminalOptions as IPublicTerminalOptions } from '@xterm/xterm';
|
||||
|
||||
export interface ICoreTerminal {
|
||||
coreMouseService: ICoreMouseService;
|
||||
@@ -447,17 +447,6 @@ export interface IColorRestoreRequest {
|
||||
}
|
||||
export type IColorEvent = (IColorReportRequest | IColorSetRequest | IColorRestoreRequest)[];
|
||||
|
||||
export const enum ClipboardEventType {
|
||||
REPORT = 0,
|
||||
SET = 1
|
||||
}
|
||||
|
||||
export interface IClipboardEvent {
|
||||
type: ClipboardEventType;
|
||||
selection: ClipboardSelectionType;
|
||||
data: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the parser and handles actions generated by the parser.
|
||||
*/
|
||||
@@ -527,7 +516,6 @@ export interface IInputHandler {
|
||||
/** OSC 10 */ setOrReportFgColor(data: string): boolean;
|
||||
/** OSC 11 */ setOrReportBgColor(data: string): boolean;
|
||||
/** OSC 12 */ setOrReportCursorColor(data: string): boolean;
|
||||
/** OSC 52 */ setOrReportClipboard(data: string): boolean;
|
||||
/** OSC 104 */ restoreIndexedColor(data: string): boolean;
|
||||
/** OSC 110 */ restoreFgColor(data: string): boolean;
|
||||
/** OSC 111 */ restoreBgColor(data: string): boolean;
|
||||
|
||||
@@ -54,8 +54,7 @@ export const DEFAULT_OPTIONS: Readonly<Required<ITerminalOptions>> = {
|
||||
convertEol: false,
|
||||
termName: 'xterm',
|
||||
cancelEvents: false,
|
||||
overviewRulerWidth: 0,
|
||||
allowClipboardAccess: false
|
||||
overviewRulerWidth: 0
|
||||
};
|
||||
|
||||
const FONT_WEIGHT_OPTIONS: Extract<FontWeight, string>[] = ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'];
|
||||
|
||||
@@ -206,7 +206,6 @@ export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '50
|
||||
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'off';
|
||||
|
||||
export interface ITerminalOptions {
|
||||
allowClipboardAccess?: boolean;
|
||||
allowProposedApi?: boolean;
|
||||
allowTransparency?: boolean;
|
||||
altClickMovesCursor?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user