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

Fix #3014 - Add onBell event listener to allow embeders to hook into it #3290

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/browser/Terminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ describe('Terminal', () => {
});
term.write('\x1b]2;title\x07');
});
it('should fire the onBell event', (done) => {
term.onBell(e => {
done();
});
term.write('\x07');
});
});

describe('attachCustomKeyEventHandler', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/browser/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export class Terminal extends CoreTerminal implements ITerminal {
public get onSelectionChange(): IEvent<void> { return this._onSelectionChange.event; }
private _onTitleChange = new EventEmitter<string>();
public get onTitleChange(): IEvent<string> { return this._onTitleChange.event; }
private _onBell = new EventEmitter<void>();
public get onBell (): IEvent<void> { return this._onBell.event; }

private _onFocus = new EventEmitter<void>();
public get onFocus(): IEvent<void> { return this._onFocus.event; }
Expand Down Expand Up @@ -1152,6 +1154,8 @@ export class Terminal extends CoreTerminal implements ITerminal {
this._soundService!.playBellSound();
}

this._onBell.fire();

// if (this._visualBell()) {
// this.element.classList.add('visual-bell-active');
// clearTimeout(this._visualBellTimer);
Expand Down
1 change: 1 addition & 0 deletions src/browser/TestUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class MockTerminal implements ITerminal {
public onData!: IEvent<string>;
public onBinary!: IEvent<string>;
public onTitleChange!: IEvent<string>;
public onBell!: IEvent<void>;
public onScroll!: IEvent<number>;
public onKey!: IEvent<{ key: string, domEvent: KeyboardEvent }>;
public onRender!: IEvent<{ start: number, end: number }>;
Expand Down
1 change: 1 addition & 0 deletions src/browser/Types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface IPublicTerminal extends IDisposable {
onRender: IEvent<{ start: number, end: number }>;
onResize: IEvent<{ cols: number, rows: number }>;
onTitleChange: IEvent<string>;
onBell: IEvent<void>;
blur(): void;
focus(): void;
resize(columns: number, rows: number): void;
Expand Down
1 change: 1 addition & 0 deletions src/browser/public/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class Terminal implements ITerminalApi {
public get onData(): IEvent<string> { return this._core.onData; }
public get onBinary(): IEvent<string> { return this._core.onBinary; }
public get onTitleChange(): IEvent<string> { return this._core.onTitleChange; }
public get onBell(): IEvent<void> { return this._core.onBell; }
public get onScroll(): IEvent<number> { return this._core.onScroll; }
public get onKey(): IEvent<{ key: string, domEvent: KeyboardEvent }> { return this._core.onKey; }
public get onRender(): IEvent<{ start: number, end: number }> { return this._core.onRender; }
Expand Down
10 changes: 10 additions & 0 deletions test/api/Terminal.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,16 @@ describe('API Integration Tests', function(): void {
await page.evaluate(`window.term.write('\\x1b]2;foo\\x9c')`);
await pollFor(page, `window.calls`, ['foo']);
});
it('onBell', async () => {
await openTerminal(page);
await page.evaluate(`
window.calls = [];
window.term.onBell(e => window.calls.push(e));
`);
await pollFor(page, `window.calls`, []);
await page.evaluate(`window.term.write('\\a')`);
await pollFor(page, `window.calls`, ['foo']);
});
});

describe('buffer', () => {
Expand Down
6 changes: 6 additions & 0 deletions typings/xterm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,12 @@ declare module 'xterm' {
* @returns an `IDisposable` to stop listening.
*/
onTitleChange: IEvent<string>;

/**
* Adds an event listener for when the bell sound.
* @returns an `IDisposable` to stop listening.
*/
onBell: IEvent<void>;

/**
* Unfocus the terminal.
Expand Down