mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Make bellStyle singular. Preload sound on option setting. Use strings as options
This commit is contained in:
+1
-2
@@ -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) {
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+26
-10
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-4
@@ -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;
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
export enum BellStyles {
|
||||
None,
|
||||
Sound,
|
||||
Visual
|
||||
}
|
||||
Reference in New Issue
Block a user