From 09ae3a9b443133e043091525dd6d35e00b18f4c6 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 27 Jul 2022 05:55:00 -0700 Subject: [PATCH 1/2] Remove sound service and simplify bell --- src/browser/Terminal.ts | 28 +------------ src/browser/services/Services.ts | 8 ---- src/browser/services/SoundService.ts | 63 ---------------------------- 3 files changed, 2 insertions(+), 97 deletions(-) delete mode 100644 src/browser/services/SoundService.ts diff --git a/src/browser/Terminal.ts b/src/browser/Terminal.ts index bd82325d..4c65b1b6 100644 --- a/src/browser/Terminal.ts +++ b/src/browser/Terminal.ts @@ -34,7 +34,6 @@ import { SelectionService } from 'browser/services/SelectionService'; import * as Browser from 'common/Platform'; import { addDisposableDomListener } from 'browser/Lifecycle'; import * as Strings from 'browser/LocalizableStrings'; -import { SoundService } from 'browser/services/SoundService'; import { MouseZoneManager } from 'browser/MouseZoneManager'; import { AccessibilityManager } from './AccessibilityManager'; import { ITheme, IMarker, IDisposable, ISelectionPosition, ILinkProvider, IDecorationOptions, IDecoration } from 'xterm'; @@ -45,7 +44,7 @@ import { EventEmitter, IEvent, forwardEvent } from 'common/EventEmitter'; import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine'; import { ColorManager } from 'browser/ColorManager'; import { RenderService } from 'browser/services/RenderService'; -import { ICharSizeService, IRenderService, IMouseService, ISelectionService, ISoundService, ICoreBrowserService, ICharacterJoinerService } from 'browser/services/Services'; +import { ICharSizeService, IRenderService, IMouseService, ISelectionService, ICoreBrowserService, ICharacterJoinerService } from 'browser/services/Services'; import { CharSizeService } from 'browser/services/CharSizeService'; import { IBuffer } from 'common/buffer/Types'; import { MouseService } from 'browser/services/MouseService'; @@ -89,7 +88,6 @@ export class Terminal extends CoreTerminal implements ITerminal { private _renderService: IRenderService | undefined; private _characterJoinerService: ICharacterJoinerService | undefined; private _selectionService: ISelectionService | undefined; - private _soundService: ISoundService | undefined; /** * Records whether the keydown event has already been handled and triggered a data event, if so @@ -174,7 +172,7 @@ export class Terminal extends CoreTerminal implements ITerminal { this._instantiationService.setService(IDecorationService, this._decorationService); // Setup InputHandler listeners - this.register(this._inputHandler.onRequestBell(() => this.bell())); + this.register(this._inputHandler.onRequestBell(() => this._onBell.fire())); this.register(this._inputHandler.onRequestRefreshRows((start, end) => this.refresh(start, end))); this.register(this._inputHandler.onRequestSendFocus(() => this._reportFocus())); this.register(this._inputHandler.onRequestReset(() => this.reset())); @@ -537,8 +535,6 @@ export class Terminal extends CoreTerminal implements ITerminal { // Performance: Add viewport and helper elements from the fragment this.element.appendChild(fragment); - this._soundService = this._instantiationService.createInstance(SoundService); - this._instantiationService.setService(ISoundService, this._soundService); this._mouseService = this._instantiationService.createInstance(MouseService); this._instantiationService.setService(IMouseService, this._mouseService); @@ -1285,26 +1281,6 @@ export class Terminal extends CoreTerminal implements ITerminal { return false; } - /** - * Ring the bell. - * Note: We could do sweet things with webaudio here - */ - public bell(): void { - if (this._soundBell()) { - this._soundService?.playBellSound(); - } - - this._onBell.fire(); - - // if (this._visualBell()) { - // this.element.classList.add('visual-bell-active'); - // clearTimeout(this._visualBellTimer); - // this._visualBellTimer = window.setTimeout(() => { - // this.element.classList.remove('visual-bell-active'); - // }, 200); - // } - } - /** * Resizes the terminal. * diff --git a/src/browser/services/Services.ts b/src/browser/services/Services.ts index e1fb5dbd..9f226338 100644 --- a/src/browser/services/Services.ts +++ b/src/browser/services/Services.ts @@ -105,14 +105,6 @@ export interface ISelectionService { isCellInSelection(x: number, y: number): boolean; } -export const ISoundService = createDecorator('SoundService'); -export interface ISoundService { - serviceBrand: undefined; - - playBellSound(): void; -} - - export const ICharacterJoinerService = createDecorator('CharacterJoinerService'); export interface ICharacterJoinerService { serviceBrand: undefined; diff --git a/src/browser/services/SoundService.ts b/src/browser/services/SoundService.ts deleted file mode 100644 index a3b6800d..00000000 --- a/src/browser/services/SoundService.ts +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (c) 2018 The xterm.js authors. All rights reserved. - * @license MIT - */ - -import { IOptionsService } from 'common/services/Services'; -import { ISoundService } from 'browser/services/Services'; - -export class SoundService implements ISoundService { - public serviceBrand: undefined; - - private static _audioContext: AudioContext; - - public static get audioContext(): AudioContext | null { - if (!SoundService._audioContext) { - const audioContextCtor: typeof AudioContext = (window as any).AudioContext || (window as any).webkitAudioContext; - if (!audioContextCtor) { - console.warn('Web Audio API is not supported by this browser. Consider upgrading to the latest version'); - return null; - } - SoundService._audioContext = new audioContextCtor(); - } - return SoundService._audioContext; - } - - constructor( - @IOptionsService private _optionsService: IOptionsService - ) { - } - - public playBellSound(): void { - const ctx = SoundService.audioContext; - if (!ctx) { - return; - } - const bellAudioSource = ctx.createBufferSource(); - ctx.decodeAudioData(this._base64ToArrayBuffer(this._removeMimeType(this._optionsService.rawOptions.bellSound)), (buffer) => { - bellAudioSource.buffer = buffer; - bellAudioSource.connect(ctx.destination); - bellAudioSource.start(0); - }); - } - - private _base64ToArrayBuffer(base64: string): ArrayBuffer { - const binaryString = window.atob(base64); - const len = binaryString.length; - const bytes = new Uint8Array(len); - - for (let i = 0; i < len; i++) { - bytes[i] = binaryString.charCodeAt(i); - } - - return bytes.buffer; - } - - private _removeMimeType(dataURI: string): string { - // Split the input to get the mime-type and the data itself - const splitUri = dataURI.split(','); - - // Return only the data - return splitUri[1]; - } -} From 66d6ed65ef2db9ee23df7bcbf17cb8327e02ff81 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 27 Jul 2022 05:58:26 -0700 Subject: [PATCH 2/2] Remove all bellSound/bellStyle/etc. references Fixes #3316 --- demo/client.ts | 2 -- src/browser/Terminal.ts | 12 ------------ src/browser/public/Terminal.ts | 9 ++++----- src/common/services/OptionsService.ts | 9 --------- src/common/services/Services.ts | 2 -- src/headless/public/Terminal.ts | 9 ++++----- typings/xterm-headless.d.ts | 24 ++++-------------------- typings/xterm.d.ts | 25 ++++--------------------- 8 files changed, 16 insertions(+), 76 deletions(-) diff --git a/demo/client.ts b/demo/client.ts index cfab9aa8..66ba7bd7 100644 --- a/demo/client.ts +++ b/demo/client.ts @@ -324,8 +324,6 @@ function initOptions(term: TerminalType): void { 'windowOptions' ]; const stringOptions = { - bellSound: null, - bellStyle: ['none', 'sound'], cursorStyle: ['block', 'underline', 'bar'], fastScrollModifier: ['alt', 'ctrl', 'shift', undefined], fontFamily: null, diff --git a/src/browser/Terminal.ts b/src/browser/Terminal.ts index 4c65b1b6..76d5461f 100644 --- a/src/browser/Terminal.ts +++ b/src/browser/Terminal.ts @@ -1398,18 +1398,6 @@ export class Terminal extends CoreTerminal implements ITerminal { ev.stopPropagation(); return false; } - - private _visualBell(): boolean { - return false; - // return this.options.bellStyle === 'visual' || - // this.options.bellStyle === 'both'; - } - - private _soundBell(): boolean { - return this.options.bellStyle === 'sound'; - // return this.options.bellStyle === 'sound' || - // this.options.bellStyle === 'both'; - } } /** diff --git a/src/browser/public/Terminal.ts b/src/browser/public/Terminal.ts index 187bd3b5..4b7f2725 100644 --- a/src/browser/public/Terminal.ts +++ b/src/browser/public/Terminal.ts @@ -241,20 +241,19 @@ export class Terminal implements ITerminalApi { public paste(data: string): void { this._core.paste(data); } - public getOption(key: 'bellSound' | 'bellStyle' | 'cursorStyle' | 'fontFamily' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string; - public getOption(key: 'allowTransparency' | 'altClickMovesCursor' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'visualBell'): boolean; + public getOption(key: 'cursorStyle' | 'fontFamily' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string; + public getOption(key: 'allowTransparency' | 'altClickMovesCursor' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord'): boolean; public getOption(key: 'cols' | 'fontSize' | 'letterSpacing' | 'lineHeight' | 'rows' | 'tabStopWidth' | 'scrollback'): number; public getOption(key: 'fontWeight' | 'fontWeightBold'): FontWeight; public getOption(key: string): any; public getOption(key: any): any { return this._core.optionsService.getOption(key); } - public setOption(key: 'bellSound' | 'fontFamily' | 'termName' | 'wordSeparator', value: string): void; + public setOption(key: 'fontFamily' | 'termName' | 'wordSeparator', value: string): void; public setOption(key: 'fontWeight' | 'fontWeightBold', value: 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | number): void; public setOption(key: 'logLevel', value: 'debug' | 'info' | 'warn' | 'error' | 'off'): void; - public setOption(key: 'bellStyle', value: 'none' | 'visual' | 'sound' | 'both'): void; public setOption(key: 'cursorStyle', value: 'block' | 'underline' | 'bar'): void; - public setOption(key: 'allowTransparency' | 'altClickMovesCursor' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'visualBell', value: boolean): void; + public setOption(key: 'allowTransparency' | 'altClickMovesCursor' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord', value: boolean): void; public setOption(key: 'fontSize' | 'letterSpacing' | 'lineHeight' | 'tabStopWidth' | 'scrollback', value: number): void; public setOption(key: 'theme', value: ITheme): void; public setOption(key: 'cols' | 'rows', value: number): void; diff --git a/src/common/services/OptionsService.ts b/src/common/services/OptionsService.ts index 4f9600a4..a8c4ff75 100644 --- a/src/common/services/OptionsService.ts +++ b/src/common/services/OptionsService.ts @@ -8,12 +8,6 @@ import { EventEmitter, IEvent } from 'common/EventEmitter'; import { isMac } from 'common/Platform'; import { CursorStyle } from 'common/Types'; -// Source: https://freesound.org/people/altemark/sounds/45759/ -// This sound is released under the Creative Commons Attribution 3.0 Unported -// (CC BY 3.0) license. It was created by 'altemark'. No modifications have been -// made, apart from the conversion to base64. -export const DEFAULT_BELL_SOUND = 'data:audio/mp3;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjMyLjEwNAAAAAAAAAAAAAAA//tQxAADB8AhSmxhIIEVCSiJrDCQBTcu3UrAIwUdkRgQbFAZC1CQEwTJ9mjRvBA4UOLD8nKVOWfh+UlK3z/177OXrfOdKl7pyn3Xf//WreyTRUoAWgBgkOAGbZHBgG1OF6zM82DWbZaUmMBptgQhGjsyYqc9ae9XFz280948NMBWInljyzsNRFLPWdnZGWrddDsjK1unuSrVN9jJsK8KuQtQCtMBjCEtImISdNKJOopIpBFpNSMbIHCSRpRR5iakjTiyzLhchUUBwCgyKiweBv/7UsQbg8isVNoMPMjAAAA0gAAABEVFGmgqK////9bP/6XCykxBTUUzLjEwMKqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq'; - export const DEFAULT_OPTIONS: Readonly = { cols: 80, rows: 24, @@ -21,8 +15,6 @@ export const DEFAULT_OPTIONS: Readonly = { cursorStyle: 'block', cursorWidth: 1, customGlyphs: true, - bellSound: DEFAULT_BELL_SOUND, - bellStyle: 'none', drawBoldTextInBrightColors: true, fastScrollModifier: 'alt', fastScrollSensitivity: 5, @@ -132,7 +124,6 @@ export class OptionsService implements IOptionsService { throw new Error(`"${value}" is not a valid value for ${key}`); } break; - case 'bellStyle': case 'cursorStyle': case 'rendererType': case 'wordSeparator': diff --git a/src/common/services/Services.ts b/src/common/services/Services.ts index fab8435a..c2fdd8e5 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -212,8 +212,6 @@ export interface ITerminalOptions { allowProposedApi: boolean; allowTransparency: boolean; altClickMovesCursor: boolean; - bellSound: string; - bellStyle: 'none' | 'sound' /* | 'visual' | 'both' */; cols: number; convertEol: boolean; cursorBlink: boolean; diff --git a/src/headless/public/Terminal.ts b/src/headless/public/Terminal.ts index 5a35fae2..01c0eab0 100644 --- a/src/headless/public/Terminal.ts +++ b/src/headless/public/Terminal.ts @@ -179,19 +179,18 @@ export class Terminal implements ITerminalApi { this._core.write(data); this._core.write('\r\n', callback); } - public getOption(key: 'bellSound' | 'bellStyle' | 'cursorStyle' | 'fontFamily' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string; - public getOption(key: 'allowTransparency' | 'altClickMovesCursor' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'visualBell'): boolean; + public getOption(key: 'cursorStyle' | 'fontFamily' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string; + public getOption(key: 'allowTransparency' | 'altClickMovesCursor' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord'): boolean; public getOption(key: 'cols' | 'fontSize' | 'letterSpacing' | 'lineHeight' | 'rows' | 'tabStopWidth' | 'scrollback'): number; public getOption(key: string): any; public getOption(key: any): any { return this._core.optionsService.getOption(key); } - public setOption(key: 'bellSound' | 'fontFamily' | 'termName' | 'wordSeparator', value: string): void; + public setOption(key: 'fontFamily' | 'termName' | 'wordSeparator', value: string): void; public setOption(key: 'fontWeight' | 'fontWeightBold', value: 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | number): void; public setOption(key: 'logLevel', value: 'debug' | 'info' | 'warn' | 'error' | 'off'): void; - public setOption(key: 'bellStyle', value: 'none' | 'visual' | 'sound' | 'both'): void; public setOption(key: 'cursorStyle', value: 'block' | 'underline' | 'bar'): void; - public setOption(key: 'allowTransparency' | 'altClickMovesCursor' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'visualBell', value: boolean): void; + public setOption(key: 'allowTransparency' | 'altClickMovesCursor' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord', value: boolean): void; public setOption(key: 'fontSize' | 'letterSpacing' | 'lineHeight' | 'tabStopWidth' | 'scrollback', value: number): void; public setOption(key: 'cols' | 'rows', value: number): void; public setOption(key: string, value: any): void; diff --git a/typings/xterm-headless.d.ts b/typings/xterm-headless.d.ts index 26a01e4c..c840ed09 100644 --- a/typings/xterm-headless.d.ts +++ b/typings/xterm-headless.d.ts @@ -38,16 +38,6 @@ declare module 'xterm-headless' { */ altClickMovesCursor?: boolean; - /** - * A data uri of the sound to use for the bell when `bellStyle = 'sound'`. - */ - bellSound?: string; - - /** - * The type of the bell notification the terminal will use. - */ - bellStyle?: 'none' | 'sound'; - /** * When enabled the cursor will be set to the beginning of the next line * with every new line. This is equivalent to sending '\r\n' for each '\n'. @@ -723,12 +713,12 @@ declare module 'xterm-headless' { * Retrieves an option's value from the terminal. * @param key The option key. */ - getOption(key: 'bellSound' | 'bellStyle' | 'cursorStyle' | 'fontFamily' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string; + getOption(key: 'cursorStyle' | 'fontFamily' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string; /** * Retrieves an option's value from the terminal. * @param key The option key. */ - getOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'visualBell' | 'windowsMode'): boolean; + getOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'windowsMode'): boolean; /** * Retrieves an option's value from the terminal. * @param key The option key. @@ -745,7 +735,7 @@ declare module 'xterm-headless' { * @param key The option key. * @param value The option value. */ - setOption(key: 'fontFamily' | 'termName' | 'bellSound' | 'wordSeparator', value: string): void; + setOption(key: 'fontFamily' | 'termName' | 'wordSeparator', value: string): void; /** * Sets an option on the terminal. * @param key The option key. @@ -758,12 +748,6 @@ declare module 'xterm-headless' { * @param value The option value. */ setOption(key: 'logLevel', value: LogLevel): void; - /** - * Sets an option on the terminal. - * @param key The option key. - * @param value The option value. - */ - setOption(key: 'bellStyle', value: null | 'none' | 'visual' | 'sound' | 'both'): void; /** * Sets an option on the terminal. * @param key The option key. @@ -775,7 +759,7 @@ declare module 'xterm-headless' { * @param key The option key. * @param value The option value. */ - setOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'popOnBell' | 'rightClickSelectsWord' | 'visualBell' | 'windowsMode', value: boolean): void; + setOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'windowsMode', value: boolean): void; /** * Sets an option on the terminal. * @param key The option key. diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index a3f47300..e8a2f8f4 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -50,16 +50,6 @@ declare module 'xterm' { */ altClickMovesCursor?: boolean; - /** - * A data uri of the sound to use for the bell when `bellStyle = 'sound'`. - */ - bellSound?: string; - - /** - * The type of the bell notification the terminal will use. - */ - bellStyle?: 'none' | 'sound'; - /** * When enabled the cursor will be set to the beginning of the next line * with every new line. This is equivalent to sending '\r\n' for each '\n'. @@ -1128,13 +1118,13 @@ declare module 'xterm' { * @param key The option key. * @deprecated Use `options` instead. */ - getOption(key: 'bellSound' | 'bellStyle' | 'cursorStyle' | 'fontFamily' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string; + getOption(key: 'cursorStyle' | 'fontFamily' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string; /** * Retrieves an option's value from the terminal. * @param key The option key. * @deprecated Use `options` instead. */ - getOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'visualBell' | 'windowsMode'): boolean; + getOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'windowsMode'): boolean; /** * Retrieves an option's value from the terminal. * @param key The option key. @@ -1160,7 +1150,7 @@ declare module 'xterm' { * @param value The option value. * @deprecated Use `options` instead. */ - setOption(key: 'fontFamily' | 'termName' | 'bellSound' | 'wordSeparator', value: string): void; + setOption(key: 'fontFamily' | 'termName' | 'wordSeparator', value: string): void; /** * Sets an option on the terminal. * @param key The option key. @@ -1175,13 +1165,6 @@ declare module 'xterm' { * @deprecated Use `options` instead. */ setOption(key: 'logLevel', value: LogLevel): void; - /** - * Sets an option on the terminal. - * @param key The option key. - * @param value The option value. - * @deprecated Use `options` instead. - */ - setOption(key: 'bellStyle', value: null | 'none' | 'visual' | 'sound' | 'both'): void; /** * Sets an option on the terminal. * @param key The option key. @@ -1195,7 +1178,7 @@ declare module 'xterm' { * @param value The option value. * @deprecated Use `options` instead. */ - setOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'popOnBell' | 'rightClickSelectsWord' | 'visualBell' | 'windowsMode', value: boolean): void; + setOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'windowsMode', value: boolean): void; /** * Sets an option on the terminal. * @param key The option key.