-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If bell() gets called emit bell event and add default bell sound #878
Changes from 20 commits
245f626
0eab4d6
fd51d0a
6b46e08
8a1f365
44ed0b9
8c94ef8
3027b1d
96c9d50
d8717d6
2f1380a
c41bd81
3beb1f5
1d6f71d
0bb5ff8
c88f501
8a6bff4
68cd79d
b0164e1
668b25e
147fef7
1211435
42c3eff
1f930c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ import { CHARSETS } from './Charsets'; | |
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'; | ||
|
||
// Declare for RequireJS in loadAddon | ||
declare var define: any; | ||
|
@@ -147,8 +148,8 @@ const DEFAULT_OPTIONS: ITerminalOptions = { | |
geometry: [80, 24], | ||
cursorBlink: false, | ||
cursorStyle: 'block', | ||
visualBell: false, | ||
popOnBell: false, | ||
bellSound: BellSound, | ||
bellStyle: null, | ||
scrollback: 1000, | ||
screenKeys: false, | ||
debug: false, | ||
|
@@ -178,6 +179,8 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT | |
private helperContainer: HTMLElement; | ||
private compositionView: HTMLElement; | ||
private charSizeStyleElement: HTMLStyleElement; | ||
private bellAudioElement: HTMLAudioElement; | ||
private visualBellTimer: number; | ||
|
||
public browser: IBrowser = <any>Browser; | ||
|
||
|
@@ -482,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; | ||
} | ||
} | ||
|
||
|
@@ -689,6 +693,9 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT | |
this.viewportScrollArea.classList.add('xterm-scroll-area'); | ||
this.viewportElement.appendChild(this.viewportScrollArea); | ||
|
||
// preload audio | ||
this.preloadBellSound(); | ||
|
||
// Create the selection container. | ||
this.selectionContainer = document.createElement('div'); | ||
this.selectionContainer.classList.add('xterm-selection'); | ||
|
@@ -1874,12 +1881,16 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT | |
* Note: We could do sweet things with webaudio here | ||
*/ | ||
public bell(): void { | ||
if (!this.options.visualBell) return; | ||
this.element.style.borderColor = 'white'; | ||
setTimeout(() => { | ||
this.element.style.borderColor = ''; | ||
}, 10); | ||
if (this.options.popOnBell) this.focus(); | ||
this.emit('bell'); | ||
if (this.soundBell()) this.bellAudioElement.play(); | ||
|
||
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); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -2271,6 +2282,27 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT | |
|
||
return matchColorCache[hash] = li; | ||
} | ||
|
||
private visualBell(): boolean { | ||
return this.options.bellStyle === 'visual' || | ||
this.options.bellStyle === 'both'; | ||
} | ||
|
||
private soundBell(): boolean { | ||
return this.options.bellStyle === 'sound' || | ||
this.options.bellStyle === 'both'; | ||
} | ||
|
||
private preloadBellSound(): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove it too if sound is now disabled |
||
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); | ||
} else if (this.bellAudioElement) { | ||
this.bellAudioElement.remove(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Support for |
||
} | ||
} | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* @license MIT | ||
*/ | ||
|
||
// 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 BellSound = 'data:audio/wav;base64,UklGRigBAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQQBAADpAFgCwAMlBZoG/wdmCcoKRAypDQ8PbRDBEQQTOxRtFYcWlBePGIUZXhoiG88bcBz7HHIdzh0WHlMeZx51HmkeUx4WHs8dah0AHXwc3hs9G4saxRnyGBIYGBcQFv8U4RPAEoYRQBACD70NWwwHC6gJOwjWBloF7gOBAhABkf8b/qv8R/ve+Xf4Ife79W/0JfPZ8Z/wde9N7ijtE+wU6xvqM+lb6H7nw+YX5mrlxuQz5Mzje+Ma49fioeKD4nXiYeJy4pHitOL04j/jn+MN5IPkFOWs5U3mDefM55/ogOl36m7rdOyE7abuyu8D8Unyj/Pg9D/2qfcb+Yn6/vuK/Qj/lAAlAg=='; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,7 @@ | |
|
||
.terminal .terminal-cursor { | ||
position: relative; | ||
transition: background-color 150ms ease; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. transition: opacity...? |
||
} | ||
|
||
.terminal:not(.focus) .terminal-cursor { | ||
|
@@ -108,6 +109,7 @@ | |
content: ''; | ||
position: absolute; | ||
background-color: #fff; | ||
transition: background-color 150ms ease; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. transition: opacity...? |
||
} | ||
|
||
.terminal.focus.xterm-cursor-style-bar:not(.xterm-cursor-blink-on) .terminal-cursor::before { | ||
|
@@ -124,6 +126,14 @@ | |
height: 1px; | ||
} | ||
|
||
.terminal.focus.xterm-cursor-style-block.visual-bell-active .terminal-cursor { | ||
background-color: #ccc !important; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be better to transition on opacity so that consumers that use custom themes don't need to deal with the visual bell? |
||
} | ||
.terminal.focus.xterm-cursor-style-bar.visual-bell-active .terminal-cursor::before, | ||
.terminal.focus.xterm-cursor-style-underline.visual-bell-active .terminal-cursor::before { | ||
background-color: transparent; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this needs to be opacity: 0 |
||
} | ||
|
||
.terminal .composition-view { | ||
background: #000; | ||
color: #FFF; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be cool if this gets lazy loaded using dynamic imports microsoft/TypeScript#12364. I'm not sure how well this works on the web yet, I guess we can defer this unless you want to have a look? #894
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a stab at this but was getting some errors so I think I'll punt this to a different PR if that's alright.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it might not be so easy 👍