mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
fix tests; fix attach addon
This commit is contained in:
@@ -33,6 +33,7 @@ export class AttachAddon implements ITerminalAddon {
|
||||
|
||||
if (this._bidirectional) {
|
||||
this._disposables.push(terminal.onData(data => this._sendData(data)));
|
||||
this._disposables.push(terminal.onBinary(data => this._sendBinary(data)));
|
||||
}
|
||||
|
||||
this._disposables.push(addSocketListener(this._socket, 'close', () => this.dispose()));
|
||||
@@ -51,6 +52,17 @@ export class AttachAddon implements ITerminalAddon {
|
||||
}
|
||||
this._socket.send(data);
|
||||
}
|
||||
|
||||
private _sendBinary(data: string): void {
|
||||
if (this._socket.readyState !== 1) {
|
||||
return;
|
||||
}
|
||||
const buffer = new Uint8Array(data.length);
|
||||
for (let i = 0; i < data.length; ++i) {
|
||||
buffer[i] = data.charCodeAt(i) & 255;
|
||||
}
|
||||
this._socket.send(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
function addSocketListener<K extends keyof WebSocketEventMap>(socket: WebSocket, type: K, handler: (this: WebSocket, ev: WebSocketEventMap[K]) => any): IDisposable {
|
||||
|
||||
@@ -223,6 +223,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
||||
this._coreService = this._instantiationService.createInstance(CoreService, () => this.scrollToBottom());
|
||||
this._instantiationService.setService(ICoreService, this._coreService);
|
||||
this._coreService.onData(e => this._onData.fire(e));
|
||||
this._coreService.onBinary(e => this._onBinary.fire(e));
|
||||
this._coreMouseService = this._instantiationService.createInstance(CoreMouseService);
|
||||
this._instantiationService.setService(ICoreMouseService, this._coreMouseService);
|
||||
this._dirtyRowService = this._instantiationService.createInstance(DirtyRowService);
|
||||
|
||||
@@ -264,7 +264,7 @@ export class CoreMouseService implements ICoreMouseService {
|
||||
|
||||
// encode report and send
|
||||
const report = this._encodings[this._activeEncoding](e);
|
||||
if (this._activeProtocol === 'DEFAULT') {
|
||||
if (this._activeEncoding === 'DEFAULT') {
|
||||
// always send DEFAULT as binary data
|
||||
if (report) {
|
||||
this._coreService.triggerBinaryEvent(report);
|
||||
|
||||
@@ -220,6 +220,7 @@ describe('Mouse Tracking Tests', () => {
|
||||
await page.evaluate(`
|
||||
window.calls = [];
|
||||
window.term.onData(e => calls.push( Array.from(e).map(el => el.charCodeAt(0)) ));
|
||||
window.term.onBinary(e => calls.push( Array.from(e).map(el => el.charCodeAt(0)) ));
|
||||
window.term.setOption('fontSize', ${fontSize});
|
||||
window.term.resize(${cols}, ${rows});
|
||||
`);
|
||||
@@ -255,12 +256,17 @@ describe('Mouse Tracking Tests', () => {
|
||||
await pollFor(page, () => getReports(encoding), [{col: 51, row: 11, state: {action: 'press', button: 'left', modifier: {control: false, shift: false, meta: false}}}]);
|
||||
|
||||
// test at max rows/cols
|
||||
// bug: we are capped at col 95 currently
|
||||
// fix: allow values up to 223, any bigger should drop to 0
|
||||
await mouseMove(cols - 1, rows - 1);
|
||||
// capped at 223 (1-based)
|
||||
await mouseMove(223 - 1, rows - 1);
|
||||
await mouseDown('left');
|
||||
await mouseUp('left');
|
||||
await pollFor(page, () => getReports(encoding), [{col: 95, row: rows, state: {action: 'press', button: 'left', modifier: {control: false, shift: false, meta: false}}}]);
|
||||
await pollFor(page, () => getReports(encoding), [{col: 223, row: rows, state: {action: 'press', button: 'left', modifier: {control: false, shift: false, meta: false}}}]);
|
||||
|
||||
// higher than 223 should not report at all
|
||||
await mouseMove(257, rows - 1);
|
||||
await mouseDown('left');
|
||||
await mouseUp('left');
|
||||
await pollFor(page, () => getReports(encoding), []);
|
||||
|
||||
// button press/move/release tests
|
||||
// left button
|
||||
@@ -511,14 +517,13 @@ describe('Mouse Tracking Tests', () => {
|
||||
]);
|
||||
|
||||
// test at max rows/cols
|
||||
// bug: we are capped at col 95 currently
|
||||
// fix: allow values up to 223, any bigger should drop to 0
|
||||
await mouseMove(cols - 1, rows - 1);
|
||||
// capped at 223 (1-based)
|
||||
await mouseMove(223 - 1, rows - 1);
|
||||
await mouseDown('left');
|
||||
await mouseUp('left');
|
||||
await pollFor(page, () => getReports(encoding), [
|
||||
{col: 95, row: rows, state: {action: 'press', button: 'left', modifier: {control: false, shift: false, meta: false}}},
|
||||
{col: 95, row: rows, state: {action: 'release', button: '<none>', modifier: {control: false, shift: false, meta: false}}}
|
||||
{col: 223, row: rows, state: {action: 'press', button: 'left', modifier: {control: false, shift: false, meta: false}}},
|
||||
{col: 223, row: rows, state: {action: 'release', button: '<none>', modifier: {control: false, shift: false, meta: false}}}
|
||||
]);
|
||||
|
||||
// button press/move/release tests
|
||||
@@ -821,14 +826,13 @@ describe('Mouse Tracking Tests', () => {
|
||||
]);
|
||||
|
||||
// test at max rows/cols
|
||||
// bug: we are capped at col 95 currently
|
||||
// fix: allow values up to 223, any bigger should drop to 0
|
||||
await mouseMove(cols - 1, rows - 1);
|
||||
// capped at 223 (1-based)
|
||||
await mouseMove(223 - 1, rows - 1);
|
||||
await mouseDown('left');
|
||||
await mouseUp('left');
|
||||
await pollFor(page, () => getReports(encoding), [
|
||||
{col: 95, row: rows, state: {action: 'press', button: 'left', modifier: {control: false, shift: false, meta: false}}},
|
||||
{col: 95, row: rows, state: {action: 'release', button: '<none>', modifier: {control: false, shift: false, meta: false}}}
|
||||
{col: 223, row: rows, state: {action: 'press', button: 'left', modifier: {control: false, shift: false, meta: false}}},
|
||||
{col: 223, row: rows, state: {action: 'release', button: '<none>', modifier: {control: false, shift: false, meta: false}}}
|
||||
]);
|
||||
|
||||
// button press/move/release tests
|
||||
@@ -1142,15 +1146,14 @@ describe('Mouse Tracking Tests', () => {
|
||||
]);
|
||||
|
||||
// test at max rows/cols
|
||||
// bug: we are capped at col 95 currently
|
||||
// fix: allow values up to 223, any bigger should drop to 0
|
||||
await mouseMove(cols - 1, rows - 1);
|
||||
// capped at 223 (1-based)
|
||||
await mouseMove(223 - 1, rows - 1);
|
||||
await mouseDown('left');
|
||||
await mouseUp('left');
|
||||
await pollFor(page, () => getReports(encoding), [
|
||||
{col: 95, row: rows, state: {action: 'move', button: '<none>', modifier: {control: false, shift: false, meta: false}}},
|
||||
{col: 95, row: rows, state: {action: 'press', button: 'left', modifier: {control: false, shift: false, meta: false}}},
|
||||
{col: 95, row: rows, state: {action: 'release', button: '<none>', modifier: {control: false, shift: false, meta: false}}}
|
||||
{col: 223, row: rows, state: {action: 'move', button: '<none>', modifier: {control: false, shift: false, meta: false}}},
|
||||
{col: 223, row: rows, state: {action: 'press', button: 'left', modifier: {control: false, shift: false, meta: false}}},
|
||||
{col: 223, row: rows, state: {action: 'release', button: '<none>', modifier: {control: false, shift: false, meta: false}}}
|
||||
]);
|
||||
|
||||
// button press/move/release tests
|
||||
|
||||
Reference in New Issue
Block a user