diff --git a/demo/main.js b/demo/main.js index 1464bcc6..9098c2f0 100644 --- a/demo/main.js +++ b/demo/main.js @@ -70,8 +70,7 @@ function createTerminal() { term = new Terminal({ cursorBlink: optionElements.cursorBlink.checked, scrollback: parseInt(optionElements.scrollback.value, 10), - tabStopWidth: parseInt(optionElements.tabstopwidth.value, 10), - bellStyles: [1, 2] + tabStopWidth: parseInt(optionElements.tabstopwidth.value, 10) }); term.on('resize', function (size) { if (!pid) { diff --git a/src/Interfaces.ts b/src/Interfaces.ts index 741ae09b..9ab16c3c 100644 --- a/src/Interfaces.ts +++ b/src/Interfaces.ts @@ -3,7 +3,7 @@ */ import { ILinkMatcherOptions } from './Interfaces'; -import { LinkMatcherHandler, LinkMatcherValidationCallback, Charset, LineData, BellStylesEnum } from './Types'; +import { LinkMatcherHandler, LinkMatcherValidationCallback, Charset, LineData } from './Types'; export interface IBrowser { isNode: boolean; @@ -114,7 +114,7 @@ export interface IInputHandlingTerminal extends IEventEmitter { export interface ITerminalOptions { bellSound?: string; - bellStyles?: BellStylesEnum[]; + bellStyle?: string[]; cancelEvents?: boolean; colors?: string[]; cols?: number; diff --git a/src/Terminal.ts b/src/Terminal.ts index 69d5c908..fae8e380 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -40,7 +40,6 @@ import { getRawByteCoords } from './utils/Mouse'; import { CustomKeyEventHandler, Charset, LinkMatcherHandler, LinkMatcherValidationCallback, CharData, LineData, Option, StringOption, BooleanOption, StringArrayOption, NumberOption, GeometryOption, HandlerOption } from './Types'; import { ITerminal, IBrowser, ITerminalOptions, IInputHandlingTerminal, ILinkMatcherOptions, IViewport, ICompositionHelper } from './Interfaces'; import { BellSound } from './utils/Sounds'; -import { BellStyles } from './utils/BellStyles'; // Declare for RequireJS in loadAddon declare var define: any; @@ -150,7 +149,7 @@ const DEFAULT_OPTIONS: ITerminalOptions = { cursorBlink: false, cursorStyle: 'block', bellSound: BellSound, - bellStyles: [BellStyles.Sound, BellStyles.Visual], + bellStyle: null, scrollback: 1000, screenKeys: false, debug: false, @@ -486,6 +485,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.viewport.syncScrollArea(); break; case 'tabStopWidth': this.setupStops(); break; + case 'bellStyle': this.preloadBellSound(); break; } } @@ -694,12 +694,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.viewportElement.appendChild(this.viewportScrollArea); // preload audio - if (this.options.bellStyles.indexOf(BellStyles.Sound) > -1) { - this.bellAudioElement = document.createElement('audio'); - this.bellAudioElement.setAttribute('preload', 'auto'); - this.bellAudioElement.setAttribute('src', this.options.bellSound); - this.element.appendChild(this.bellAudioElement); - } + this.preloadBellSound() // Create the selection container. this.selectionContainer = document.createElement('div'); @@ -1887,10 +1882,10 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT */ public bell(): void { this.emit('bell'); - if (this.options.bellStyles.indexOf(BellStyles.Sound) > -1) { + if (this.soundBell()) { this.bellAudioElement.play(); } - if (this.options.bellStyles.indexOf(BellStyles.Visual) > -1) { + if (this.visualBell()) { this.element.classList.add('visual-bell-active'); clearTimeout(this.visualBellTimer); this.visualBellTimer = window.setTimeout(() => { @@ -2288,6 +2283,27 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT return matchColorCache[hash] = li; } + + private visualBell() { + var styles = [].concat.apply([], [this.options.bellStyle]); + + return styles.indexOf('visual') > -1 || styles.indexOf('both') > -1 + } + + private soundBell() { + var styles = [].concat.apply([], [this.options.bellStyle]); + + return styles.indexOf('sound') > -1 || styles.indexOf('both') > -1 + } + + private preloadBellSound() { + if (this.soundBell()) { + this.bellAudioElement = document.createElement('audio'); + this.bellAudioElement.setAttribute('preload', 'auto'); + this.bellAudioElement.setAttribute('src', this.options.bellSound); + this.element.appendChild(this.bellAudioElement); + } + } } /** diff --git a/src/Types.ts b/src/Types.ts index e32f6295..c287030d 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -2,8 +2,6 @@ * @license MIT */ -import { BellStyles } from './utils/BellStyles'; - export type LinkMatcher = { id: number, regex: RegExp, @@ -32,6 +30,7 @@ export type BooleanOption = 'useFlowControl'; export type StringOption = 'cursorStyle' | + 'bellStyle' | 'termName'; export type StringArrayOption = 'colors'; export type NumberOption = @@ -41,5 +40,3 @@ export type NumberOption = 'scrollback'; export type GeometryOption = 'geometry'; export type HandlerOption = 'handler'; - -export type BellStylesEnum = BellStyles; diff --git a/src/utils/BellStyles.ts b/src/utils/BellStyles.ts deleted file mode 100644 index 5534ea54..00000000 --- a/src/utils/BellStyles.ts +++ /dev/null @@ -1,5 +0,0 @@ -export enum BellStyles { - None, - Sound, - Visual -}