Skip to content

Commit

Permalink
Merge pull request #2109 from Tyriar/2107_cursor_report
Browse files Browse the repository at this point in the history
Fix status reporting
  • Loading branch information
Tyriar committed May 21, 2019
2 parents 739723f + d0a3164 commit 8e460df
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
86 changes: 86 additions & 0 deletions src/InputHandler.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/

import * as puppeteer from 'puppeteer';
import { assert } from 'chai';
import { ITerminalOptions } from './Types';

const APP = 'http://127.0.0.1:3000/test';

let browser: puppeteer.Browser;
let page: puppeteer.Page;
const width = 800;
const height = 600;

describe('InputHandler Integration Tests', () => {
before(async function(): Promise<any> {
this.timeout(10000);
browser = await puppeteer.launch({
headless: process.argv.indexOf('--headless') !== -1,
slowMo: 80,
args: [`--window-size=${width},${height}`]
});
page = (await browser.pages())[0];
await page.setViewport({ width, height });
});

after(() => {
browser.close();
});

beforeEach(async () => {
await page.goto(APP);
});

describe('Device Status Report (DSR)', () => {
it('Status Report - CSI 5 n', async function(): Promise<any> {
this.timeout(10000);
await openTerminal();
await page.evaluate(`
window.term.onData(e => window.result = e);
window.term.write('\\x1b[5n');
`);
assert.equal(await page.evaluate(`window.result`), '\x1b[0n');
});

it('Report Cursor Position (CPR) - CSI 6 n', async function(): Promise<any> {
this.timeout(10000);
await openTerminal();
await page.evaluate(`window.term.write('\\n\\nfoo')`);
assert.deepEqual(await page.evaluate(`
[window.term.buffer.cursorY, window.term.buffer.cursorX]
`), [2, 3]);
await page.evaluate(`
window.term.onData(e => window.result = e);
window.term.write('\\x1b[6n');
`);
assert.equal(await page.evaluate(`window.result`), '\x1b[3;4R');
});

it('Report Cursor Position (DECXCPR) - CSI ? 6 n', async function(): Promise<any> {
this.timeout(10000);
await openTerminal();
await page.evaluate(`window.term.write('\\n\\nfoo')`);
assert.deepEqual(await page.evaluate(`
[window.term.buffer.cursorY, window.term.buffer.cursorX]
`), [2, 3]);
await page.evaluate(`
window.term.onData(e => window.result = e);
window.term.write('\\x1b[?6n');
`);
assert.equal(await page.evaluate(`window.result`), '\x1b[?3;4R');
});
});
});

async function openTerminal(options: ITerminalOptions = {}): Promise<void> {
await page.evaluate(`window.term = new Terminal(${JSON.stringify(options)})`);
await page.evaluate(`window.term.open(document.querySelector('#terminal-container'))`);
if (options.rendererType === 'dom') {
await page.waitForSelector('.xterm-rows');
} else {
await page.waitForSelector('.xterm-text-layer');
}
}
1 change: 1 addition & 0 deletions src/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
this._inputHandler = new InputHandler(this);
this._inputHandler.onCursorMove(() => this._onCursorMove.fire());
this._inputHandler.onLineFeed(() => this._onLineFeed.fire());
this._inputHandler.onData(e => this._onData.fire(e));
this.register(this._inputHandler);

this.selectionManager = this.selectionManager || null;
Expand Down

0 comments on commit 8e460df

Please sign in to comment.