Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser hooks #2346

Merged
merged 34 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d8364d7
remove null type from dcsHandler
jerch Jul 24, 2019
f626e1c
fix OSC parsing
jerch Jul 25, 2019
c87b3fd
integration test for addOscHandler
jerch Jul 25, 2019
1f4dde6
remove experimental from addCsiHandler
jerch Jul 25, 2019
f985c30
add addEscHandler
jerch Jul 25, 2019
4133115
Merge branch 'master' into parser_hooks
Tyriar Jul 25, 2019
6606024
support for multiple DCS handler
jerch Jul 25, 2019
229a7ec
Merge branch 'parser_hooks' of github.com:jerch/xterm.js into parser_…
jerch Jul 25, 2019
c9b7aef
reset internal state on unhook
jerch Jul 26, 2019
82aaef2
dcs parser tests
jerch Jul 26, 2019
a9b2728
add DCS interface, payload limits for DCS/OSC
jerch Jul 26, 2019
bffa785
test cases for payload limits
jerch Jul 26, 2019
0a2d9a2
addOscHandler integration test
jerch Jul 26, 2019
0106bdc
parser tests for addDcsHandler
jerch Jul 26, 2019
d78c062
Merge branch 'master' into parser_hooks
jerch Jul 26, 2019
812fc5e
register functions by prefix/intermediate/final bytes
jerch Jul 31, 2019
83a1340
abort and cleanup subparsers for CAN and SUB
jerch Jul 31, 2019
7252a59
cleanup parser rules and docs
jerch Jul 31, 2019
bbd7275
make linter happy
jerch Jul 31, 2019
4e8a1c5
Merge remote-tracking branch 'upstream/master' into parser_hooks
jerch Aug 4, 2019
2a533e7
map DECEL back to eraseInLine
jerch Aug 4, 2019
a97742c
Merge branch 'master' into parser_hooks
jerch Aug 8, 2019
20fa447
namespace parser related stuff
jerch Aug 8, 2019
1286eb6
rename to OscHandler and DcsHandler
jerch Aug 8, 2019
0469e27
cache ParserApi, remove namespace
jerch Aug 8, 2019
e58a84d
Merge branch 'master' into parser_hooks
Tyriar Aug 10, 2019
f677516
better interfaces, cleanup
jerch Aug 11, 2019
d05d6e6
Merge branch 'master' into parser_hooks
Tyriar Aug 11, 2019
b353839
cleanup interfaces
jerch Aug 11, 2019
7c47faf
Merge branch 'parser_hooks' of github.com:jerch/xterm.js into parser_…
jerch Aug 11, 2019
3a5d0bd
fix escHandlers type and disposing
jerch Aug 11, 2019
a2c266a
rename handler type aliases to XyType to avoid ambiguity with class b…
jerch Aug 11, 2019
29a6f3f
Merge branch 'master' into parser_hooks
jerch Aug 16, 2019
1c20057
add parser property to interface
jerch Aug 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/InputHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,54 +53,52 @@ describe('InputHandler', () => {
it('should call Terminal.setOption with correct params', () => {
const optionsService = new MockOptionsService();
const inputHandler = new InputHandler(new MockInputHandlingTerminal(), new MockBufferService(80, 30), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), optionsService);
const collect = ' ';

inputHandler.setCursorStyle(Params.fromArray([0]), collect);
inputHandler.setCursorStyle(Params.fromArray([0]));
assert.equal(optionsService.options['cursorStyle'], 'block');
assert.equal(optionsService.options['cursorBlink'], true);

optionsService.options = clone(DEFAULT_OPTIONS);
inputHandler.setCursorStyle(Params.fromArray([1]), collect);
inputHandler.setCursorStyle(Params.fromArray([1]));
assert.equal(optionsService.options['cursorStyle'], 'block');
assert.equal(optionsService.options['cursorBlink'], true);

optionsService.options = clone(DEFAULT_OPTIONS);
inputHandler.setCursorStyle(Params.fromArray([2]), collect);
inputHandler.setCursorStyle(Params.fromArray([2]));
assert.equal(optionsService.options['cursorStyle'], 'block');
assert.equal(optionsService.options['cursorBlink'], false);

optionsService.options = clone(DEFAULT_OPTIONS);
inputHandler.setCursorStyle(Params.fromArray([3]), collect);
inputHandler.setCursorStyle(Params.fromArray([3]));
assert.equal(optionsService.options['cursorStyle'], 'underline');
assert.equal(optionsService.options['cursorBlink'], true);

optionsService.options = clone(DEFAULT_OPTIONS);
inputHandler.setCursorStyle(Params.fromArray([4]), collect);
inputHandler.setCursorStyle(Params.fromArray([4]));
assert.equal(optionsService.options['cursorStyle'], 'underline');
assert.equal(optionsService.options['cursorBlink'], false);

optionsService.options = clone(DEFAULT_OPTIONS);
inputHandler.setCursorStyle(Params.fromArray([5]), collect);
inputHandler.setCursorStyle(Params.fromArray([5]));
assert.equal(optionsService.options['cursorStyle'], 'bar');
assert.equal(optionsService.options['cursorBlink'], true);

optionsService.options = clone(DEFAULT_OPTIONS);
inputHandler.setCursorStyle(Params.fromArray([6]), collect);
inputHandler.setCursorStyle(Params.fromArray([6]));
assert.equal(optionsService.options['cursorStyle'], 'bar');
assert.equal(optionsService.options['cursorBlink'], false);
});
});
describe('setMode', () => {
it('should toggle Terminal.bracketedPasteMode', () => {
const terminal = new MockInputHandlingTerminal();
const collect = '?';
terminal.bracketedPasteMode = false;
const inputHandler = new InputHandler(terminal, new MockBufferService(80, 30), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService());
// Set bracketed paste mode
inputHandler.setMode(Params.fromArray([2004]), collect);
inputHandler.setModePrivate(Params.fromArray([2004]));
assert.equal(terminal.bracketedPasteMode, true);
// Reset bracketed paste mode
inputHandler.resetMode(Params.fromArray([2004]), collect);
inputHandler.resetModePrivate(Params.fromArray([2004]));
assert.equal(terminal.bracketedPasteMode, false);
});
});
Expand Down
441 changes: 229 additions & 212 deletions src/InputHandler.ts

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions src/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import { Disposable } from 'common/Lifecycle';
import { IBufferSet, IBuffer } from 'common/buffer/Types';
import { Attributes } from 'common/buffer/Constants';
import { MouseService } from 'browser/services/MouseService';
import { IParams } from 'common/parser/Types';
import { IParams, IFunctionIdentifier } from 'common/parser/Types';
import { CoreService } from 'common/services/CoreService';
import { LogService } from 'common/services/LogService';
import { ILinkifier, IMouseZoneManager, LinkMatcherHandler, ILinkMatcherOptions, IViewport } from 'browser/Types';
Expand Down Expand Up @@ -1397,9 +1397,19 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this._customKeyEventHandler = customKeyEventHandler;
}

