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({
|
term = new Terminal({
|
||||||
cursorBlink: optionElements.cursorBlink.checked,
|
cursorBlink: optionElements.cursorBlink.checked,
|
||||||
scrollback: parseInt(optionElements.scrollback.value, 10),
|
scrollback: parseInt(optionElements.scrollback.value, 10),
|
||||||
tabStopWidth: parseInt(optionElements.tabstopwidth.value, 10),
|
tabStopWidth: parseInt(optionElements.tabstopwidth.value, 10)
|
||||||
bellStyles: [1, 2]
|
|
||||||
});
|
});
|
||||||
term.on('resize', function (size) {
|
term.on('resize', function (size) {
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
|
|||||||
+2
-2
@@ -3,7 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { ILinkMatcherOptions } from './Interfaces';
|
import { ILinkMatcherOptions } from './Interfaces';
|
||||||
import { LinkMatcherHandler, LinkMatcherValidationCallback, Charset, LineData, BellStylesEnum } from './Types';
|
import { LinkMatcherHandler, LinkMatcherValidationCallback, Charset, LineData } from './Types';
|
||||||
|
|
||||||
export interface IBrowser {
|
export interface IBrowser {
|
||||||
isNode: boolean;
|
isNode: boolean;
|
||||||
@@ -114,7 +114,7 @@ export interface IInputHandlingTerminal extends IEventEmitter {
|
|||||||
|
|
||||||
export interface ITerminalOptions {
|
export interface ITerminalOptions {
|
||||||
bellSound?: string;
|
bellSound?: string;
|
||||||
bellStyles?: BellStylesEnum[];
|
bellStyle?: string[];
|
||||||
cancelEvents?: boolean;
|
cancelEvents?: boolean;
|
||||||
colors?: string[];
|
colors?: string[];
|
||||||
cols?: number;
|
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 { 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 { ITerminal, IBrowser, ITerminalOptions, IInputHandlingTerminal, ILinkMatcherOptions, IViewport, ICompositionHelper } from './Interfaces';
|
||||||
import { BellSound } from './utils/Sounds';
|
import { BellSound } from './utils/Sounds';
|
||||||
import { BellStyles } from './utils/BellStyles';
|
|
||||||
|
|
||||||
// Declare for RequireJS in loadAddon
|
// Declare for RequireJS in loadAddon
|
||||||
declare var define: any;
|
declare var define: any;
|
||||||
@@ -150,7 +149,7 @@ const DEFAULT_OPTIONS: ITerminalOptions = {
|
|||||||
cursorBlink: false,
|
cursorBlink: false,
|
||||||
cursorStyle: 'block',
|
cursorStyle: 'block',
|
||||||
bellSound: BellSound,
|
bellSound: BellSound,
|
||||||
bellStyles: [BellStyles.Sound, BellStyles.Visual],
|
bellStyle: null,
|
||||||
scrollback: 1000,
|
scrollback: 1000,
|
||||||
screenKeys: false,
|
screenKeys: false,
|
||||||
debug: false,
|
debug: false,
|
||||||
@@ -486,6 +485,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
|
|||||||
this.viewport.syncScrollArea();
|
this.viewport.syncScrollArea();
|
||||||
break;
|
break;
|
||||||
case 'tabStopWidth': this.setupStops(); 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);
|
this.viewportElement.appendChild(this.viewportScrollArea);
|
||||||
|
|
||||||
// preload audio
|
// preload audio
|
||||||
if (this.options.bellStyles.indexOf(BellStyles.Sound) > -1) {
|
this.preloadBellSound()
|
||||||
this.bellAudioElement = document.createElement('audio');
|
|
||||||
this.bellAudioElement.setAttribute('preload', 'auto');
|
|
||||||
this.bellAudioElement.setAttribute('src', this.options.bellSound);
|
|
||||||
this.element.appendChild(this.bellAudioElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the selection container.
|
// Create the selection container.
|
||||||
this.selectionContainer = document.createElement('div');
|
this.selectionContainer = document.createElement('div');
|
||||||
@@ -1887,10 +1882,10 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
|
|||||||
*/
|
*/
|
||||||
public bell(): void {
|
public bell(): void {
|
||||||
this.emit('bell');
|
this.emit('bell');
|
||||||
if (this.options.bellStyles.indexOf(BellStyles.Sound) > -1) {
|
if (this.soundBell()) {
|
||||||
this.bellAudioElement.play();
|
this.bellAudioElement.play();
|
||||||
}
|
}
|
||||||
if (this.options.bellStyles.indexOf(BellStyles.Visual) > -1) {
|
if (this.visualBell()) {
|
||||||
this.element.classList.add('visual-bell-active');
|
this.element.classList.add('visual-bell-active');
|
||||||
clearTimeout(this.visualBellTimer);
|
clearTimeout(this.visualBellTimer);
|
||||||
this.visualBellTimer = window.setTimeout(() => {
|
this.visualBellTimer = window.setTimeout(() => {
|
||||||
@@ -2288,6 +2283,27 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
|
|||||||
|
|
||||||
return matchColorCache[hash] = li;
|
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
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { BellStyles } from './utils/BellStyles';
|
|
||||||
|
|
||||||
export type LinkMatcher = {
|
export type LinkMatcher = {
|
||||||
id: number,
|
id: number,
|
||||||
regex: RegExp,
|
regex: RegExp,
|
||||||
@@ -32,6 +30,7 @@ export type BooleanOption =
|
|||||||
'useFlowControl';
|
'useFlowControl';
|
||||||
export type StringOption =
|
export type StringOption =
|
||||||
'cursorStyle' |
|
'cursorStyle' |
|
||||||
|
'bellStyle' |
|
||||||
'termName';
|
'termName';
|
||||||
export type StringArrayOption = 'colors';
|
export type StringArrayOption = 'colors';
|
||||||
export type NumberOption =
|
export type NumberOption =
|
||||||
@@ -41,5 +40,3 @@ export type NumberOption =
|
|||||||
'scrollback';
|
'scrollback';
|
||||||
export type GeometryOption = 'geometry';
|
export type GeometryOption = 'geometry';
|
||||||
export type HandlerOption = 'handler';
|
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