- Add onBell event listener to allow embeders to hook into it
This commit is contained in:
Bruno Ribeiro
2021-04-03 16:34:00 +01:00
parent 0421f6ebcf
commit 7b7b7a36db
8 changed files with 30 additions and 0 deletions
+6
View File
@@ -131,6 +131,12 @@ describe('Terminal', () => {
}); });
term.write('\x1b]2;title\x07'); term.write('\x1b]2;title\x07');
}); });
it('should fire the onBell event', (done) => {
term.onBell(e => {
done();
});
term.write('\a');
});
}); });
describe('attachCustomKeyEventHandler', () => { describe('attachCustomKeyEventHandler', () => {
+4
View File
@@ -111,6 +111,8 @@ export class Terminal extends CoreTerminal implements ITerminal {
public get onSelectionChange(): IEvent<void> { return this._onSelectionChange.event; } public get onSelectionChange(): IEvent<void> { return this._onSelectionChange.event; }
private _onTitleChange = new EventEmitter<string>(); private _onTitleChange = new EventEmitter<string>();
public get onTitleChange(): IEvent<string> { return this._onTitleChange.event; } 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>(); private _onFocus = new EventEmitter<void>();
public get onFocus(): IEvent<void> { return this._onFocus.event; } public get onFocus(): IEvent<void> { return this._onFocus.event; }
@@ -1141,6 +1143,8 @@ export class Terminal extends CoreTerminal implements ITerminal {
this._soundService!.playBellSound(); this._soundService!.playBellSound();
} }
this._onBell.fire();
// if (this._visualBell()) { // if (this._visualBell()) {
// this.element.classList.add('visual-bell-active'); // this.element.classList.add('visual-bell-active');
// clearTimeout(this._visualBellTimer); // clearTimeout(this._visualBellTimer);
+1
View File
@@ -37,6 +37,7 @@ export class MockTerminal implements ITerminal {
public onData!: IEvent<string>; public onData!: IEvent<string>;
public onBinary!: IEvent<string>; public onBinary!: IEvent<string>;
public onTitleChange!: IEvent<string>; public onTitleChange!: IEvent<string>;
public onBell!: IEvent<void>;
public onScroll!: IEvent<number>; public onScroll!: IEvent<number>;
public onKey!: IEvent<{ key: string, domEvent: KeyboardEvent }>; public onKey!: IEvent<{ key: string, domEvent: KeyboardEvent }>;
public onRender!: IEvent<{ start: number, end: number }>; public onRender!: IEvent<{ start: number, end: number }>;
+1
View File
@@ -47,6 +47,7 @@ export interface IPublicTerminal extends IDisposable {
onRender: IEvent<{ start: number, end: number }>; onRender: IEvent<{ start: number, end: number }>;
onResize: IEvent<{ cols: number, rows: number }>; onResize: IEvent<{ cols: number, rows: number }>;
onTitleChange: IEvent<string>; onTitleChange: IEvent<string>;
onBell: IEvent<void>;
blur(): void; blur(): void;
focus(): void; focus(): void;
resize(columns: number, rows: number): void; resize(columns: number, rows: number): void;
+1
View File
@@ -38,6 +38,7 @@ export class Terminal implements ITerminalApi {
public get onData(): IEvent<string> { return this._core.onData; } public get onData(): IEvent<string> { return this._core.onData; }
public get onBinary(): IEvent<string> { return this._core.onBinary; } public get onBinary(): IEvent<string> { return this._core.onBinary; }
public get onTitleChange(): IEvent<string> { return this._core.onTitleChange; } 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 onScroll(): IEvent<number> { return this._core.onScroll; }
public get onKey(): IEvent<{ key: string, domEvent: KeyboardEvent }> { return this._core.onKey; } public get onKey(): IEvent<{ key: string, domEvent: KeyboardEvent }> { return this._core.onKey; }
public get onRender(): IEvent<{ start: number, end: number }> { return this._core.onRender; } public get onRender(): IEvent<{ start: number, end: number }> { return this._core.onRender; }
+1
View File
@@ -357,6 +357,7 @@ export interface IAnsiColorChangeEvent {
*/ */
export interface IInputHandler { export interface IInputHandler {
onTitleChange: IEvent<string>; onTitleChange: IEvent<string>;
onRequestBell: IEvent<void>;
parse(data: string | Uint8Array, promiseResult?: boolean): void | Promise<boolean>; parse(data: string | Uint8Array, promiseResult?: boolean): void | Promise<boolean>;
print(data: Uint32Array, start: number, end: number): void; print(data: Uint32Array, start: number, end: number): void;
+10
View File
@@ -410,6 +410,16 @@ describe('API Integration Tests', function(): void {
await page.evaluate(`window.term.write('\\x1b]2;foo\\x9c')`); await page.evaluate(`window.term.write('\\x1b]2;foo\\x9c')`);
await pollFor(page, `window.calls`, ['foo']); 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', () => { describe('buffer', () => {
+6
View File
@@ -709,6 +709,12 @@ declare module 'xterm' {
*/ */
onTitleChange: IEvent<string>; onTitleChange: IEvent<string>;
/**
* Adds an event listener for when the bell sound.
* @returns an `IDisposable` to stop listening.
*/
onBell: IEvent<void>;
/** /**
* Unfocus the terminal. * Unfocus the terminal.
*/ */