Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

CoreMouseService #2323

Merged
merged 29 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4858bdc
CoreMouseService
jerch Jul 18, 2019
e38a68e
debounce events at grid level
jerch Jul 19, 2019
df0cf25
debounce only move events
jerch Jul 19, 2019
cbddbc6
some changes in mouse event handling:
jerch Jul 19, 2019
b64ed4f
cleanup sendEvent, switch reported button during move
jerch Jul 19, 2019
6465ab9
Merge branch 'master' into mouse_services
Tyriar Jul 19, 2019
f239e10
use enums instead
jerch Jul 19, 2019
e5b28d4
Merge branch 'mouse_services' of github.com:jerch/xterm.js into mouse…
jerch Jul 19, 2019
3e5b075
remove modifier restriction for 1000
jerch Jul 22, 2019
88faf1b
Merge branch 'master' into mouse_services
jerch Jul 23, 2019
776c6df
refactor buttons, wheel with left right
jerch Jul 23, 2019
f68769e
Merge branch 'master' into mouse_services
jerch Jul 24, 2019
4fba080
deactivate wheel left/right, docs
jerch Jul 24, 2019
e32dbc6
Merge branch 'master' into mouse_services
jerch Jul 24, 2019
9d32dc4
Merge branch 'master' into mouse_services
jerch Jul 26, 2019
aa8165a
Merge branch 'master' into mouse_services
jerch Jul 31, 2019
4dec882
fix mouse tests
jerch Jul 31, 2019
51feff3
Merge branch 'mouse_services' of github.com:jerch/xterm.js into mouse…
jerch Jul 31, 2019
565b079
fix osx tests
jerch Aug 1, 2019
b8b3cdb
increase test timeout
jerch Aug 1, 2019
bf2cc23
tests for DECSET 1003
jerch Aug 1, 2019
d28b601
doc multi button tests as not doable
jerch Aug 1, 2019
ae914c1
Merge branch 'master' into mouse_services
jerch Aug 16, 2019
82d1bd8
only report on loglevel debug, explain events
jerch Aug 17, 2019
a215362
drop leftover aux button support, cleanup remnants
jerch Aug 17, 2019
64c06d3
remove any types
jerch Aug 17, 2019
36b3bbd
Merge branch 'master' into mouse_services
jerch Aug 23, 2019
4fd651f
Merge branch 'master' into mouse_services
jerch Aug 23, 2019
6a5223b
Merge branch 'master' into mouse_services
jerch Sep 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/InputHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { CellData } from 'common/buffer/CellData';
import { Attributes } from 'common/buffer/Constants';
import { AttributeData } from 'common/buffer/AttributeData';
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 { DEFAULT_OPTIONS } from 'common/services/OptionsService';
import { clone } from 'common/Clone';
Expand All @@ -33,7 +33,7 @@ describe('InputHandler', () => {
bufferService.buffer.x = 1;
bufferService.buffer.y = 2;
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
inputHandler.saveCursor();
assert.equal(bufferService.buffer.x, 1);
Expand All @@ -52,7 +52,7 @@ describe('InputHandler', () => {
describe('setCursorStyle', () => {
it('should call Terminal.setOption with correct params', () => {
const optionsService = new MockOptionsService();
const inputHandler = new InputHandler(new MockInputHandlingTerminal(), new MockBufferService(80, 30), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), optionsService);
const inputHandler = new InputHandler(new MockInputHandlingTerminal(), new MockBufferService(80, 30), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), optionsService, new MockCoreMouseService());

inputHandler.setCursorStyle(Params.fromArray([0]));
assert.equal(optionsService.options['cursorStyle'], 'block');
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('InputHandler', () => {
it('should toggle Terminal.bracketedPasteMode', () => {
const terminal = new MockInputHandlingTerminal();
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
inputHandler.setModePrivate(Params.fromArray([2004]));
assert.equal(terminal.bracketedPasteMode, true);
Expand All @@ -112,7 +112,7 @@ describe('InputHandler', () => {
it('insertChars', function(): void {
const term = new Terminal();
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
inputHandler.parse(Array(bufferService.cols - 9).join('a'));
Expand Down Expand Up @@ -150,7 +150,7 @@ describe('InputHandler', () => {
it('deleteChars', function(): void {
const term = new Terminal();
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
inputHandler.parse(Array(bufferService.cols - 9).join('a'));
Expand Down Expand Up @@ -191,7 +191,7 @@ describe('InputHandler', () => {
it('eraseInLine', function(): void {
const term = new Terminal();
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
inputHandler.parse(Array(bufferService.cols + 1).join('a'));
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('InputHandler', () => {
it('eraseInDisplay', function(): void {
const term = new Terminal({cols: 80, rows: 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
for (let i = 0; i < bufferService.rows; ++i) inputHandler.parse(Array(bufferService.cols + 1).join('a'));
Expand Down Expand Up @@ -355,7 +355,7 @@ describe('InputHandler', () => {
describe('print', () => {
it('should not cause an infinite loop (regression test)', () => {
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);
container[0] = 0x200B;
inputHandler.print(container, 0, 1);
Expand All @@ -370,7 +370,7 @@ describe('InputHandler', () => {
beforeEach(() => {
term = new Terminal();
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)', () => {
handler.parse('\x1b[?47h\r\n\x1b[31mJUNK\x1b[?47lTEST');
Expand Down
64 changes: 16 additions & 48 deletions src/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import { NULL_CELL_CODE, NULL_CELL_WIDTH, Attributes, FgFlags, BgFlags, Content
import { CellData } from 'common/buffer/CellData';
import { AttributeData } from 'common/buffer/AttributeData';
import { IAttributeData, IDisposable } from 'common/Types';
import { ICoreService, IBufferService, IOptionsService, ILogService, IDirtyRowService } from 'common/services/Services';
import { ISelectionService } from 'browser/services/Services';
import { ICoreService, IBufferService, IOptionsService, ILogService, IDirtyRowService, ICoreMouseService } from 'common/services/Services';
import { OscHandler } from 'common/parser/OscParser';
import { DcsHandler } from 'common/parser/DcsParser';

Expand Down Expand Up @@ -124,8 +123,6 @@ export class InputHandler extends Disposable implements IInputHandler {
private _utf8Decoder: Utf8ToUtf32 = new Utf8ToUtf32();
private _workCell: CellData = new CellData();

private _selectionService: ISelectionService | undefined;

private _onCursorMove = new EventEmitter<void>();
public get onCursorMove(): IEvent<void> { return this._onCursorMove.event; }
private _onLineFeed = new EventEmitter<void>();
Expand All @@ -140,6 +137,7 @@ export class InputHandler extends Disposable implements IInputHandler {
private readonly _dirtyRowService: IDirtyRowService,
private readonly _logService: ILogService,
private readonly _optionsService: IOptionsService,
private readonly _coreMouseService: ICoreMouseService,
private readonly _parser: IEscapeSequenceParser = new EscapeSequenceParser())
Tyriar marked this conversation as resolved.
Show resolved Hide resolved
{
super();
Expand Down Expand Up @@ -326,11 +324,6 @@ export class InputHandler extends Disposable implements IInputHandler {
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 {
let buffer = this._bufferService.buffer;
const cursorStartX = buffer.x;
Expand Down Expand Up @@ -1322,51 +1315,35 @@ export class InputHandler extends Disposable implements IInputHandler {
break;
case 9: // X10 Mouse
// no release, no motion, no wheel, no modifiers.
this._coreMouseService.activeProtocol = 'X10';
break;
case 1000: // vt200 mouse
// no motion.
// no modifiers, except control on the wheel.
this._coreMouseService.activeProtocol = 'VT200';
break;
case 1002: // button event mouse
this._coreMouseService.activeProtocol = 'DRAG';
break;
case 1003: // any event mouse
// any event - sends motion events,
// even if there is no button held down.

// 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.');
this._coreMouseService.activeProtocol = 'ANY';
break;
case 1004: // send focusin/focusout events
// focusin: ^[[I
// focusout: ^[[O
this._terminal.sendFocus = true;
break;
case 1005: // utf8 ext mode mouse
this._terminal.utfMouse = true;
// for wide terminals
// simply encodes large values as utf8 characters
this._coreMouseService.activeEncoding = 'UTF8';
break;
case 1006: // sgr ext mode mouse
this._terminal.sgrMouse = true;
// for wide terminals
// does not add 32 to fields
// press: ^[[<b;x;yM
// release: ^[[<b;x;ym
this._coreMouseService.activeEncoding = 'SGR';
break;
case 1015: // urxvt ext mode mouse
this._terminal.urxvtMouse = true;
// for wide terminals
// numbers for fields
// press: ^[[b;x;yM
// motion: ^[[b;x;yT
this._coreMouseService.activeEncoding = 'URXVT';
break;
case 25: // show cursor
this._terminal.cursorHidden = false;
Expand Down Expand Up @@ -1525,28 +1502,19 @@ export class InputHandler extends Disposable implements IInputHandler {
case 1000: // vt200 mouse
case 1002: // button event mouse
case 1003: // any event mouse
this._terminal.x10Mouse = false;
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();
}
this._coreMouseService.activeProtocol = 'NONE';
break;
case 1004: // send focusin/focusout events
this._terminal.sendFocus = false;
break;
case 1005: // utf8 ext mode mouse
this._terminal.utfMouse = false;
this._coreMouseService.activeEncoding = 'DEFAULT';
jerch marked this conversation as resolved.
Show resolved Hide resolved
break;
case 1006: // sgr ext mode mouse
this._terminal.sgrMouse = false;
this._coreMouseService.activeEncoding = 'DEFAULT';
break;
case 1015: // urxvt ext mode mouse
this._terminal.urxvtMouse = false;
this._coreMouseService.activeEncoding = 'DEFAULT';
break;
case 25: // hide cursor
this._terminal.cursorHidden = true;
Expand Down