mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Convert linefeed to EventEmitter2
This commit is contained in:
@@ -77,7 +77,7 @@ export class AccessibilityManager extends Disposable {
|
||||
this.register(this._terminal.addDisposableListener('scroll', data => this._refreshRows()));
|
||||
// Line feed is an issue as the prompt won't be read out after a command is run
|
||||
this.register(this._terminal.addDisposableListener('a11y.char', (char) => this._onChar(char)));
|
||||
this.register(this._terminal.addDisposableListener('linefeed', () => this._onChar('\n')));
|
||||
this.register(this._terminal.onLineFeed(() => this._onChar('\n')));
|
||||
this.register(this._terminal.addDisposableListener('a11y.tab', spaceCount => this._onTab(spaceCount)));
|
||||
this.register(this._terminal.onKey(e => this._onKey(e.key)));
|
||||
this.register(this._terminal.addDisposableListener('blur', () => this._clearLiveRegion()));
|
||||
|
||||
+4
-6
@@ -109,6 +109,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
|
||||
private _onCursorMove = new EventEmitter2<void>();
|
||||
public get onCursorMove(): IEvent<void> { return this._onCursorMove.event; }
|
||||
private _onLineFeed = new EventEmitter2<void>();
|
||||
public get onLineFeed(): IEvent<void> { return this._onLineFeed.event; }
|
||||
|
||||
constructor(
|
||||
protected _terminal: IInputHandlingTerminal,
|
||||
@@ -458,12 +460,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
if (buffer.x >= this._terminal.cols) {
|
||||
buffer.x--;
|
||||
}
|
||||
/**
|
||||
* This event is emitted whenever the terminal outputs a LF or NL.
|
||||
*
|
||||
* @event linefeed
|
||||
*/
|
||||
this._terminal.emit('linefeed');
|
||||
|
||||
this._onLineFeed.fire();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+11
-1
@@ -17,7 +17,7 @@ class TestTerminal extends Terminal {
|
||||
public keyPress(ev: any): boolean { return this._keyPress(ev); }
|
||||
}
|
||||
|
||||
describe('term.js addons', () => {
|
||||
describe('xterm.js', () => {
|
||||
let term: TestTerminal;
|
||||
const termOptions = {
|
||||
cols: INIT_COLS,
|
||||
@@ -95,6 +95,16 @@ describe('term.js addons', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('linefeed', () => {
|
||||
it('should emit a linefeed event', (done) => {
|
||||
term.on('linefeed', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
term.write('\n');
|
||||
});
|
||||
});
|
||||
|
||||
describe(`keypress (including 'key' event)`, () => {
|
||||
it('should receive a string and event object', (done) => {
|
||||
let steps = 0;
|
||||
|
||||
+3
-1
@@ -261,7 +261,6 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
||||
this._setup();
|
||||
|
||||
// TODO: Replace EventEmitter with EventEmitter2 internally
|
||||
this.on('linefeed', () => this._onLineFeed.fire());
|
||||
this.on('selection', () => this._onSelectionChange.fire());
|
||||
this.on('data', e => this._onInput.fire(e));
|
||||
this.on('scroll', e => this._onScroll.fire(e));
|
||||
@@ -271,6 +270,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
||||
// Fire old style events from new emitters
|
||||
this.onCursorMove(() => this.emit('cursormove'));
|
||||
this.onKey(e => this.emit('key', e.key, e.domEvent));
|
||||
this.onLineFeed(() => this.emit('linefeed'));
|
||||
this.onResize(e => this.emit('resize', e));
|
||||
this.onTitleChange(e => this.emit('title', e));
|
||||
}
|
||||
@@ -349,8 +349,10 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
||||
// this._writeStopped = false;
|
||||
this._userScrolling = false;
|
||||
|
||||
// Register input handler and refire/handle events
|
||||
this._inputHandler = new InputHandler(this);
|
||||
this._inputHandler.onCursorMove(() => this._onCursorMove.fire());
|
||||
this._inputHandler.onLineFeed(() => this._onLineFeed.fire());
|
||||
this.register(this._inputHandler);
|
||||
|
||||
// Reuse renderer if the Terminal is being recreated via a reset call.
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ export function applyWindowsMode(terminal: ITerminal): IDisposable {
|
||||
// space. This is certainly not without its problems, but generally on
|
||||
// Windows when text reaches the end of the terminal it's likely going to be
|
||||
// wrapped.
|
||||
return terminal.addDisposableListener('linefeed', () => {
|
||||
return terminal.onLineFeed(() => {
|
||||
const line = terminal.buffer.lines.get(terminal.buffer.ybase + terminal.buffer.y - 1);
|
||||
const lastChar = line.get(terminal.cols - 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user