Skip to content

Commit eedc314

Browse files
authored
Merge pull request #3290 from nikonso/feat/3014-add-onBell-event-listener
Fix #3014 - Add onBell event listener to allow embeders to hook into it
2 parents c7978f7 + 2556137 commit eedc314

File tree

7 files changed

+29
-0
lines changed

7 files changed

+29
-0
lines changed

src/browser/Terminal.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ describe('Terminal', () => {
131131
});
132132
term.write('\x1b]2;title\x07');
133133
});
134+
it('should fire the onBell event', (done) => {
135+
term.onBell(e => {
136+
done();
137+
});
138+
term.write('\x07');
139+
});
134140
});
135141

136142
describe('attachCustomKeyEventHandler', () => {

src/browser/Terminal.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ export class Terminal extends CoreTerminal implements ITerminal {
113113
public get onSelectionChange(): IEvent<void> { return this._onSelectionChange.event; }
114114
private _onTitleChange = new EventEmitter<string>();
115115
public get onTitleChange(): IEvent<string> { return this._onTitleChange.event; }
116+
private _onBell = new EventEmitter<void>();
117+
public get onBell (): IEvent<void> { return this._onBell.event; }
116118

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

1157+
this._onBell.fire();
1158+
11551159
// if (this._visualBell()) {
11561160
// this.element.classList.add('visual-bell-active');
11571161
// clearTimeout(this._visualBellTimer);

src/browser/TestUtils.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class MockTerminal implements ITerminal {
3737
public onData!: IEvent<string>;
3838
public onBinary!: IEvent<string>;
3939
public onTitleChange!: IEvent<string>;
40+
public onBell!: IEvent<void>;
4041
public onScroll!: IEvent<number>;
4142
public onKey!: IEvent<{ key: string, domEvent: KeyboardEvent }>;
4243
public onRender!: IEvent<{ start: number, end: number }>;

src/browser/Types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface IPublicTerminal extends IDisposable {
4747
onRender: IEvent<{ start: number, end: number }>;
4848
onResize: IEvent<{ cols: number, rows: number }>;
4949
onTitleChange: IEvent<string>;
50+
onBell: IEvent<void>;
5051
blur(): void;
5152
focus(): void;
5253
resize(columns: number, rows: number): void;

src/browser/public/Terminal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class Terminal implements ITerminalApi {
3838
public get onData(): IEvent<string> { return this._core.onData; }
3939
public get onBinary(): IEvent<string> { return this._core.onBinary; }
4040
public get onTitleChange(): IEvent<string> { return this._core.onTitleChange; }
41+
public get onBell(): IEvent<void> { return this._core.onBell; }
4142
public get onScroll(): IEvent<number> { return this._core.onScroll; }
4243
public get onKey(): IEvent<{ key: string, domEvent: KeyboardEvent }> { return this._core.onKey; }
4344
public get onRender(): IEvent<{ start: number, end: number }> { return this._core.onRender; }

test/api/Terminal.api.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,16 @@ describe('API Integration Tests', function(): void {
410410
await page.evaluate(`window.term.write('\\x1b]2;foo\\x9c')`);
411411
await pollFor(page, `window.calls`, ['foo']);
412412
});
413+
it('onBell', async () => {
414+
await openTerminal(page);
415+
await page.evaluate(`
416+
window.calls = [];
417+
window.term.onBell(() => window.calls.push(true));
418+
`);
419+
await pollFor(page, `window.calls`, []);
420+
await page.evaluate(`window.term.write('\\x07')`);
421+
await pollFor(page, `window.calls`, [true]);
422+
});
413423
});
414424

415425
describe('buffer', () => {

typings/xterm.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,12 @@ declare module 'xterm' {
709709
*/
710710
onTitleChange: IEvent<string>;
711711

712+
/**
713+
* Adds an event listener for when the bell is triggered.
714+
* @returns an `IDisposable` to stop listening.
715+
*/
716+
onBell: IEvent<void>;
717+
712718
/**
713719
* Unfocus the terminal.
714720
*/

0 commit comments

Comments
 (0)