Merge branch 'master' into left_right_scroll
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
},
|
},
|
||||||
"main": "lib/xterm-addon-attach.js",
|
"main": "lib/xterm-addon-attach.js",
|
||||||
"types": "typings/xterm-addon-attach.d.ts",
|
"types": "typings/xterm-addon-attach.d.ts",
|
||||||
|
"repository": "https://github.com/xtermjs/xterm.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "../../node_modules/.bin/tsc -p src",
|
"build": "../../node_modules/.bin/tsc -p src",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
},
|
},
|
||||||
"main": "lib/xterm-addon-fit.js",
|
"main": "lib/xterm-addon-fit.js",
|
||||||
"types": "typings/xterm-addon-fit.d.ts",
|
"types": "typings/xterm-addon-fit.d.ts",
|
||||||
|
"repository": "https://github.com/xtermjs/xterm.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "../../node_modules/.bin/tsc -p src",
|
"build": "../../node_modules/.bin/tsc -p src",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
},
|
},
|
||||||
"main": "lib/xterm-addon-search.js",
|
"main": "lib/xterm-addon-search.js",
|
||||||
"types": "typings/xterm-addon-search.d.ts",
|
"types": "typings/xterm-addon-search.d.ts",
|
||||||
|
"repository": "https://github.com/xtermjs/xterm.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "../../node_modules/.bin/tsc -p src",
|
"build": "../../node_modules/.bin/tsc -p src",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
},
|
},
|
||||||
"main": "lib/xterm-addon-web-links.js",
|
"main": "lib/xterm-addon-web-links.js",
|
||||||
"types": "typings/xterm-addon-web-links.d.ts",
|
"types": "typings/xterm-addon-web-links.d.ts",
|
||||||
|
"repository": "https://github.com/xtermjs/xterm.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "../../node_modules/.bin/tsc -p src",
|
"build": "../../node_modules/.bin/tsc -p src",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
},
|
},
|
||||||
"main": "lib/xterm-addon-webgl.js",
|
"main": "lib/xterm-addon-webgl.js",
|
||||||
"types": "typings/xterm-addon-webgl.d.ts",
|
"types": "typings/xterm-addon-webgl.d.ts",
|
||||||
|
"repository": "https://github.com/xtermjs/xterm.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "../../node_modules/.bin/tsc -p src",
|
"build": "../../node_modules/.bin/tsc -p src",
|
||||||
|
|||||||
+10
-10
@@ -13,7 +13,7 @@ import { CellData } from 'common/buffer/CellData';
|
|||||||
import { Attributes } from 'common/buffer/Constants';
|
import { Attributes } from 'common/buffer/Constants';
|
||||||
import { AttributeData } from 'common/buffer/AttributeData';
|
import { AttributeData } from 'common/buffer/AttributeData';
|
||||||
import { Params } from 'common/parser/Params';
|
import { Params } from 'common/parser/Params';
|
||||||
import { MockCoreService, MockBufferService, MockDirtyRowService, MockOptionsService, MockLogService } from 'common/TestUtils.test';
|
import { MockCoreService, MockBufferService, MockDirtyRowService, MockOptionsService, MockLogService, MockCoreMouseService } from 'common/TestUtils.test';
|
||||||
import { IBufferService } from 'common/services/Services';
|
import { IBufferService } from 'common/services/Services';
|
||||||
import { DEFAULT_OPTIONS } from 'common/services/OptionsService';
|
import { DEFAULT_OPTIONS } from 'common/services/OptionsService';
|
||||||
import { clone } from 'common/Clone';
|
import { clone } from 'common/Clone';
|
||||||
@@ -41,7 +41,7 @@ describe('InputHandler', () => {
|
|||||||
bufferService.buffer.x = 1;
|
bufferService.buffer.x = 1;
|
||||||
bufferService.buffer.y = 2;
|
bufferService.buffer.y = 2;
|
||||||
bufferService.buffer.ybase = 0;
|
bufferService.buffer.ybase = 0;
|
||||||
const inputHandler = new InputHandler(terminal, bufferService, new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService());
|
const inputHandler = new InputHandler(terminal, bufferService, new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService());
|
||||||
// Save cursor position
|
// Save cursor position
|
||||||
inputHandler.saveCursor();
|
inputHandler.saveCursor();
|
||||||
assert.equal(bufferService.buffer.x, 1);
|
assert.equal(bufferService.buffer.x, 1);
|
||||||
@@ -60,7 +60,7 @@ describe('InputHandler', () => {
|
|||||||
describe('setCursorStyle', () => {
|
describe('setCursorStyle', () => {
|
||||||
it('should call Terminal.setOption with correct params', () => {
|
it('should call Terminal.setOption with correct params', () => {
|
||||||
const optionsService = new MockOptionsService();
|
const optionsService = new MockOptionsService();
|
||||||
const inputHandler = new InputHandler(new MockInputHandlingTerminal(), new MockBufferService(80, 30), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), optionsService);
|
const inputHandler = new InputHandler(new MockInputHandlingTerminal(), new MockBufferService(80, 30), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), optionsService, new MockCoreMouseService());
|
||||||
|
|
||||||
inputHandler.setCursorStyle(Params.fromArray([0]));
|
inputHandler.setCursorStyle(Params.fromArray([0]));
|
||||||
assert.equal(optionsService.options['cursorStyle'], 'block');
|
assert.equal(optionsService.options['cursorStyle'], 'block');
|
||||||
@@ -101,7 +101,7 @@ describe('InputHandler', () => {
|
|||||||
it('should toggle Terminal.bracketedPasteMode', () => {
|
it('should toggle Terminal.bracketedPasteMode', () => {
|
||||||
const terminal = new MockInputHandlingTerminal();
|
const terminal = new MockInputHandlingTerminal();
|
||||||
terminal.bracketedPasteMode = false;
|
terminal.bracketedPasteMode = false;
|
||||||
const inputHandler = new InputHandler(terminal, new MockBufferService(80, 30), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService());
|
const inputHandler = new InputHandler(terminal, new MockBufferService(80, 30), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService());
|
||||||
// Set bracketed paste mode
|
// Set bracketed paste mode
|
||||||
inputHandler.setModePrivate(Params.fromArray([2004]));
|
inputHandler.setModePrivate(Params.fromArray([2004]));
|
||||||
assert.equal(terminal.bracketedPasteMode, true);
|
assert.equal(terminal.bracketedPasteMode, true);
|
||||||
@@ -120,7 +120,7 @@ describe('InputHandler', () => {
|
|||||||
it('insertChars', function(): void {
|
it('insertChars', function(): void {
|
||||||
const term = new Terminal();
|
const term = new Terminal();
|
||||||
const bufferService = new MockBufferService(80, 30);
|
const bufferService = new MockBufferService(80, 30);
|
||||||
const inputHandler = new InputHandler(term, bufferService, new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService());
|
const inputHandler = new InputHandler(term, bufferService, new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService());
|
||||||
|
|
||||||
// insert some data in first and second line
|
// insert some data in first and second line
|
||||||
inputHandler.parse(Array(bufferService.cols - 9).join('a'));
|
inputHandler.parse(Array(bufferService.cols - 9).join('a'));
|
||||||
@@ -158,7 +158,7 @@ describe('InputHandler', () => {
|
|||||||
it('deleteChars', function(): void {
|
it('deleteChars', function(): void {
|
||||||
const term = new Terminal();
|
const term = new Terminal();
|
||||||
const bufferService = new MockBufferService(80, 30);
|
const bufferService = new MockBufferService(80, 30);
|
||||||
const inputHandler = new InputHandler(term, bufferService, new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService());
|
const inputHandler = new InputHandler(term, bufferService, new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService());
|
||||||
|
|
||||||
// insert some data in first and second line
|
// insert some data in first and second line
|
||||||
inputHandler.parse(Array(bufferService.cols - 9).join('a'));
|
inputHandler.parse(Array(bufferService.cols - 9).join('a'));
|
||||||
@@ -199,7 +199,7 @@ describe('InputHandler', () => {
|
|||||||
it('eraseInLine', function(): void {
|
it('eraseInLine', function(): void {
|
||||||
const term = new Terminal();
|
const term = new Terminal();
|
||||||
const bufferService = new MockBufferService(80, 30);
|
const bufferService = new MockBufferService(80, 30);
|
||||||
const inputHandler = new InputHandler(term, bufferService, new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService());
|
const inputHandler = new InputHandler(term, bufferService, new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService());
|
||||||
|
|
||||||
// fill 6 lines to test 3 different states
|
// fill 6 lines to test 3 different states
|
||||||
inputHandler.parse(Array(bufferService.cols + 1).join('a'));
|
inputHandler.parse(Array(bufferService.cols + 1).join('a'));
|
||||||
@@ -228,7 +228,7 @@ describe('InputHandler', () => {
|
|||||||
it('eraseInDisplay', function(): void {
|
it('eraseInDisplay', function(): void {
|
||||||
const term = new Terminal({cols: 80, rows: 7});
|
const term = new Terminal({cols: 80, rows: 7});
|
||||||
const bufferService = new MockBufferService(80, 7);
|
const bufferService = new MockBufferService(80, 7);
|
||||||
const inputHandler = new InputHandler(term, bufferService, new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService());
|
const inputHandler = new InputHandler(term, bufferService, new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService());
|
||||||
|
|
||||||
// fill display with a's
|
// fill display with a's
|
||||||
for (let i = 0; i < bufferService.rows; ++i) inputHandler.parse(Array(bufferService.cols + 1).join('a'));
|
for (let i = 0; i < bufferService.rows; ++i) inputHandler.parse(Array(bufferService.cols + 1).join('a'));
|
||||||
@@ -363,7 +363,7 @@ describe('InputHandler', () => {
|
|||||||
describe('print', () => {
|
describe('print', () => {
|
||||||
it('should not cause an infinite loop (regression test)', () => {
|
it('should not cause an infinite loop (regression test)', () => {
|
||||||
const term = new Terminal();
|
const term = new Terminal();
|
||||||
const inputHandler = new InputHandler(term, new MockBufferService(80, 30), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService());
|
const inputHandler = new InputHandler(term, new MockBufferService(80, 30), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService());
|
||||||
const container = new Uint32Array(10);
|
const container = new Uint32Array(10);
|
||||||
container[0] = 0x200B;
|
container[0] = 0x200B;
|
||||||
inputHandler.print(container, 0, 1);
|
inputHandler.print(container, 0, 1);
|
||||||
@@ -378,7 +378,7 @@ describe('InputHandler', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
term = new Terminal();
|
term = new Terminal();
|
||||||
bufferService = new MockBufferService(80, 30);
|
bufferService = new MockBufferService(80, 30);
|
||||||
handler = new InputHandler(term, bufferService, new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService());
|
handler = new InputHandler(term, bufferService, new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService());
|
||||||
});
|
});
|
||||||
it('should handle DECSET/DECRST 47 (alt screen buffer)', () => {
|
it('should handle DECSET/DECRST 47 (alt screen buffer)', () => {
|
||||||
handler.parse('\x1b[?47h\r\n\x1b[31mJUNK\x1b[?47lTEST');
|
handler.parse('\x1b[?47h\r\n\x1b[31mJUNK\x1b[?47lTEST');
|
||||||
|
|||||||
+16
-48
@@ -19,8 +19,7 @@ import { NULL_CELL_CODE, NULL_CELL_WIDTH, Attributes, FgFlags, BgFlags, Content
|
|||||||
import { CellData } from 'common/buffer/CellData';
|
import { CellData } from 'common/buffer/CellData';
|
||||||
import { AttributeData } from 'common/buffer/AttributeData';
|
import { AttributeData } from 'common/buffer/AttributeData';
|
||||||
import { IAttributeData, IDisposable } from 'common/Types';
|
import { IAttributeData, IDisposable } from 'common/Types';
|
||||||
import { ICoreService, IBufferService, IOptionsService, ILogService, IDirtyRowService } from 'common/services/Services';
|
import { ICoreService, IBufferService, IOptionsService, ILogService, IDirtyRowService, ICoreMouseService } from 'common/services/Services';
|
||||||
import { ISelectionService } from 'browser/services/Services';
|
|
||||||
import { OscHandler } from 'common/parser/OscParser';
|
import { OscHandler } from 'common/parser/OscParser';
|
||||||
import { DcsHandler } from 'common/parser/DcsParser';
|
import { DcsHandler } from 'common/parser/DcsParser';
|
||||||
|
|
||||||
@@ -124,8 +123,6 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
private _utf8Decoder: Utf8ToUtf32 = new Utf8ToUtf32();
|
private _utf8Decoder: Utf8ToUtf32 = new Utf8ToUtf32();
|
||||||
private _workCell: CellData = new CellData();
|
private _workCell: CellData = new CellData();
|
||||||
|
|
||||||
private _selectionService: ISelectionService | undefined;
|
|
||||||
|
|
||||||
private _onCursorMove = new EventEmitter<void>();
|
private _onCursorMove = new EventEmitter<void>();
|
||||||
public get onCursorMove(): IEvent<void> { return this._onCursorMove.event; }
|
public get onCursorMove(): IEvent<void> { return this._onCursorMove.event; }
|
||||||
private _onLineFeed = new EventEmitter<void>();
|
private _onLineFeed = new EventEmitter<void>();
|
||||||
@@ -140,6 +137,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
private readonly _dirtyRowService: IDirtyRowService,
|
private readonly _dirtyRowService: IDirtyRowService,
|
||||||
private readonly _logService: ILogService,
|
private readonly _logService: ILogService,
|
||||||
private readonly _optionsService: IOptionsService,
|
private readonly _optionsService: IOptionsService,
|
||||||
|
private readonly _coreMouseService: ICoreMouseService,
|
||||||
private readonly _parser: IEscapeSequenceParser = new EscapeSequenceParser())
|
private readonly _parser: IEscapeSequenceParser = new EscapeSequenceParser())
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
@@ -330,11 +328,6 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: When InputHandler moves into common, browser dependencies need to move out
|
|
||||||
public setBrowserServices(selectionService: ISelectionService): void {
|
|
||||||
this._selectionService = selectionService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public parse(data: string): void {
|
public parse(data: string): void {
|
||||||
let buffer = this._bufferService.buffer;
|
let buffer = this._bufferService.buffer;
|
||||||
const cursorStartX = buffer.x;
|
const cursorStartX = buffer.x;
|
||||||
@@ -1396,27 +1389,19 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
break;
|
break;
|
||||||
case 9: // X10 Mouse
|
case 9: // X10 Mouse
|
||||||
// no release, no motion, no wheel, no modifiers.
|
// no release, no motion, no wheel, no modifiers.
|
||||||
|
this._coreMouseService.activeProtocol = 'X10';
|
||||||
|
break;
|
||||||
case 1000: // vt200 mouse
|
case 1000: // vt200 mouse
|
||||||
// no motion.
|
// no motion.
|
||||||
// no modifiers, except control on the wheel.
|
this._coreMouseService.activeProtocol = 'VT200';
|
||||||
|
break;
|
||||||
case 1002: // button event mouse
|
case 1002: // button event mouse
|
||||||
|
this._coreMouseService.activeProtocol = 'DRAG';
|
||||||
|
break;
|
||||||
case 1003: // any event mouse
|
case 1003: // any event mouse
|
||||||
// any event - sends motion events,
|
// any event - sends motion events,
|
||||||
// even if there is no button held down.
|
// even if there is no button held down.
|
||||||
|
this._coreMouseService.activeProtocol = 'ANY';
|
||||||
// TODO: Why are params[0] compares nested within a switch for params[0]?
|
|
||||||
|
|
||||||
this._terminal.x10Mouse = params.params[i] === 9;
|
|
||||||
this._terminal.vt200Mouse = params.params[i] === 1000;
|
|
||||||
this._terminal.normalMouse = params.params[i] > 1000;
|
|
||||||
this._terminal.mouseEvents = true;
|
|
||||||
if (this._terminal.element) {
|
|
||||||
this._terminal.element.classList.add('enable-mouse-events');
|
|
||||||
}
|
|
||||||
if (this._selectionService) {
|
|
||||||
this._selectionService.disable();
|
|
||||||
}
|
|
||||||
this._logService.debug('Binding to mouse events.');
|
|
||||||
break;
|
break;
|
||||||
case 1004: // send focusin/focusout events
|
case 1004: // send focusin/focusout events
|
||||||
// focusin: ^[[I
|
// focusin: ^[[I
|
||||||
@@ -1424,23 +1409,15 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
this._terminal.sendFocus = true;
|
this._terminal.sendFocus = true;
|
||||||
break;
|
break;
|
||||||
case 1005: // utf8 ext mode mouse
|
case 1005: // utf8 ext mode mouse
|
||||||
this._terminal.utfMouse = true;
|
|
||||||
// for wide terminals
|
// for wide terminals
|
||||||
// simply encodes large values as utf8 characters
|
// simply encodes large values as utf8 characters
|
||||||
|
this._coreMouseService.activeEncoding = 'UTF8';
|
||||||
break;
|
break;
|
||||||
case 1006: // sgr ext mode mouse
|
case 1006: // sgr ext mode mouse
|
||||||
this._terminal.sgrMouse = true;
|
this._coreMouseService.activeEncoding = 'SGR';
|
||||||
// for wide terminals
|
|
||||||
// does not add 32 to fields
|
|
||||||
// press: ^[[<b;x;yM
|
|
||||||
// release: ^[[<b;x;ym
|
|
||||||
break;
|
break;
|
||||||
case 1015: // urxvt ext mode mouse
|
case 1015: // urxvt ext mode mouse
|
||||||
this._terminal.urxvtMouse = true;
|
this._coreMouseService.activeEncoding = 'URXVT';
|
||||||
// for wide terminals
|
|
||||||
// numbers for fields
|
|
||||||
// press: ^[[b;x;yM
|
|
||||||
// motion: ^[[b;x;yT
|
|
||||||
break;
|
break;
|
||||||
case 25: // show cursor
|
case 25: // show cursor
|
||||||
this._terminal.cursorHidden = false;
|
this._terminal.cursorHidden = false;
|
||||||
@@ -1599,28 +1576,19 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
case 1000: // vt200 mouse
|
case 1000: // vt200 mouse
|
||||||
case 1002: // button event mouse
|
case 1002: // button event mouse
|
||||||
case 1003: // any event mouse
|
case 1003: // any event mouse
|
||||||
this._terminal.x10Mouse = false;
|
this._coreMouseService.activeProtocol = 'NONE';
|
||||||
this._terminal.vt200Mouse = false;
|
|
||||||
this._terminal.normalMouse = false;
|
|
||||||
this._terminal.mouseEvents = false;
|
|
||||||
if (this._terminal.element) {
|
|
||||||
this._terminal.element.classList.remove('enable-mouse-events');
|
|
||||||
}
|
|
||||||
if (this._selectionService) {
|
|
||||||
this._selectionService.enable();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 1004: // send focusin/focusout events
|
case 1004: // send focusin/focusout events
|
||||||
this._terminal.sendFocus = false;
|
this._terminal.sendFocus = false;
|
||||||
break;
|
break;
|
||||||
case 1005: // utf8 ext mode mouse
|
case 1005: // utf8 ext mode mouse
|
||||||
this._terminal.utfMouse = false;
|
this._coreMouseService.activeEncoding = 'DEFAULT';
|
||||||
break;
|
break;
|
||||||
case 1006: // sgr ext mode mouse
|
case 1006: // sgr ext mode mouse
|
||||||
this._terminal.sgrMouse = false;
|
this._coreMouseService.activeEncoding = 'DEFAULT';
|
||||||
break;
|
break;
|
||||||
case 1015: // urxvt ext mode mouse
|
case 1015: // urxvt ext mode mouse
|
||||||
this._terminal.urxvtMouse = false;
|
this._coreMouseService.activeEncoding = 'DEFAULT';
|
||||||
break;
|
break;
|
||||||
case 25: // hide cursor
|
case 25: // hide cursor
|
||||||
this._terminal.cursorHidden = true;
|
this._terminal.cursorHidden = true;
|
||||||
|
|||||||
+172
-254
@@ -39,14 +39,14 @@ import { MouseZoneManager } from 'browser/MouseZoneManager';
|
|||||||
import { AccessibilityManager } from './AccessibilityManager';
|
import { AccessibilityManager } from './AccessibilityManager';
|
||||||
import { ITheme, IMarker, IDisposable, ISelectionPosition } from 'xterm';
|
import { ITheme, IMarker, IDisposable, ISelectionPosition } from 'xterm';
|
||||||
import { DomRenderer } from './renderer/dom/DomRenderer';
|
import { DomRenderer } from './renderer/dom/DomRenderer';
|
||||||
import { IKeyboardEvent, KeyboardResultType, ICharset, IBufferLine, IAttributeData } from 'common/Types';
|
import { IKeyboardEvent, KeyboardResultType, ICharset, IBufferLine, IAttributeData, CoreMouseEventType, CoreMouseButton, CoreMouseAction } from 'common/Types';
|
||||||
import { evaluateKeyboardEvent } from 'common/input/Keyboard';
|
import { evaluateKeyboardEvent } from 'common/input/Keyboard';
|
||||||
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
||||||
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
|
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
|
||||||
import { applyWindowsMode } from './WindowsMode';
|
import { applyWindowsMode } from './WindowsMode';
|
||||||
import { ColorManager } from 'browser/ColorManager';
|
import { ColorManager } from 'browser/ColorManager';
|
||||||
import { RenderService } from 'browser/services/RenderService';
|
import { RenderService } from 'browser/services/RenderService';
|
||||||
import { IOptionsService, IBufferService, ICoreService, ILogService, IDirtyRowService, IInstantiationService } from 'common/services/Services';
|
import { IOptionsService, IBufferService, ICoreMouseService, ICoreService, ILogService, IDirtyRowService, IInstantiationService } from 'common/services/Services';
|
||||||
import { OptionsService } from 'common/services/OptionsService';
|
import { OptionsService } from 'common/services/OptionsService';
|
||||||
import { ICharSizeService, IRenderService, IMouseService, ISelectionService, ISoundService } from 'browser/services/Services';
|
import { ICharSizeService, IRenderService, IMouseService, ISelectionService, ISoundService } from 'browser/services/Services';
|
||||||
import { CharSizeService } from 'browser/services/CharSizeService';
|
import { CharSizeService } from 'browser/services/CharSizeService';
|
||||||
@@ -61,6 +61,7 @@ import { LogService } from 'common/services/LogService';
|
|||||||
import { ILinkifier, IMouseZoneManager, LinkMatcherHandler, ILinkMatcherOptions, IViewport } from 'browser/Types';
|
import { ILinkifier, IMouseZoneManager, LinkMatcherHandler, ILinkMatcherOptions, IViewport } from 'browser/Types';
|
||||||
import { DirtyRowService } from 'common/services/DirtyRowService';
|
import { DirtyRowService } from 'common/services/DirtyRowService';
|
||||||
import { InstantiationService } from 'common/services/InstantiationService';
|
import { InstantiationService } from 'common/services/InstantiationService';
|
||||||
|
import { CoreMouseService } from 'common/services/CoreMouseService';
|
||||||
|
|
||||||
// Let it work inside Node.js for automated testing purposes.
|
// Let it work inside Node.js for automated testing purposes.
|
||||||
const document = (typeof window !== 'undefined') ? window.document : null;
|
const document = (typeof window !== 'undefined') ? window.document : null;
|
||||||
@@ -112,6 +113,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
|||||||
// common services
|
// common services
|
||||||
private _bufferService: IBufferService;
|
private _bufferService: IBufferService;
|
||||||
private _coreService: ICoreService;
|
private _coreService: ICoreService;
|
||||||
|
private _coreMouseService: ICoreMouseService;
|
||||||
private _dirtyRowService: IDirtyRowService;
|
private _dirtyRowService: IDirtyRowService;
|
||||||
private _instantiationService: IInstantiationService;
|
private _instantiationService: IInstantiationService;
|
||||||
private _logService: ILogService;
|
private _logService: ILogService;
|
||||||
@@ -139,16 +141,8 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
|||||||
public charsets: ICharset[];
|
public charsets: ICharset[];
|
||||||
|
|
||||||
// mouse properties
|
// mouse properties
|
||||||
private _decLocator: boolean; // This is unstable and never set
|
public mouseEvents: CoreMouseEventType = CoreMouseEventType.NONE;
|
||||||
public x10Mouse: boolean;
|
|
||||||
public vt200Mouse: boolean;
|
|
||||||
private _vt300Mouse: boolean; // This is unstable and never set
|
|
||||||
public normalMouse: boolean;
|
|
||||||
public mouseEvents: boolean;
|
|
||||||
public sendFocus: boolean;
|
public sendFocus: boolean;
|
||||||
public utfMouse: boolean;
|
|
||||||
public sgrMouse: boolean;
|
|
||||||
public urxvtMouse: boolean;
|
|
||||||
|
|
||||||
// misc
|
// misc
|
||||||
public savedCols: number;
|
public savedCols: number;
|
||||||
@@ -257,6 +251,8 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
|||||||
this._coreService = this._instantiationService.createInstance(CoreService, () => this.scrollToBottom());
|
this._coreService = this._instantiationService.createInstance(CoreService, () => this.scrollToBottom());
|
||||||
this._instantiationService.setService(ICoreService, this._coreService);
|
this._instantiationService.setService(ICoreService, this._coreService);
|
||||||
this._coreService.onData(e => this._onData.fire(e));
|
this._coreService.onData(e => this._onData.fire(e));
|
||||||
|
this._coreMouseService = this._instantiationService.createInstance(CoreMouseService);
|
||||||
|
this._instantiationService.setService(ICoreMouseService, this._coreMouseService);
|
||||||
this._dirtyRowService = this._instantiationService.createInstance(DirtyRowService);
|
this._dirtyRowService = this._instantiationService.createInstance(DirtyRowService);
|
||||||
this._instantiationService.setService(IDirtyRowService, this._dirtyRowService);
|
this._instantiationService.setService(IDirtyRowService, this._dirtyRowService);
|
||||||
|
|
||||||
@@ -320,7 +316,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
|||||||
this._userScrolling = false;
|
this._userScrolling = false;
|
||||||
|
|
||||||
// Register input handler and refire/handle events
|
// Register input handler and refire/handle events
|
||||||
this._inputHandler = new InputHandler(this, this._bufferService, this._coreService, this._dirtyRowService, this._logService, this.optionsService);
|
this._inputHandler = new InputHandler(this, this._bufferService, this._coreService, this._dirtyRowService, this._logService, this.optionsService, this._coreMouseService);
|
||||||
this._inputHandler.onCursorMove(() => this._onCursorMove.fire());
|
this._inputHandler.onCursorMove(() => this._onCursorMove.fire());
|
||||||
this._inputHandler.onLineFeed(() => this._onLineFeed.fire());
|
this._inputHandler.onLineFeed(() => this._onLineFeed.fire());
|
||||||
this.register(this._inputHandler);
|
this.register(this._inputHandler);
|
||||||
@@ -674,7 +670,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
|||||||
} else {
|
} else {
|
||||||
this._selectionService.enable();
|
this._selectionService.enable();
|
||||||
}
|
}
|
||||||
this._inputHandler.setBrowserServices(this._selectionService);
|
|
||||||
|
|
||||||
if (this.options.screenReaderMode) {
|
if (this.options.screenReaderMode) {
|
||||||
// Note that this must be done *after* the renderer is created in order to
|
// Note that this must be done *after* the renderer is created in order to
|
||||||
@@ -694,7 +689,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
|||||||
// Listen for mouse events and translate
|
// Listen for mouse events and translate
|
||||||
// them into terminal mouse protocols.
|
// them into terminal mouse protocols.
|
||||||
this.bindMouse();
|
this.bindMouse();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _createRenderer(): IRenderer {
|
private _createRenderer(): IRenderer {
|
||||||
@@ -723,227 +717,188 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XTerm mouse events
|
* Bind certain mouse events to the terminal.
|
||||||
* http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
|
* By default only 3 button + wheel up/down is ativated. For higher buttons
|
||||||
* To better understand these
|
* no mouse report will be created. Typically the standard actions will be active.
|
||||||
* the xterm code is very helpful:
|
*
|
||||||
* Relevant files:
|
* There are several reasons not to enable support for higher buttons/wheel:
|
||||||
* button.c, charproc.c, misc.c
|
* - Button 4 and 5 are typically used for history back and forward navigation,
|
||||||
* Relevant functions in xterm/button.c:
|
* there is no straight forward way to supress/intercept those standard actions.
|
||||||
* BtnCode, EmitButtonCode, EditorButton, SendMousePosition
|
* - Support for higher buttons does not work in some platform/browser combinations.
|
||||||
|
* - Left/right wheel was not tested.
|
||||||
|
* - Emulators vary in mouse button support, typically only 3 buttons and
|
||||||
|
* wheel up/down work reliable.
|
||||||
|
*
|
||||||
|
* TODO: Move mouse event code into its own file.
|
||||||
*/
|
*/
|
||||||
public bindMouse(): void {
|
public bindMouse(): void {
|
||||||
const el = this.element;
|
|
||||||
const self = this;
|
const self = this;
|
||||||
let pressed = 32;
|
const el = this.element;
|
||||||
|
|
||||||
// mouseup, mousedown, wheel
|
// send event to CoreMouseService
|
||||||
// left click: ^[[M 3<^[[M#3<
|
function sendEvent(ev: MouseEvent | WheelEvent): boolean {
|
||||||
// wheel up: ^[[M`3>
|
|
||||||
function sendButton(ev: MouseEvent | WheelEvent): void {
|
|
||||||
let button;
|
|
||||||
let pos;
|
let pos;
|
||||||
|
|
||||||
// get the xterm-style button
|
|
||||||
button = getButton(ev);
|
|
||||||
|
|
||||||
// get mouse coordinates
|
// get mouse coordinates
|
||||||
pos = self._mouseService.getRawByteCoords(ev, self.screenElement, self.cols, self.rows);
|
pos = self._mouseService.getRawByteCoords(ev, self.screenElement, self.cols, self.rows);
|
||||||
if (!pos) return;
|
if (!pos) {
|
||||||
|
return false;
|
||||||
sendEvent(button, pos);
|
}
|
||||||
|
|
||||||
|
let but: CoreMouseButton;
|
||||||
|
let action: CoreMouseAction;
|
||||||
switch ((<any>ev).overrideType || ev.type) {
|
switch ((<any>ev).overrideType || ev.type) {
|
||||||
case 'mousedown':
|
case 'mousemove':
|
||||||
pressed = button;
|
action = CoreMouseAction.MOVE;
|
||||||
|
if (ev.buttons === undefined) {
|
||||||
|
// buttons is not supported on macOS, try to get a value from button instead
|
||||||
|
but = CoreMouseButton.NONE;
|
||||||
|
if (ev.button !== undefined) {
|
||||||
|
but = ev.button < 3 ? ev.button : CoreMouseButton.NONE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// according to MDN buttons only reports up to button 5 (AUX2)
|
||||||
|
but = ev.buttons & 1 ? CoreMouseButton.LEFT :
|
||||||
|
ev.buttons & 4 ? CoreMouseButton.MIDDLE :
|
||||||
|
ev.buttons & 2 ? CoreMouseButton.RIGHT :
|
||||||
|
CoreMouseButton.NONE; // fallback to NONE
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'mouseup':
|
case 'mouseup':
|
||||||
// keep it at the left
|
action = CoreMouseAction.UP;
|
||||||
// button, just in case.
|
but = ev.button < 3 ? ev.button : CoreMouseButton.NONE;
|
||||||
pressed = 32;
|
break;
|
||||||
|
case 'mousedown':
|
||||||
|
action = CoreMouseAction.DOWN;
|
||||||
|
but = ev.button < 3 ? ev.button : CoreMouseButton.NONE;
|
||||||
break;
|
break;
|
||||||
case 'wheel':
|
case 'wheel':
|
||||||
// nothing. don't
|
// only UP/DOWN wheel events are respected
|
||||||
// interfere with
|
if ((ev as WheelEvent).deltaY !== 0) {
|
||||||
// `pressed`.
|
action = (ev as WheelEvent).deltaY < 0 ? CoreMouseAction.UP : CoreMouseAction.DOWN;
|
||||||
|
}
|
||||||
|
but = CoreMouseButton.WHEEL;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
// dont handle other event types by accident
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// exit if we cannot determine valid button/action values
|
||||||
|
// do nothing for higher buttons than wheel
|
||||||
|
if (action === undefined || but === undefined || but > CoreMouseButton.WHEEL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self._coreMouseService.triggerMouseEvent({
|
||||||
|
col: pos.x - 33, // FIXME: why -33 here?
|
||||||
|
row: pos.y - 33,
|
||||||
|
button: but,
|
||||||
|
action,
|
||||||
|
ctrl: ev.ctrlKey,
|
||||||
|
alt: ev.altKey,
|
||||||
|
shift: ev.shiftKey
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// motion example of a left click:
|
/**
|
||||||
// ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7<
|
* Event listener state handling.
|
||||||
function sendMove(ev: MouseEvent): void {
|
* We listen to the onProtocolChange event of CoreMouseService and put
|
||||||
let button = pressed;
|
* requested listeners in `requestedEvents`. With this the listeners
|
||||||
const pos = self._mouseService.getRawByteCoords(ev, self.screenElement, self.cols, self.rows);
|
* have all bits to do the event listener juggling.
|
||||||
if (!pos) return;
|
* Note: 'mousedown' currently is "always on" and not managed
|
||||||
|
* by onProtocolChange.
|
||||||
// buttons marked as motions
|
*/
|
||||||
// are incremented by 32
|
const requestedEvents: {[key: string]: ((ev: Event) => void) | null} = {
|
||||||
button += 32;
|
mouseup: null,
|
||||||
|
wheel: null,
|
||||||
sendEvent(button, pos);
|
mousedrag: null,
|
||||||
}
|
mousemove: null
|
||||||
|
};
|
||||||
// encode button and
|
const eventListeners: {[key: string]: (ev: Event) => void} = {
|
||||||
// position to characters
|
mouseup: (ev: MouseEvent) => {
|
||||||
function encode(data: number[], ch: number): void {
|
sendEvent(ev);
|
||||||
if (!self.utfMouse) {
|
if (!ev.buttons) {
|
||||||
if (ch === 255) {
|
// if no other button is held remove global handlers
|
||||||
data.push(0);
|
this._document.removeEventListener('mouseup', requestedEvents.mouseup);
|
||||||
return;
|
if (requestedEvents.mousedrag) {
|
||||||
|
this._document.removeEventListener('mousemove', requestedEvents.mousedrag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ch > 127) ch = 127;
|
return this.cancel(ev);
|
||||||
data.push(ch);
|
},
|
||||||
|
wheel: (ev: WheelEvent) => {
|
||||||
|
sendEvent(ev);
|
||||||
|
ev.preventDefault();
|
||||||
|
return this.cancel(ev);
|
||||||
|
},
|
||||||
|
mousedrag: (ev: MouseEvent) => {
|
||||||
|
// deal only with move while a button is held
|
||||||
|
if (ev.buttons) {
|
||||||
|
sendEvent(ev);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mousemove: (ev: MouseEvent) => {
|
||||||
|
// deal only with move without any button
|
||||||
|
if (!ev.buttons) {
|
||||||
|
sendEvent(ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this._coreMouseService.onProtocolChange(events => {
|
||||||
|
// apply global changes on events
|
||||||
|
this.mouseEvents = events;
|
||||||
|
if (events) {
|
||||||
|
if (this.optionsService.options.logLevel === 'debug') {
|
||||||
|
this._logService.debug('Binding to mouse events:', this._coreMouseService.explainEvents(events));
|
||||||
|
}
|
||||||
|
this.element.classList.add('enable-mouse-events');
|
||||||
|
this._selectionService.disable();
|
||||||
} else {
|
} else {
|
||||||
if (ch > 2047) {
|
this._logService.debug('Unbinding from mouse events.');
|
||||||
data.push(2047);
|
this.element.classList.remove('enable-mouse-events');
|
||||||
return;
|
this._selectionService.enable();
|
||||||
}
|
|
||||||
data.push(ch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// send a mouse event:
|
|
||||||
// regular/utf8: ^[[M Cb Cx Cy
|
|
||||||
// urxvt: ^[[ Cb ; Cx ; Cy M
|
|
||||||
// sgr: ^[[ Cb ; Cx ; Cy M/m
|
|
||||||
// vt300: ^[[ 24(1/3/5)~ [ Cx , Cy ] \r
|
|
||||||
// locator: CSI P e ; P b ; P r ; P c ; P p & w
|
|
||||||
function sendEvent(button: number, pos: {x: number, y: number}): void {
|
|
||||||
if (self._vt300Mouse) {
|
|
||||||
// NOTE: Unstable.
|
|
||||||
// http://www.vt100.net/docs/vt3xx-gp/chapter15.html
|
|
||||||
button &= 3;
|
|
||||||
pos.x -= 32;
|
|
||||||
pos.y -= 32;
|
|
||||||
let data = C0.ESC + '[24';
|
|
||||||
if (button === 0) data += '1';
|
|
||||||
else if (button === 1) data += '3';
|
|
||||||
else if (button === 2) data += '5';
|
|
||||||
else if (button === 3) return;
|
|
||||||
else data += '0';
|
|
||||||
data += '~[' + pos.x + ',' + pos.y + ']\r';
|
|
||||||
self._coreService.triggerDataEvent(data, true);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self._decLocator) {
|
// add/remove handlers from requestedEvents
|
||||||
// NOTE: Unstable.
|
|
||||||
button &= 3;
|
if (!(events & CoreMouseEventType.MOVE)) {
|
||||||
pos.x -= 32;
|
el.removeEventListener('mousemove', requestedEvents.mousemove);
|
||||||
pos.y -= 32;
|
requestedEvents.mousemove = null;
|
||||||
if (button === 0) button = 2;
|
} else if (!requestedEvents.mousemove) {
|
||||||
else if (button === 1) button = 4;
|
el.addEventListener('mousemove', eventListeners.mousemove);
|
||||||
else if (button === 2) button = 6;
|
requestedEvents.mousemove = eventListeners.mousemove;
|
||||||
else if (button === 3) button = 3;
|
|
||||||
self._coreService.triggerDataEvent(C0.ESC + '['
|
|
||||||
+ button
|
|
||||||
+ ';'
|
|
||||||
+ (button === 3 ? 4 : 0)
|
|
||||||
+ ';'
|
|
||||||
+ pos.y
|
|
||||||
+ ';'
|
|
||||||
+ pos.x
|
|
||||||
+ ';'
|
|
||||||
// Not sure what page is meant to be
|
|
||||||
+ (<any>pos).page || 0
|
|
||||||
+ '&w', true);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.urxvtMouse) {
|
if (!(events & CoreMouseEventType.WHEEL)) {
|
||||||
pos.x -= 32;
|
el.removeEventListener('wheel', requestedEvents.wheel);
|
||||||
pos.y -= 32;
|
requestedEvents.wheel = null;
|
||||||
pos.x++;
|
} else if (!requestedEvents.wheel) {
|
||||||
pos.y++;
|
el.addEventListener('wheel', eventListeners.wheel);
|
||||||
self._coreService.triggerDataEvent(C0.ESC + '[' + button + ';' + pos.x + ';' + pos.y + 'M', true);
|
requestedEvents.wheel = eventListeners.wheel;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.sgrMouse) {
|
if (!(events & CoreMouseEventType.UP)) {
|
||||||
pos.x -= 32;
|
this._document.removeEventListener('mouseup', requestedEvents.mouseup);
|
||||||
pos.y -= 32;
|
requestedEvents.mouseup = null;
|
||||||
self._coreService.triggerDataEvent(C0.ESC + '[<'
|
} else if (!requestedEvents.mouseup) {
|
||||||
+ (((button & 3) === 3 ? button & ~3 : button) - 32)
|
requestedEvents.mouseup = eventListeners.mouseup;
|
||||||
+ ';'
|
|
||||||
+ pos.x
|
|
||||||
+ ';'
|
|
||||||
+ pos.y
|
|
||||||
+ ((button & 3) === 3 ? 'm' : 'M'), true);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const data: number[] = [];
|
if (!(events & CoreMouseEventType.DRAG)) {
|
||||||
|
this._document.removeEventListener('mousemove', requestedEvents.mousedrag);
|
||||||
encode(data, button);
|
requestedEvents.mousedrag = null;
|
||||||
encode(data, pos.x);
|
} else if (!requestedEvents.mousedrag) {
|
||||||
encode(data, pos.y);
|
requestedEvents.mousedrag = eventListeners.mousedrag;
|
||||||
|
|
||||||
self._coreService.triggerDataEvent(C0.ESC + '[M' + String.fromCharCode.apply(String, data), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getButton(ev: MouseEvent): number {
|
|
||||||
let button;
|
|
||||||
let shift;
|
|
||||||
let meta;
|
|
||||||
let ctrl;
|
|
||||||
let mod;
|
|
||||||
|
|
||||||
// two low bits:
|
|
||||||
// 0 = left
|
|
||||||
// 1 = middle
|
|
||||||
// 2 = right
|
|
||||||
// 3 = release
|
|
||||||
// wheel up/down:
|
|
||||||
// 1, and 2 - with 64 added
|
|
||||||
switch ((<any>ev).overrideType || ev.type) {
|
|
||||||
case 'mousedown':
|
|
||||||
button = ev.button !== null && ev.button !== undefined
|
|
||||||
? +ev.button
|
|
||||||
: ev.which !== null && ev.which !== undefined
|
|
||||||
? ev.which - 1
|
|
||||||
: null;
|
|
||||||
break;
|
|
||||||
case 'mouseup':
|
|
||||||
button = 3;
|
|
||||||
break;
|
|
||||||
case 'DOMMouseScroll':
|
|
||||||
button = ev.detail < 0
|
|
||||||
? 64
|
|
||||||
: 65;
|
|
||||||
break;
|
|
||||||
case 'wheel':
|
|
||||||
button = (<WheelEvent>ev).deltaY < 0
|
|
||||||
? 64
|
|
||||||
: 65;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
// force initial onProtocolChange so we dont miss early mouse requests
|
||||||
|
this._coreMouseService.activeProtocol = this._coreMouseService.activeProtocol;
|
||||||
|
|
||||||
// next three bits are the modifiers:
|
/**
|
||||||
// 4 = shift, 8 = meta, 16 = control
|
* "Always on" event listeners.
|
||||||
shift = ev.shiftKey ? 4 : 0;
|
*/
|
||||||
meta = ev.metaKey ? 8 : 0;
|
|
||||||
ctrl = ev.ctrlKey ? 16 : 0;
|
|
||||||
mod = shift | meta | ctrl;
|
|
||||||
|
|
||||||
// no mods
|
|
||||||
if (self.vt200Mouse) {
|
|
||||||
// ctrl only
|
|
||||||
mod &= ctrl;
|
|
||||||
} else if (!self.normalMouse) {
|
|
||||||
mod = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// increment to SP
|
|
||||||
button = (32 + (mod << 2)) + button;
|
|
||||||
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.register(addDisposableDomListener(el, 'mousedown', (ev: MouseEvent) => {
|
this.register(addDisposableDomListener(el, 'mousedown', (ev: MouseEvent) => {
|
||||||
|
|
||||||
// Prevent the focus on the textarea from getting lost
|
|
||||||
// and make sure we get focused on mousedown
|
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
this.focus();
|
this.focus();
|
||||||
|
|
||||||
@@ -954,60 +909,24 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// send the button
|
sendEvent(ev);
|
||||||
sendButton(ev);
|
|
||||||
|
|
||||||
// fix for odd bug
|
// Register additional global handlers which should keep reporting outside
|
||||||
// if (this.vt200Mouse && !this.normalMouse) {
|
// of the terminal element.
|
||||||
if (this.vt200Mouse) {
|
// Note: Other emulators also do this for 'mousedown' while a button
|
||||||
(<any>ev).overrideType = 'mouseup';
|
// is held, we currently limit 'mousedown' to the terminal only.
|
||||||
sendButton(ev);
|
if (requestedEvents.mouseup) {
|
||||||
return this.cancel(ev);
|
this._document.addEventListener('mouseup', requestedEvents.mouseup);
|
||||||
}
|
}
|
||||||
|
if (requestedEvents.mousedrag) {
|
||||||
// TODO: All mouse handling should be pulled into its own file.
|
this._document.addEventListener('mousemove', requestedEvents.mousedrag);
|
||||||
|
|
||||||
// bind events
|
|
||||||
let moveHandler: (event: MouseEvent) => void;
|
|
||||||
if (this.normalMouse) {
|
|
||||||
moveHandler = (event: MouseEvent) => {
|
|
||||||
// Do nothing if normal mouse mode is on. This can happen if the mouse is held down when the
|
|
||||||
// terminal exits normalMouse mode.
|
|
||||||
if (!this.normalMouse) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sendMove(event);
|
|
||||||
};
|
|
||||||
// TODO: these event listeners should be managed by the disposable, the Terminal reference may
|
|
||||||
// be kept aroud if Terminal.dispose is fired when the mouse is down
|
|
||||||
this._document.addEventListener('mousemove', moveHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// x10 compatibility mode can't send button releases
|
|
||||||
const handler = (ev: MouseEvent) => {
|
|
||||||
if (this.normalMouse && !this.x10Mouse) {
|
|
||||||
sendButton(ev);
|
|
||||||
}
|
|
||||||
if (moveHandler) {
|
|
||||||
// Even though this should only be attached when this.normalMouse is true, holding the
|
|
||||||
// mouse button down when normalMouse changes can happen. Just always try to remove it.
|
|
||||||
this._document.removeEventListener('mousemove', moveHandler);
|
|
||||||
moveHandler = null;
|
|
||||||
}
|
|
||||||
this._document.removeEventListener('mouseup', handler);
|
|
||||||
return this.cancel(ev);
|
|
||||||
};
|
|
||||||
this._document.addEventListener('mouseup', handler);
|
|
||||||
|
|
||||||
return this.cancel(ev);
|
return this.cancel(ev);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// if (this.normalMouse) {
|
|
||||||
// on(this.document, 'mousemove', sendMove);
|
|
||||||
// }
|
|
||||||
|
|
||||||
this.register(addDisposableDomListener(el, 'wheel', (ev: WheelEvent) => {
|
this.register(addDisposableDomListener(el, 'wheel', (ev: WheelEvent) => {
|
||||||
if (!this.mouseEvents) {
|
if (!requestedEvents.wheel) {
|
||||||
// Convert wheel events into up/down events when the buffer does not have scrollback, this
|
// Convert wheel events into up/down events when the buffer does not have scrollback, this
|
||||||
// enables scrolling in apps hosted in the alt buffer such as vim or tmux.
|
// enables scrolling in apps hosted in the alt buffer such as vim or tmux.
|
||||||
if (!this.buffer.hasScrollback) {
|
if (!this.buffer.hasScrollback) {
|
||||||
@@ -1028,15 +947,12 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.x10Mouse || this._vt300Mouse || this._decLocator) return;
|
|
||||||
sendButton(ev);
|
|
||||||
ev.preventDefault();
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// allow wheel scrolling in
|
// allow wheel scrolling in
|
||||||
// the shell for example
|
// the shell for example
|
||||||
this.register(addDisposableDomListener(el, 'wheel', (ev: WheelEvent) => {
|
this.register(addDisposableDomListener(el, 'wheel', (ev: WheelEvent) => {
|
||||||
if (this.mouseEvents) return;
|
if (requestedEvents.wheel) return;
|
||||||
if (!this.viewport.onWheel(ev)) {
|
if (!this.viewport.onWheel(ev)) {
|
||||||
return this.cancel(ev);
|
return this.cancel(ev);
|
||||||
}
|
}
|
||||||
@@ -1056,6 +972,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells the renderer to refresh terminal content between two rows (inclusive) at the next
|
* Tells the renderer to refresh terminal content between two rows (inclusive) at the next
|
||||||
* opportunity.
|
* opportunity.
|
||||||
@@ -1835,6 +1752,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
|||||||
this._setup();
|
this._setup();
|
||||||
this._bufferService.reset();
|
this._bufferService.reset();
|
||||||
this._coreService.reset();
|
this._coreService.reset();
|
||||||
|
this._coreMouseService.reset();
|
||||||
if (this._selectionService) {
|
if (this._selectionService) {
|
||||||
this._selectionService.reset();
|
this._selectionService.reset();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
import { IRenderer, IRenderDimensions, CharacterJoinerHandler } from 'browser/renderer/Types';
|
import { IRenderer, IRenderDimensions, CharacterJoinerHandler } from 'browser/renderer/Types';
|
||||||
import { IInputHandlingTerminal, ICompositionHelper, ITerminal, IBrowser, ITerminalOptions } from './Types';
|
import { IInputHandlingTerminal, ICompositionHelper, ITerminal, IBrowser, ITerminalOptions } from './Types';
|
||||||
import { IBuffer, IBufferStringIterator, IBufferSet } from 'common/buffer/Types';
|
import { IBuffer, IBufferStringIterator, IBufferSet } from 'common/buffer/Types';
|
||||||
import { IBufferLine, ICellData, IAttributeData, ICircularList, XtermListener, ICharset } from 'common/Types';
|
import { IBufferLine, ICellData, IAttributeData, ICircularList, XtermListener, ICharset, CoreMouseEventType } from 'common/Types';
|
||||||
import { Buffer } from 'common/buffer/Buffer';
|
import { Buffer } from 'common/buffer/Buffer';
|
||||||
import * as Browser from 'common/Platform';
|
import * as Browser from 'common/Platform';
|
||||||
import { IDisposable, IMarker, IEvent, ISelectionPosition } from 'xterm';
|
import { IDisposable, IMarker, IEvent, ISelectionPosition } from 'xterm';
|
||||||
@@ -219,7 +219,7 @@ export class MockInputHandlingTerminal implements IInputHandlingTerminal {
|
|||||||
x10Mouse: boolean;
|
x10Mouse: boolean;
|
||||||
vt200Mouse: boolean;
|
vt200Mouse: boolean;
|
||||||
normalMouse: boolean;
|
normalMouse: boolean;
|
||||||
mouseEvents: boolean;
|
mouseEvents: CoreMouseEventType;
|
||||||
sendFocus: boolean;
|
sendFocus: boolean;
|
||||||
utfMouse: boolean;
|
utfMouse: boolean;
|
||||||
sgrMouse: boolean;
|
sgrMouse: boolean;
|
||||||
|
|||||||
Vendored
+2
-8
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { ITerminalOptions as IPublicTerminalOptions, IDisposable, IMarker, ISelectionPosition } from 'xterm';
|
import { ITerminalOptions as IPublicTerminalOptions, IDisposable, IMarker, ISelectionPosition } from 'xterm';
|
||||||
import { ICharset, IAttributeData, CharData } from 'common/Types';
|
import { ICharset, IAttributeData, CharData, CoreMouseEventType } from 'common/Types';
|
||||||
import { IEvent, IEventEmitter } from 'common/EventEmitter';
|
import { IEvent, IEventEmitter } from 'common/EventEmitter';
|
||||||
import { IColorSet, ILinkifier, ILinkMatcherOptions, IViewport } from 'browser/Types';
|
import { IColorSet, ILinkifier, ILinkMatcherOptions, IViewport } from 'browser/Types';
|
||||||
import { IOptionsService } from 'common/services/Services';
|
import { IOptionsService } from 'common/services/Services';
|
||||||
@@ -36,14 +36,8 @@ export interface IInputHandlingTerminal {
|
|||||||
bracketedPasteMode: boolean;
|
bracketedPasteMode: boolean;
|
||||||
curAttrData: IAttributeData;
|
curAttrData: IAttributeData;
|
||||||
savedCols: number;
|
savedCols: number;
|
||||||
x10Mouse: boolean;
|
mouseEvents: CoreMouseEventType;
|
||||||
vt200Mouse: boolean;
|
|
||||||
normalMouse: boolean;
|
|
||||||
mouseEvents: boolean;
|
|
||||||
sendFocus: boolean;
|
sendFocus: boolean;
|
||||||
utfMouse: boolean;
|
|
||||||
sgrMouse: boolean;
|
|
||||||
urxvtMouse: boolean;
|
|
||||||
cursorHidden: boolean;
|
cursorHidden: boolean;
|
||||||
|
|
||||||
buffers: IBufferSet;
|
buffers: IBufferSet;
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { IBufferService, ICoreService, ILogService, IOptionsService, ITerminalOptions, IPartialTerminalOptions, IDirtyRowService } from 'common/services/Services';
|
import { IBufferService, ICoreService, ILogService, IOptionsService, ITerminalOptions, IPartialTerminalOptions, IDirtyRowService, ICoreMouseService } from 'common/services/Services';
|
||||||
import { IEvent, EventEmitter } from 'common/EventEmitter';
|
import { IEvent, EventEmitter } from 'common/EventEmitter';
|
||||||
import { clone } from 'common/Clone';
|
import { clone } from 'common/Clone';
|
||||||
import { DEFAULT_OPTIONS } from 'common/services/OptionsService';
|
import { DEFAULT_OPTIONS } from 'common/services/OptionsService';
|
||||||
import { IBufferSet, IBuffer } from 'common/buffer/Types';
|
import { IBufferSet, IBuffer } from 'common/buffer/Types';
|
||||||
import { BufferSet } from 'common/buffer/BufferSet';
|
import { BufferSet } from 'common/buffer/BufferSet';
|
||||||
import { IDecPrivateModes } from 'common/Types';
|
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEventType } from 'common/Types';
|
||||||
|
|
||||||
export class MockBufferService implements IBufferService {
|
export class MockBufferService implements IBufferService {
|
||||||
serviceBrand: any;
|
serviceBrand: any;
|
||||||
@@ -29,6 +29,19 @@ export class MockBufferService implements IBufferService {
|
|||||||
reset(): void {}
|
reset(): void {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class MockCoreMouseService implements ICoreMouseService {
|
||||||
|
activeEncoding: string = '';
|
||||||
|
activeProtocol: string = '';
|
||||||
|
addEncoding(name: string): void {}
|
||||||
|
addProtocol(name: string): void {}
|
||||||
|
reset(): void {}
|
||||||
|
triggerMouseEvent(event: ICoreMouseEvent): boolean { return false; }
|
||||||
|
onProtocolChange: IEvent<CoreMouseEventType> = new EventEmitter<CoreMouseEventType>().event;
|
||||||
|
explainEvents(events: CoreMouseEventType): {[event: string]: boolean} {
|
||||||
|
throw new Error('Method not implemented.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class MockCoreService implements ICoreService {
|
export class MockCoreService implements ICoreService {
|
||||||
serviceBrand: any;
|
serviceBrand: any;
|
||||||
decPrivateModes: IDecPrivateModes = {} as any;
|
decPrivateModes: IDecPrivateModes = {} as any;
|
||||||
|
|||||||
Vendored
+93
@@ -158,3 +158,96 @@ export interface IRowRange {
|
|||||||
start: number;
|
start: number;
|
||||||
end: number;
|
end: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for mouse events in the core.
|
||||||
|
*/
|
||||||
|
export const enum CoreMouseButton {
|
||||||
|
LEFT = 0,
|
||||||
|
MIDDLE = 1,
|
||||||
|
RIGHT = 2,
|
||||||
|
NONE = 3,
|
||||||
|
WHEEL = 4,
|
||||||
|
// additional buttons 1..8
|
||||||
|
// untested!
|
||||||
|
AUX1 = 8,
|
||||||
|
AUX2 = 9,
|
||||||
|
AUX3 = 10,
|
||||||
|
AUX4 = 11,
|
||||||
|
AUX5 = 12,
|
||||||
|
AUX6 = 13,
|
||||||
|
AUX7 = 14,
|
||||||
|
AUX8 = 15
|
||||||
|
}
|
||||||
|
|
||||||
|
export const enum CoreMouseAction {
|
||||||
|
UP = 0, // buttons, wheel
|
||||||
|
DOWN = 1, // buttons, wheel
|
||||||
|
LEFT = 2, // wheel only
|
||||||
|
RIGHT = 3, // wheel only
|
||||||
|
MOVE = 32 // buttons only
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ICoreMouseEvent {
|
||||||
|
/** column (zero based). */
|
||||||
|
col: number;
|
||||||
|
/** row (zero based). */
|
||||||
|
row: number;
|
||||||
|
/**
|
||||||
|
* Button the action occured. Due to restrictions of the tracking protocols
|
||||||
|
* it is not possible to report multiple buttons at once.
|
||||||
|
* Wheel is treated as a button.
|
||||||
|
* There are invalid combinations of buttons and actions possible
|
||||||
|
* (like move + wheel), those are silently ignored by the CoreMouseService.
|
||||||
|
*/
|
||||||
|
button: CoreMouseButton;
|
||||||
|
action: CoreMouseAction;
|
||||||
|
/**
|
||||||
|
* Modifier states.
|
||||||
|
* Protocols will add/ignore those based on specific restrictions.
|
||||||
|
*/
|
||||||
|
ctrl?: boolean;
|
||||||
|
alt?: boolean;
|
||||||
|
shift?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CoreMouseEventType
|
||||||
|
* To be reported to the browser component which events a mouse
|
||||||
|
* protocol wants to be catched and forwarded as an ICoreMouseEvent
|
||||||
|
* to CoreMouseService.
|
||||||
|
*/
|
||||||
|
export const enum CoreMouseEventType {
|
||||||
|
NONE = 0,
|
||||||
|
/** any mousedown event */
|
||||||
|
DOWN = 1,
|
||||||
|
/** any mouseup event */
|
||||||
|
UP = 2,
|
||||||
|
/** any mousemove event while a button is held */
|
||||||
|
DRAG = 4,
|
||||||
|
/** any mousemove event without a button */
|
||||||
|
MOVE = 8,
|
||||||
|
/** any wheel event */
|
||||||
|
WHEEL = 16
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mouse protocol interface.
|
||||||
|
* A mouse protocol can be registered and activated at the CoreMouseService.
|
||||||
|
* `events` should contain a list of needed events as a hint for the browser component
|
||||||
|
* to install/remove the appropriate event handlers.
|
||||||
|
* `restrict` applies further protocol specific restrictions like not allowed
|
||||||
|
* modifiers or filtering invalid event types.
|
||||||
|
*/
|
||||||
|
export interface ICoreMouseProtocol {
|
||||||
|
events: CoreMouseEventType;
|
||||||
|
restrict: (e: ICoreMouseEvent) => boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CoreMouseEncoding
|
||||||
|
* The tracking encoding can be registered and activated at the CoreMouseService.
|
||||||
|
* If a ICoreMouseEvent passes all procotol restrictions it will be encoded
|
||||||
|
* with the active encoding and sent out.
|
||||||
|
*/
|
||||||
|
export type CoreMouseEncoding = (event: ICoreMouseEvent) => string;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { IParsingState, IParams, ParamsArray, IOscParser, IOscHandler, OscFallbackHandlerType } from 'common/parser/Types';
|
import { IParsingState, IParams, ParamsArray, IOscParser, IOscHandler, OscFallbackHandlerType, IFunctionIdentifier } from 'common/parser/Types';
|
||||||
import { EscapeSequenceParser, TransitionTable, VT500_TRANSITION_TABLE } from 'common/parser/EscapeSequenceParser';
|
import { EscapeSequenceParser, TransitionTable, VT500_TRANSITION_TABLE } from 'common/parser/EscapeSequenceParser';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
import { StringToUtf32, stringFromCodePoint, utf32ToString } from 'common/input/TextDecoder';
|
import { StringToUtf32, stringFromCodePoint, utf32ToString } from 'common/input/TextDecoder';
|
||||||
@@ -86,6 +86,9 @@ class TestEscapeSequenceParser extends EscapeSequenceParser {
|
|||||||
public mockOscParser(): void {
|
public mockOscParser(): void {
|
||||||
this._oscParser = oscPutParser;
|
this._oscParser = oscPutParser;
|
||||||
}
|
}
|
||||||
|
public identifier(id: IFunctionIdentifier): number {
|
||||||
|
return this._identifier(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// test object to collect parser actions and compare them with expected values
|
// test object to collect parser actions and compare them with expected values
|
||||||
@@ -1552,5 +1555,110 @@ describe('EscapeSequenceParser', function (): void {
|
|||||||
chai.expect(errorState).eql(null);
|
chai.expect(errorState).eql(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('function identifiers', () => {
|
||||||
|
describe('registration limits', () => {
|
||||||
|
it('prefix range 0x3c .. 0x3f, one byte', () => {
|
||||||
|
for (let i = 0x3c; i <= 0x3f; ++i) {
|
||||||
|
const c = String.fromCharCode(i);
|
||||||
|
chai.expect(parser.identToString(parser.identifier({prefix: c, final: 'z'}))).eql(c + 'z');
|
||||||
|
}
|
||||||
|
chai.assert.throws(() => { parser.identifier({prefix: '\x3b', final: 'z'}); }, 'prefix must be in range 0x3c .. 0x3f');
|
||||||
|
chai.assert.throws(() => { parser.identifier({prefix: '\x40', final: 'z'}); }, 'prefix must be in range 0x3c .. 0x3f');
|
||||||
|
chai.assert.throws(() => { parser.identifier({prefix: '??', final: 'z'}); }, 'only one byte as prefix supported');
|
||||||
|
});
|
||||||
|
it('intermediates range 0x20 .. 0x2f, up to two bytes', () => {
|
||||||
|
for (let i = 0x20; i <= 0x2f; ++i) {
|
||||||
|
const c = String.fromCharCode(i);
|
||||||
|
chai.expect(parser.identToString(parser.identifier({intermediates: c + c, final: 'z'}))).eql(c + c + 'z');
|
||||||
|
}
|
||||||
|
chai.assert.throws(() => { parser.identifier({intermediates: '\x1f', final: 'z'}); }, 'intermediate must be in range 0x20 .. 0x2f');
|
||||||
|
chai.assert.throws(() => { parser.identifier({intermediates: '\x30', final: 'z'}); }, 'intermediate must be in range 0x20 .. 0x2f');
|
||||||
|
chai.assert.throws(() => { parser.identifier({intermediates: '!!!', final: 'z'}); }, 'only two bytes as intermediates are supported');
|
||||||
|
});
|
||||||
|
it('final CSI/DCS range 0x40 .. 0x7e (default), one byte', () => {
|
||||||
|
for (let i = 0x40; i <= 0x7e; ++i) {
|
||||||
|
const c = String.fromCharCode(i);
|
||||||
|
chai.expect(parser.identToString(parser.identifier({final: c}))).eql(c);
|
||||||
|
}
|
||||||
|
chai.assert.throws(() => { parser.identifier({final: '\x3f'}); }, 'final must be in range 64 .. 126');
|
||||||
|
chai.assert.throws(() => { parser.identifier({final: '\x7f'}); }, 'final must be in range 64 .. 126');
|
||||||
|
chai.assert.throws(() => { parser.identifier({final: 'zz'}); }, 'final must be a single byte');
|
||||||
|
});
|
||||||
|
it('final ESC range 0x30 .. 0x7e, one byte', () => {
|
||||||
|
for (let i = 0x30; i <= 0x7e; ++i) {
|
||||||
|
const c = String.fromCharCode(i);
|
||||||
|
let handler: IDisposable | undefined;
|
||||||
|
chai.assert.doesNotThrow(() => { handler = parser.addEscHandler({final: c}, () => {}); }, 'final must be in range 48 .. 126');
|
||||||
|
if (handler) handler.dispose();
|
||||||
|
}
|
||||||
|
chai.assert.throws(() => { parser.addEscHandler({final: '\x2f'}, () => {}); }, 'final must be in range 48 .. 126');
|
||||||
|
chai.assert.throws(() => { parser.addEscHandler({final: '\x7f'}, () => {}); }, 'final must be in range 48 .. 126');
|
||||||
|
});
|
||||||
|
it('id calculation - should stacking prefix -> intermediate -> final', () => {
|
||||||
|
chai.expect(parser.identToString(parser.identifier({final: 'z'}))).eql('z');
|
||||||
|
chai.expect(parser.identToString(parser.identifier({prefix: '?', final: 'z'}))).eql('?z');
|
||||||
|
chai.expect(parser.identToString(parser.identifier({intermediates: '!', final: 'z'}))).eql('!z');
|
||||||
|
chai.expect(parser.identToString(parser.identifier({prefix: '?', intermediates: '!', final: 'z'}))).eql('?!z');
|
||||||
|
chai.expect(parser.identToString(parser.identifier({prefix: '?', intermediates: '!!', final: 'z'}))).eql('?!!z');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('identifier invocation', () => {
|
||||||
|
it('ESC', () => {
|
||||||
|
const callstack: string[] = [];
|
||||||
|
const h1 = parser.addEscHandler({final: 'z'}, () => { callstack.push('z'); });
|
||||||
|
const h2 = parser.addEscHandler({intermediates: '!', final: 'z'}, () => { callstack.push('!z'); });
|
||||||
|
const h3 = parser.addEscHandler({intermediates: '!!', final: 'z'}, () => { callstack.push('!!z'); });
|
||||||
|
parse(parser, '\x1bz\x1b!z\x1b!!z');
|
||||||
|
h1.dispose();
|
||||||
|
h2.dispose();
|
||||||
|
h3.dispose();
|
||||||
|
parse(parser, '\x1bz\x1b!z\x1b!!z');
|
||||||
|
chai.expect(callstack).eql(['z', '!z', '!!z']);
|
||||||
|
});
|
||||||
|
it('CSI', () => {
|
||||||
|
const callstack: any[] = [];
|
||||||
|
const h1 = parser.addCsiHandler({final: 'z'}, params => { callstack.push(['z', params.toArray()]); });
|
||||||
|
const h2 = parser.addCsiHandler({intermediates: '!', final: 'z'}, params => { callstack.push(['!z', params.toArray()]); });
|
||||||
|
const h3 = parser.addCsiHandler({intermediates: '!!', final: 'z'}, params => { callstack.push(['!!z', params.toArray()]); });
|
||||||
|
const h4 = parser.addCsiHandler({prefix: '?', final: 'z'}, params => { callstack.push(['?z', params.toArray()]); });
|
||||||
|
const h5 = parser.addCsiHandler({prefix: '?', intermediates: '!', final: 'z'}, params => { callstack.push(['?!z', params.toArray()]); });
|
||||||
|
const h6 = parser.addCsiHandler({prefix: '?', intermediates: '!!', final: 'z'}, params => { callstack.push(['?!!z', params.toArray()]); });
|
||||||
|
parse(parser, '\x1b[1;z\x1b[1;!z\x1b[1;!!z\x1b[?1;z\x1b[?1;!z\x1b[?1;!!z');
|
||||||
|
h1.dispose();
|
||||||
|
h2.dispose();
|
||||||
|
h3.dispose();
|
||||||
|
h4.dispose();
|
||||||
|
h5.dispose();
|
||||||
|
h6.dispose();
|
||||||
|
parse(parser, '\x1b[1;z\x1b[1;!z\x1b[1;!!z\x1b[?1;z\x1b[?1;!z\x1b[?1;!!z');
|
||||||
|
chai.expect(callstack).eql([['z', [1, 0]], ['!z', [1, 0]], ['!!z', [1, 0]], ['?z', [1, 0]], ['?!z', [1, 0]], ['?!!z', [1, 0]]]);
|
||||||
|
});
|
||||||
|
it('DCS', () => {
|
||||||
|
const callstack: any[] = [];
|
||||||
|
const h1 = parser.addDcsHandler({final: 'z'}, new DcsHandler((data, params) => { callstack.push(['z', params.toArray(), data]); }));
|
||||||
|
const h2 = parser.addDcsHandler({intermediates: '!', final: 'z'}, new DcsHandler((data, params) => { callstack.push(['!z', params.toArray(), data]); }));
|
||||||
|
const h3 = parser.addDcsHandler({intermediates: '!!', final: 'z'}, new DcsHandler((data, params) => { callstack.push(['!!z', params.toArray(), data]); }));
|
||||||
|
const h4 = parser.addDcsHandler({prefix: '?', final: 'z'}, new DcsHandler((data, params) => { callstack.push(['?z', params.toArray(), data]); }));
|
||||||
|
const h5 = parser.addDcsHandler({prefix: '?', intermediates: '!', final: 'z'}, new DcsHandler((data, params) => { callstack.push(['?!z', params.toArray(), data]); }));
|
||||||
|
const h6 = parser.addDcsHandler({prefix: '?', intermediates: '!!', final: 'z'}, new DcsHandler((data, params) => { callstack.push(['?!!z', params.toArray(), data]); }));
|
||||||
|
parse(parser, '\x1bP1;zAB\x1b\\\x1bP1;!zAB\x1b\\\x1bP1;!!zAB\x1b\\\x1bP?1;zAB\x1b\\\x1bP?1;!zAB\x1b\\\x1bP?1;!!zAB\x1b\\');
|
||||||
|
h1.dispose();
|
||||||
|
h2.dispose();
|
||||||
|
h3.dispose();
|
||||||
|
h4.dispose();
|
||||||
|
h5.dispose();
|
||||||
|
h6.dispose();
|
||||||
|
parse(parser, '\x1bP1;zAB\x1b\\\x1bP1;!zAB\x1b\\\x1bP1;!!zAB\x1b\\\x1bP?1;zAB\x1b\\\x1bP?1;!zAB\x1b\\\x1bP?1;!!zAB\x1b\\');
|
||||||
|
chai.expect(callstack).eql([
|
||||||
|
['z', [1, 0], 'AB'],
|
||||||
|
['!z', [1, 0], 'AB'],
|
||||||
|
['!!z', [1, 0], 'AB'],
|
||||||
|
['?z', [1, 0], 'AB'],
|
||||||
|
['?!z', [1, 0], 'AB'],
|
||||||
|
['?!!z', [1, 0], 'AB']
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
// TODO: error conditions and error recovery (not implemented yet in parser)
|
// TODO: error conditions and error recovery (not implemented yet in parser)
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
|
|||||||
this.setEscHandler({final: '\\'}, () => {});
|
this.setEscHandler({final: '\\'}, () => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _identifier(id: IFunctionIdentifier, finalRange: number[] = [0x40, 0x7e]): number {
|
protected _identifier(id: IFunctionIdentifier, finalRange: number[] = [0x40, 0x7e]): number {
|
||||||
let res = 0;
|
let res = 0;
|
||||||
if (id.prefix) {
|
if (id.prefix) {
|
||||||
if (id.prefix.length > 1) {
|
if (id.prefix.length > 1) {
|
||||||
@@ -558,6 +558,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
|
|||||||
i--;
|
i--;
|
||||||
break;
|
break;
|
||||||
case ParserAction.COLLECT:
|
case ParserAction.COLLECT:
|
||||||
|
collect <<= 8;
|
||||||
collect |= code;
|
collect |= code;
|
||||||
break;
|
break;
|
||||||
case ParserAction.ESC_DISPATCH:
|
case ParserAction.ESC_DISPATCH:
|
||||||
|
|||||||
@@ -0,0 +1,218 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
import { CoreMouseService } from 'common/services/CoreMouseService';
|
||||||
|
import { MockCoreService, MockBufferService } from 'common/TestUtils.test';
|
||||||
|
import { assert } from 'chai';
|
||||||
|
import { ICoreMouseEvent, CoreMouseEventType, CoreMouseButton, CoreMouseAction } from 'common/Types';
|
||||||
|
|
||||||
|
// needed mock services
|
||||||
|
const bufferService = new MockBufferService(300, 100);
|
||||||
|
const coreService = new MockCoreService();
|
||||||
|
|
||||||
|
function toBytes(s: string | undefined): number[] {
|
||||||
|
if (!s) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const res: number[] = [];
|
||||||
|
for (let i = 0; i < s.length; ++i) {
|
||||||
|
res.push(s.charCodeAt(i));
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('CoreMouseService', () => {
|
||||||
|
it('init', () => {
|
||||||
|
const cms = new CoreMouseService(bufferService, coreService);
|
||||||
|
assert.equal(cms.activeEncoding, 'DEFAULT');
|
||||||
|
assert.equal(cms.activeProtocol, 'NONE');
|
||||||
|
});
|
||||||
|
it('default protocols - NONE, X10, VT200, DRAG, ANY', () => {
|
||||||
|
const cms = new CoreMouseService(bufferService, coreService);
|
||||||
|
assert.deepEqual(Object.keys((cms as any)._protocols), ['NONE', 'X10', 'VT200', 'DRAG', 'ANY']);
|
||||||
|
});
|
||||||
|
it('default encodings - DEFAULT, UTF8, SGR, URXVT', () => {
|
||||||
|
const cms = new CoreMouseService(bufferService, coreService);
|
||||||
|
assert.deepEqual(Object.keys((cms as any)._encodings), ['DEFAULT', 'UTF8', 'SGR', 'URXVT']);
|
||||||
|
});
|
||||||
|
it('protocol/encoding setter, reset', () => {
|
||||||
|
const cms = new CoreMouseService(bufferService, coreService);
|
||||||
|
cms.activeEncoding = 'SGR';
|
||||||
|
cms.activeProtocol = 'ANY';
|
||||||
|
assert.equal(cms.activeEncoding, 'SGR');
|
||||||
|
assert.equal(cms.activeProtocol, 'ANY');
|
||||||
|
cms.reset();
|
||||||
|
assert.equal(cms.activeEncoding, 'DEFAULT');
|
||||||
|
assert.equal(cms.activeProtocol, 'NONE');
|
||||||
|
assert.throws(() => { cms.activeEncoding = 'xyz'; }, 'unknown encoding "xyz"');
|
||||||
|
assert.throws(() => { cms.activeProtocol = 'xyz'; }, 'unknown protocol "xyz"');
|
||||||
|
});
|
||||||
|
it('addEncoding', () => {
|
||||||
|
const cms = new CoreMouseService(bufferService, coreService);
|
||||||
|
cms.addEncoding('XYZ', (e: ICoreMouseEvent) => '');
|
||||||
|
cms.activeEncoding = 'XYZ';
|
||||||
|
assert.equal(cms.activeEncoding, 'XYZ');
|
||||||
|
});
|
||||||
|
it('addProtocol', () => {
|
||||||
|
const cms = new CoreMouseService(bufferService, coreService);
|
||||||
|
cms.addProtocol('XYZ', { events: CoreMouseEventType.NONE, restrict: (e: ICoreMouseEvent) => false });
|
||||||
|
cms.activeProtocol = 'XYZ';
|
||||||
|
assert.equal(cms.activeProtocol, 'XYZ');
|
||||||
|
});
|
||||||
|
it('onProtocolChange', () => {
|
||||||
|
const cms = new CoreMouseService(bufferService, coreService);
|
||||||
|
const wantedEvents: CoreMouseEventType[] = [];
|
||||||
|
cms.onProtocolChange(events => wantedEvents.push(events));
|
||||||
|
cms.activeProtocol = 'NONE';
|
||||||
|
assert.deepEqual(wantedEvents, [CoreMouseEventType.NONE]);
|
||||||
|
cms.activeProtocol = 'ANY';
|
||||||
|
assert.deepEqual(wantedEvents, [
|
||||||
|
CoreMouseEventType.NONE,
|
||||||
|
CoreMouseEventType.DOWN | CoreMouseEventType.UP | CoreMouseEventType.WHEEL | CoreMouseEventType.DRAG | CoreMouseEventType.MOVE
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
describe('triggerMouseEvent', () => {
|
||||||
|
let cms: CoreMouseService;
|
||||||
|
let reports: string[];
|
||||||
|
beforeEach(() => {
|
||||||
|
cms = new CoreMouseService(bufferService, coreService);
|
||||||
|
reports = [];
|
||||||
|
coreService.triggerDataEvent = (data: string, userInput?: boolean) => reports.push(data);
|
||||||
|
});
|
||||||
|
it('NONE', () => {
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.DOWN }), false);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.UP }), false);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.MOVE }), false);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.MIDDLE, action: CoreMouseAction.DOWN }), false);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.RIGHT, action: CoreMouseAction.DOWN }), false);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.WHEEL, action: CoreMouseAction.UP }), false);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.NONE, action: CoreMouseAction.MOVE }), false);
|
||||||
|
});
|
||||||
|
it('X10', () => {
|
||||||
|
cms.activeProtocol = 'X10';
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.DOWN }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.UP }), false);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.MOVE }), false);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.MIDDLE, action: CoreMouseAction.DOWN }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.RIGHT, action: CoreMouseAction.DOWN }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.WHEEL, action: CoreMouseAction.UP }), false);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.NONE, action: CoreMouseAction.MOVE }), false);
|
||||||
|
});
|
||||||
|
it('VT200', () => {
|
||||||
|
cms.activeProtocol = 'VT200';
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.DOWN }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.UP }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.MOVE }), false);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.MIDDLE, action: CoreMouseAction.DOWN }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.RIGHT, action: CoreMouseAction.DOWN }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.WHEEL, action: CoreMouseAction.UP }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.NONE, action: CoreMouseAction.MOVE }), false);
|
||||||
|
});
|
||||||
|
it('DRAG', () => {
|
||||||
|
cms.activeProtocol = 'DRAG';
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.DOWN }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.UP }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.MOVE }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.MIDDLE, action: CoreMouseAction.DOWN }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.RIGHT, action: CoreMouseAction.DOWN }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.WHEEL, action: CoreMouseAction.UP }), true);
|
||||||
|
});
|
||||||
|
it('ANY', () => {
|
||||||
|
cms.activeProtocol = 'ANY';
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.DOWN }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.UP }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.MOVE }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.MIDDLE, action: CoreMouseAction.DOWN }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.RIGHT, action: CoreMouseAction.DOWN }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.WHEEL, action: CoreMouseAction.UP }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.NONE, action: CoreMouseAction.MOVE }), true);
|
||||||
|
// should not report in any case
|
||||||
|
// invalid button + action combinations
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.WHEEL, action: CoreMouseAction.MOVE }), false);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.NONE, action: CoreMouseAction.DOWN }), false);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.NONE, action: CoreMouseAction.UP }), false);
|
||||||
|
// invalid coords
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: -1, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.DOWN }), false);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 500, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.DOWN }), false);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: -1, button: CoreMouseButton.LEFT, action: CoreMouseAction.DOWN }), false);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 500, button: CoreMouseButton.LEFT, action: CoreMouseAction.DOWN }), false);
|
||||||
|
});
|
||||||
|
describe('coords', () => {
|
||||||
|
it('DEFAULT encoding', () => {
|
||||||
|
cms.activeProtocol = 'ANY';
|
||||||
|
for (let i = 0; i < bufferService.cols; ++i) {
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: i, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.DOWN }), true);
|
||||||
|
// capped at 95
|
||||||
|
if (i < 95) {
|
||||||
|
assert.deepEqual(toBytes(reports.pop()), [0x1b, 0x5b, 0x4d, 0x20, i + 33, 0x21]);
|
||||||
|
} else {
|
||||||
|
assert.deepEqual(toBytes(reports.pop()), [0x1b, 0x5b, 0x4d, 0x20, 0x7f, 0x21]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it('UTF8 encoding', () => {
|
||||||
|
cms.activeProtocol = 'ANY';
|
||||||
|
cms.activeEncoding = 'UTF8';
|
||||||
|
for (let i = 0; i < bufferService.cols; ++i) {
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: i, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.DOWN }), true);
|
||||||
|
assert.deepEqual(toBytes(reports.pop()), [0x1b, 0x5b, 0x4d, 0x20, i + 33, 0x21]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it('SGR encoding', () => {
|
||||||
|
cms.activeProtocol = 'ANY';
|
||||||
|
cms.activeEncoding = 'SGR';
|
||||||
|
for (let i = 0; i < bufferService.cols; ++i) {
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: i, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.DOWN }), true);
|
||||||
|
assert.deepEqual(reports.pop(), `\x1b[<0;${i + 1};1M`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it('URXVT', () => {
|
||||||
|
cms.activeProtocol = 'ANY';
|
||||||
|
cms.activeEncoding = 'URXVT';
|
||||||
|
for (let i = 0; i < bufferService.cols; ++i) {
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: i, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.DOWN }), true);
|
||||||
|
assert.deepEqual(reports.pop(), `\x1b[32;${i + 1};1M`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('eventCodes with modifiers (DEFAULT encoding)', () => {
|
||||||
|
// TODO: implement AUX button tests
|
||||||
|
cms.activeProtocol = 'ANY';
|
||||||
|
cms.activeEncoding = 'DEFAULT';
|
||||||
|
// all buttons + down + no modifer
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.DOWN, ctrl: false, alt: false, shift: false }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.MIDDLE, action: CoreMouseAction.DOWN, ctrl: false, alt: false, shift: false }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.RIGHT, action: CoreMouseAction.DOWN, ctrl: false, alt: false, shift: false }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.WHEEL, action: CoreMouseAction.DOWN, ctrl: false, alt: false, shift: false }), true);
|
||||||
|
assert.deepEqual(reports, ['\x1b[M !!', '\x1b[M!!!', '\x1b[M"!!', '\x1b[Ma!!']);
|
||||||
|
while (reports.pop()) { }
|
||||||
|
|
||||||
|
// all buttons + up + no modifier
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.UP, ctrl: false, alt: false, shift: false }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.MIDDLE, action: CoreMouseAction.UP, ctrl: false, alt: false, shift: false }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.RIGHT, action: CoreMouseAction.UP, ctrl: false, alt: false, shift: false }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.WHEEL, action: CoreMouseAction.UP, ctrl: false, alt: false, shift: false }), true);
|
||||||
|
assert.deepEqual(reports, ['\x1b[M#!!', '\x1b[M#!!', '\x1b[M#!!', '\x1b[M`!!']);
|
||||||
|
while (reports.pop()) { }
|
||||||
|
|
||||||
|
// all buttons + move + no modifier
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.LEFT, action: CoreMouseAction.MOVE, ctrl: false, alt: false, shift: false }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.MIDDLE, action: CoreMouseAction.MOVE, ctrl: false, alt: false, shift: false }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.RIGHT, action: CoreMouseAction.MOVE, ctrl: false, alt: false, shift: false }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.NONE, action: CoreMouseAction.MOVE, ctrl: false, alt: false, shift: false }), true);
|
||||||
|
assert.deepEqual(reports, ['\x1b[M@!!', '\x1b[MA!!', '\x1b[MB!!', '\x1b[MC!!']);
|
||||||
|
while (reports.pop()) { }
|
||||||
|
|
||||||
|
// button none + move + modifiers
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.NONE, action: CoreMouseAction.MOVE, ctrl: true, alt: false, shift: false }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.NONE, action: CoreMouseAction.MOVE, ctrl: false, alt: true, shift: false }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.NONE, action: CoreMouseAction.MOVE, ctrl: false, alt: false, shift: true }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.NONE, action: CoreMouseAction.MOVE, ctrl: true, alt: true, shift: false }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.NONE, action: CoreMouseAction.MOVE, ctrl: false, alt: true, shift: true }), true);
|
||||||
|
assert.equal(cms.triggerMouseEvent({ col: 0, row: 0, button: CoreMouseButton.NONE, action: CoreMouseAction.MOVE, ctrl: true, alt: true, shift: true }), true);
|
||||||
|
assert.deepEqual(reports, ['\x1b[MS!!', '\x1b[MK!!', '\x1b[MG!!', '\x1b[M[!!', '\x1b[MO!!', '\x1b[M_!!']);
|
||||||
|
while (reports.pop()) { }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,315 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
import { IBufferService, ICoreService, ICoreMouseService } from 'common/services/Services';
|
||||||
|
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
||||||
|
import { ICoreMouseProtocol, ICoreMouseEvent, CoreMouseEncoding, CoreMouseEventType, CoreMouseButton, CoreMouseAction } from 'common/Types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supported default protocols.
|
||||||
|
*/
|
||||||
|
const DEFAULT_PROTOCOLS: {[key: string]: ICoreMouseProtocol} = {
|
||||||
|
/**
|
||||||
|
* NONE
|
||||||
|
* Events: none
|
||||||
|
* Modifiers: none
|
||||||
|
*/
|
||||||
|
NONE: {
|
||||||
|
events: CoreMouseEventType.NONE,
|
||||||
|
restrict: () => false
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* X10
|
||||||
|
* Events: mousedown
|
||||||
|
* Modifiers: none
|
||||||
|
*/
|
||||||
|
X10: {
|
||||||
|
events: CoreMouseEventType.DOWN,
|
||||||
|
restrict: (e: ICoreMouseEvent) => {
|
||||||
|
// no wheel, no move, no up
|
||||||
|
if (e.button === CoreMouseButton.WHEEL || e.action !== CoreMouseAction.DOWN) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// no modifiers
|
||||||
|
e.ctrl = false;
|
||||||
|
e.alt = false;
|
||||||
|
e.shift = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* VT200
|
||||||
|
* Events: mousedown / mouseup / wheel
|
||||||
|
* Modifiers: all
|
||||||
|
*/
|
||||||
|
VT200: {
|
||||||
|
events: CoreMouseEventType.DOWN | CoreMouseEventType.UP | CoreMouseEventType.WHEEL,
|
||||||
|
restrict: (e: ICoreMouseEvent) => {
|
||||||
|
// no move
|
||||||
|
if (e.action === CoreMouseAction.MOVE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* DRAG
|
||||||
|
* Events: mousedown / mouseup / wheel / mousedrag
|
||||||
|
* Modifiers: all
|
||||||
|
*/
|
||||||
|
DRAG: {
|
||||||
|
events: CoreMouseEventType.DOWN | CoreMouseEventType.UP | CoreMouseEventType.WHEEL | CoreMouseEventType.DRAG,
|
||||||
|
restrict: (e: ICoreMouseEvent) => {
|
||||||
|
// no move without button
|
||||||
|
if (e.action === CoreMouseAction.MOVE && e.button === CoreMouseButton.NONE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* ANY
|
||||||
|
* Events: all mouse related events
|
||||||
|
* Modifiers: all
|
||||||
|
*/
|
||||||
|
ANY: {
|
||||||
|
events:
|
||||||
|
CoreMouseEventType.DOWN | CoreMouseEventType.UP | CoreMouseEventType.WHEEL
|
||||||
|
| CoreMouseEventType.DRAG | CoreMouseEventType.MOVE,
|
||||||
|
restrict: (e: ICoreMouseEvent) => true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const enum Modifiers {
|
||||||
|
SHIFT = 4,
|
||||||
|
ALT = 8,
|
||||||
|
CTRL = 16
|
||||||
|
}
|
||||||
|
|
||||||
|
// helper for default encoders to generate the event code.
|
||||||
|
function eventCode(e: ICoreMouseEvent, isSGR: boolean): number {
|
||||||
|
let code = (e.ctrl ? Modifiers.CTRL : 0) | (e.shift ? Modifiers.SHIFT : 0) | (e.alt ? Modifiers.ALT : 0);
|
||||||
|
if (e.button === CoreMouseButton.WHEEL) {
|
||||||
|
code |= 64;
|
||||||
|
code |= e.action;
|
||||||
|
} else {
|
||||||
|
code |= e.button & 3;
|
||||||
|
if (e.button & 4) {
|
||||||
|
code |= 64;
|
||||||
|
}
|
||||||
|
if (e.button & 8) {
|
||||||
|
code |= 128;
|
||||||
|
}
|
||||||
|
if (e.action === CoreMouseAction.MOVE) {
|
||||||
|
code |= CoreMouseAction.MOVE;
|
||||||
|
} else if (e.action === CoreMouseAction.UP && !isSGR) {
|
||||||
|
// special case - only SGR can report button on release
|
||||||
|
// all others have to go with NONE
|
||||||
|
code |= CoreMouseButton.NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
const S = String.fromCharCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supported default encodings.
|
||||||
|
*/
|
||||||
|
const DEFAULT_ENCODINGS: {[key: string]: CoreMouseEncoding} = {
|
||||||
|
/**
|
||||||
|
* DEFAULT - CSI M Pb Px Py
|
||||||
|
* Single byte encoding for coords and event code.
|
||||||
|
* Can encode values up to 223. The Encoding of higher
|
||||||
|
* values is not UTF-8 compatible (and currently limited
|
||||||
|
* to 95 in xterm.js).
|
||||||
|
*/
|
||||||
|
DEFAULT: (e: ICoreMouseEvent) => {
|
||||||
|
let params = [eventCode(e, false) + 32, e.col + 32, e.row + 32];
|
||||||
|
// FIXME: we are currently limited to ASCII range
|
||||||
|
params = params.map(v => (v > 127) ? 127 : v);
|
||||||
|
// FIXED: params = params.map(v => (v > 255) ? 0 : value);
|
||||||
|
return `\x1b[M${S(params[0])}${S(params[1])}${S(params[2])}`;
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* UTF8 - CSI M Pb Px Py
|
||||||
|
* Same as DEFAULT, but with optional 2-byte UTF8
|
||||||
|
* encoding for values > 223 (can encode up to 2015).
|
||||||
|
*/
|
||||||
|
UTF8: (e: ICoreMouseEvent) => {
|
||||||
|
let params = [eventCode(e, false) + 32, e.col + 32, e.row + 32];
|
||||||
|
// limit to 2-byte UTF8
|
||||||
|
params = params.map(v => (v > 2047) ? 0 : v);
|
||||||
|
return `\x1b[M${S(params[0])}${S(params[1])}${S(params[2])}`;
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* SGR - CSI < Pb ; Px ; Py M|m
|
||||||
|
* No encoding limitation.
|
||||||
|
* Can report button on release and works with a well formed sequence.
|
||||||
|
*/
|
||||||
|
SGR: (e: ICoreMouseEvent) => {
|
||||||
|
const final = (e.action === CoreMouseAction.UP && e.button !== CoreMouseButton.WHEEL) ? 'm' : 'M';
|
||||||
|
return `\x1b[<${eventCode(e, true)};${e.col};${e.row}${final}`;
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* URXVT - CSI Pb ; Px ; Py M
|
||||||
|
* Same button encoding as default, decimal encoding for coords.
|
||||||
|
* Ambiguity with other sequences, should not be used.
|
||||||
|
*/
|
||||||
|
URXVT: (e: ICoreMouseEvent) => {
|
||||||
|
return `\x1b[${eventCode(e, false) + 32};${e.col};${e.row}M`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CoreMouseService
|
||||||
|
*
|
||||||
|
* Provides mouse tracking reports with different protocols and encodings.
|
||||||
|
* - protocols: NONE (default), X10, VT200, DRAG, ANY
|
||||||
|
* - encodings: DEFAULT, SGR, UTF8, URXVT
|
||||||
|
*
|
||||||
|
* Custom protocols/encodings can be added by `addProtocol` / `addEncoding`.
|
||||||
|
* To activate a protocol/encoding, set `activeProtocol` / `activeEncoding`.
|
||||||
|
* Switching a protocol will send a notification event `onProtocolChange`
|
||||||
|
* with a list of needed events to track.
|
||||||
|
*
|
||||||
|
* The service handles the mouse tracking state and decides whether to send
|
||||||
|
* a tracking report to the backend based on protocol and encoding limitations.
|
||||||
|
* To send a mouse event call `triggerMouseEvent`.
|
||||||
|
*/
|
||||||
|
export class CoreMouseService implements ICoreMouseService {
|
||||||
|
private _protocols: {[name: string]: ICoreMouseProtocol} = {};
|
||||||
|
private _encodings: {[name: string]: CoreMouseEncoding} = {};
|
||||||
|
private _activeProtocol: string = '';
|
||||||
|
private _activeEncoding: string = '';
|
||||||
|
private _onProtocolChange = new EventEmitter<CoreMouseEventType>();
|
||||||
|
private _lastEvent: ICoreMouseEvent | null = null;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@IBufferService private readonly _bufferService: IBufferService,
|
||||||
|
@ICoreService private readonly _coreService: ICoreService
|
||||||
|
) {
|
||||||
|
// register default protocols and encodings
|
||||||
|
Object.keys(DEFAULT_PROTOCOLS).forEach(name => this.addProtocol(name, DEFAULT_PROTOCOLS[name]));
|
||||||
|
Object.keys(DEFAULT_ENCODINGS).forEach(name => this.addEncoding(name, DEFAULT_ENCODINGS[name]));
|
||||||
|
// call reset to set defaults
|
||||||
|
this.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public addProtocol(name: string, protocol: ICoreMouseProtocol): void {
|
||||||
|
this._protocols[name] = protocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
public addEncoding(name: string, encoding: CoreMouseEncoding): void {
|
||||||
|
this._encodings[name] = encoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get activeProtocol(): string {
|
||||||
|
return this._activeProtocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set activeProtocol(name: string) {
|
||||||
|
if (!this._protocols[name]) {
|
||||||
|
throw new Error(`unknown protocol "${name}"`);
|
||||||
|
}
|
||||||
|
this._activeProtocol = name;
|
||||||
|
this._onProtocolChange.fire(this._protocols[name].events);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get activeEncoding(): string {
|
||||||
|
return this._activeEncoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set activeEncoding(name: string) {
|
||||||
|
if (!this._encodings[name]) {
|
||||||
|
throw new Error(`unknown encoding "${name}"`);
|
||||||
|
}
|
||||||
|
this._activeEncoding = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public reset(): void {
|
||||||
|
this.activeProtocol = 'NONE';
|
||||||
|
this.activeEncoding = 'DEFAULT';
|
||||||
|
this._lastEvent = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event to announce changes in mouse tracking.
|
||||||
|
*/
|
||||||
|
public get onProtocolChange(): IEvent<CoreMouseEventType> {
|
||||||
|
return this._onProtocolChange.event;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers a mouse event to be sent.
|
||||||
|
*
|
||||||
|
* Returns true if the event passed all protocol restrictions and a report
|
||||||
|
* was sent, otherwise false. The return value may be used to decide whether
|
||||||
|
* the default event action in the bowser component should be omitted.
|
||||||
|
*
|
||||||
|
* Note: The method will change values of the given event object
|
||||||
|
* to fullfill protocol and encoding restrictions.
|
||||||
|
*/
|
||||||
|
public triggerMouseEvent(e: ICoreMouseEvent): boolean {
|
||||||
|
// range check for col/row
|
||||||
|
if (e.col < 0 || e.col >= this._bufferService.cols
|
||||||
|
|| e.row < 0 || e.row >= this._bufferService.rows) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// filter nonsense combinations of button + action
|
||||||
|
if (e.button === CoreMouseButton.WHEEL && e.action === CoreMouseAction.MOVE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (e.button === CoreMouseButton.NONE && e.action !== CoreMouseAction.MOVE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (e.button !== CoreMouseButton.WHEEL && (e.action === CoreMouseAction.LEFT || e.action === CoreMouseAction.RIGHT)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// report 1-based coords
|
||||||
|
e.col++;
|
||||||
|
e.row++;
|
||||||
|
|
||||||
|
// debounce move at grid level
|
||||||
|
if (e.action === CoreMouseAction.MOVE && this._lastEvent && this._compareEvents(this._lastEvent, e)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// apply protocol restrictions
|
||||||
|
if (!this._protocols[this._activeProtocol].restrict(e)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// encode report and send
|
||||||
|
const report = this._encodings[this._activeEncoding](e);
|
||||||
|
this._coreService.triggerDataEvent(report, true);
|
||||||
|
|
||||||
|
this._lastEvent = e;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public explainEvents(events: CoreMouseEventType): {[event: string]: boolean} {
|
||||||
|
return {
|
||||||
|
DOWN: !!(events & CoreMouseEventType.DOWN),
|
||||||
|
UP: !!(events & CoreMouseEventType.UP),
|
||||||
|
DRAG: !!(events & CoreMouseEventType.DRAG),
|
||||||
|
MOVE: !!(events & CoreMouseEventType.MOVE),
|
||||||
|
WHEEL: !!(events & CoreMouseEventType.WHEEL)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private _compareEvents(e1: ICoreMouseEvent, e2: ICoreMouseEvent): boolean {
|
||||||
|
if (e1.col !== e2.col) return false;
|
||||||
|
if (e1.row !== e2.row) return false;
|
||||||
|
if (e1.button !== e2.button) return false;
|
||||||
|
if (e1.action !== e2.action) return false;
|
||||||
|
if (e1.ctrl !== e2.ctrl) return false;
|
||||||
|
if (e1.alt !== e2.alt) return false;
|
||||||
|
if (e1.shift !== e2.shift) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import { IEvent } from 'common/EventEmitter';
|
import { IEvent } from 'common/EventEmitter';
|
||||||
import { IBuffer, IBufferSet } from 'common/buffer/Types';
|
import { IBuffer, IBufferSet } from 'common/buffer/Types';
|
||||||
import { IDecPrivateModes } from 'common/Types';
|
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEncoding, ICoreMouseProtocol, CoreMouseEventType } from 'common/Types';
|
||||||
import { createDecorator } from 'common/services/ServiceRegistry';
|
import { createDecorator } from 'common/services/ServiceRegistry';
|
||||||
|
|
||||||
export const IBufferService = createDecorator<IBufferService>('BufferService');
|
export const IBufferService = createDecorator<IBufferService>('BufferService');
|
||||||
@@ -23,6 +23,37 @@ export interface IBufferService {
|
|||||||
reset(): void;
|
reset(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ICoreMouseService = createDecorator<ICoreMouseService>('CoreMouseService');
|
||||||
|
export interface ICoreMouseService {
|
||||||
|
activeProtocol: string;
|
||||||
|
activeEncoding: string;
|
||||||
|
addProtocol(name: string, protocol: ICoreMouseProtocol): void;
|
||||||
|
addEncoding(name: string, encoding: CoreMouseEncoding): void;
|
||||||
|
reset(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers a mouse event to be sent.
|
||||||
|
*
|
||||||
|
* Returns true if the event passed all protocol restrictions and a report
|
||||||
|
* was sent, otherwise false. The return value may be used to decide whether
|
||||||
|
* the default event action in the bowser component should be omitted.
|
||||||
|
*
|
||||||
|
* Note: The method will change values of the given event object
|
||||||
|
* to fullfill protocol and encoding restrictions.
|
||||||
|
*/
|
||||||
|
triggerMouseEvent(event: ICoreMouseEvent): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event to announce changes in mouse tracking.
|
||||||
|
*/
|
||||||
|
onProtocolChange: IEvent<CoreMouseEventType>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Human readable version of mouse events.
|
||||||
|
*/
|
||||||
|
explainEvents(events: CoreMouseEventType): {[event: string]: boolean};
|
||||||
|
}
|
||||||
|
|
||||||
export const ICoreService = createDecorator<ICoreService>('CoreService');
|
export const ICoreService = createDecorator<ICoreService>('CoreService');
|
||||||
export interface ICoreService {
|
export interface ICoreService {
|
||||||
serviceBrand: any;
|
serviceBrand: any;
|
||||||
|
|||||||
+874
-363
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user