/** Add handler for ESC escape sequence. See xterm.d.ts for details. */
public addEscHandler(id: IFunctionIdentifier, callback: () => boolean): IDisposable {
return this._inputHandler.addEscHandler(id, callback);
}

/** Add handler for DCS escape sequence. See xterm.d.ts for details. */
public addDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: IParams) => boolean): IDisposable {
return this._inputHandler.addDcsHandler(id, callback);
}

/** Add handler for CSI escape sequence. See xterm.d.ts for details. */
public addCsiHandler(flag: string, callback: (params: IParams, collect: string) => boolean): IDisposable {
return this._inputHandler.addCsiHandler(flag, callback);
public addCsiHandler(id: IFunctionIdentifier, callback: (params: IParams) => boolean): IDisposable {
return this._inputHandler.addCsiHandler(id, callback);
}
/** Add handler for OSC escape sequence. See xterm.d.ts for details. */
public addOscHandler(ident: number, callback: (data: string) => boolean): IDisposable {
Expand Down
14 changes: 10 additions & 4 deletions src/TestUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { AttributeData } from 'common/buffer/AttributeData';
import { IColorManager, IColorSet, ILinkMatcherOptions, ILinkifier, IViewport } from 'browser/Types';
import { IOptionsService } from 'common/services/Services';
import { EventEmitter } from 'common/EventEmitter';
import { IParams } from 'common/parser/Types';
import { IParams, IFunctionIdentifier } from 'common/parser/Types';
import { ISelectionService } from 'browser/services/Services';

export class TestTerminal extends Terminal {
Expand Down Expand Up @@ -74,11 +74,17 @@ export class MockTerminal implements ITerminal {
attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void {
throw new Error('Method not implemented.');
}
addCsiHandler(flag: string, callback: (params: IParams, collect: string) => boolean): IDisposable {
throw new Error('Method not implemented.');
addCsiHandler(id: IFunctionIdentifier, callback: (params: IParams) => boolean): IDisposable {
throw new Error('Method not implemented.');
}
addDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: IParams) => boolean): IDisposable {
throw new Error('Method not implemented.');
}
addEscHandler(id: IFunctionIdentifier, handler: () => boolean): IDisposable {
throw new Error('Method not implemented.');
}
addOscHandler(ident: number, callback: (data: string) => boolean): IDisposable {
throw new Error('Method not implemented.');
throw new Error('Method not implemented.');
}
registerLinkMatcher(regex: RegExp, handler: (event: MouseEvent, uri: string) => boolean | void, options?: ILinkMatcherOptions): number {
throw new Error('Method not implemented.');
Expand Down
9 changes: 6 additions & 3 deletions src/Types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IEvent, IEventEmitter } from 'common/EventEmitter';
import { IColorSet, ILinkifier, ILinkMatcherOptions, IViewport } from 'browser/Types';
import { IOptionsService } from 'common/services/Services';
import { IBuffer, IBufferSet } from 'common/buffer/Types';
import { IParams } from 'common/parser/Types';
import { IParams, IFunctionIdentifier } from 'common/parser/Types';

export type CustomKeyEventHandler = (event: KeyboardEvent) => boolean;

Expand Down Expand Up @@ -113,7 +113,8 @@ export interface IInputHandler {
/** CSI ` */ charPosAbsolute(params: IParams): void;
/** CSI a */ hPositionRelative(params: IParams): void;
/** CSI b */ repeatPrecedingCharacter(params: IParams): void;
/** CSI c */ sendDeviceAttributes(params: IParams, collect?: string): void;
/** CSI c */ sendDeviceAttributesPrimary(params: IParams): void;
sendDeviceAttributesSecondary(params: IParams): void;
jerch marked this conversation as resolved.
Show resolved Hide resolved
/** CSI d */ linePosAbsolute(params: IParams): void;
/** CSI e */ vPositionRelative(params: IParams): void;
/** CSI f */ hVPosition(params: IParams): void;
Expand Down Expand Up @@ -200,7 +201,9 @@ export interface IPublicTerminal extends IDisposable {
writeln(data: string): void;
open(parent: HTMLElement): void;
attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;
addCsiHandler(flag: string, callback: (params: IParams, collect: string) => boolean): IDisposable;
addCsiHandler(id: IFunctionIdentifier, callback: (params: IParams) => boolean): IDisposable;
addDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: IParams) => boolean): IDisposable;
addEscHandler(id: IFunctionIdentifier, callback: () => boolean): IDisposable;
addOscHandler(ident: number, callback: (data: string) => boolean): IDisposable;
registerLinkMatcher(regex: RegExp, handler: (event: MouseEvent, uri: string) => void, options?: ILinkMatcherOptions): number;
deregisterLinkMatcher(matcherId: number): void;
Expand Down
13 changes: 13 additions & 0 deletions src/common/parser/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,16 @@ export const enum ParserAction {
DCS_PUT = 13,
DCS_UNHOOK = 14
}

/**
* Internal states of OscParser.
*/
export const enum OscState {
START = 0,
ID = 1,
PAYLOAD = 2,
ABORT = 3
}

// payload limit for OSC and DCS
export const PAYLOAD_LIMIT = 10000000;
Tyriar marked this conversation as resolved.
Show resolved Hide resolved