Add config for bell (#468)

* Add config for bell

* Use Set instead
This commit is contained in:
Albin Ekblom 2016-08-06 00:30:40 +02:00 committed by James Hall
parent ad586d6ba2
commit f954a1e7bc
5 changed files with 39 additions and 6 deletions

View file

@ -57,7 +57,13 @@ module.exports = {
shell: '', shell: '',
// for environment variables // for environment variables
env: {} env: {},
// set to false for no bell
bell: 'SOUND'
// URL to custom bell
// bellSoundURL: 'http://example.com/bell.mp3',
// for advanced config flags please refer to https://hyperterm.org/#cfg // for advanced config flags please refer to https://hyperterm.org/#cfg
}, },

View file

@ -39,6 +39,12 @@ export default class Term extends Component {
this.term.prefs_.set('send-encoding', 'raw'); this.term.prefs_.set('send-encoding', 'raw');
this.term.prefs_.set('alt-sends-what', 'browser-key'); this.term.prefs_.set('alt-sends-what', 'browser-key');
if (props.bell === 'SOUND') {
this.term.prefs_.set('audible-bell-sound', this.props.bellSoundURL);
} else {
this.term.prefs_.set('audible-bell-sound', '');
}
this.term.onTerminalReady = () => { this.term.onTerminalReady = () => {
const io = this.term.io.push(); const io = this.term.io.push();
io.onVTKeystroke = io.sendString = props.onData; io.onVTKeystroke = io.sendString = props.onData;
@ -200,6 +206,12 @@ export default class Term extends Component {
if (this.props.customCSS !== nextProps.customCSS) { if (this.props.customCSS !== nextProps.customCSS) {
this.term.prefs_.set('user-css', this.getStylesheet(nextProps.customCSS)); this.term.prefs_.set('user-css', this.getStylesheet(nextProps.customCSS));
} }
if (this.props.bell === 'SOUND') {
this.term.prefs_.set('audible-bell-sound', this.props.bellSoundURL);
} else {
this.term.prefs_.set('audible-bell-sound', '');
}
} }
componentWillUnmount () { componentWillUnmount () {

View file

@ -143,7 +143,9 @@ export default class Terms extends Component {
onResize: this.bind(this.props.onResize, null, uid), onResize: this.bind(this.props.onResize, null, uid),
onTitle: this.bind(this.props.onTitle, null, uid), onTitle: this.bind(this.props.onTitle, null, uid),
onData: this.bind(this.props.onData, null, uid), onData: this.bind(this.props.onData, null, uid),
onURLAbort: this.bind(this.props.onURLAbort, null, uid) onURLAbort: this.bind(this.props.onURLAbort, null, uid),
bell: this.props.bell,
bellSoundURL: this.props.bellSoundURL
}); });
return <div return <div
key={`d${uid}`} key={`d${uid}`}

View file

@ -30,7 +30,9 @@ const TermsContainer = connect(
borderColor: state.ui.borderColor, borderColor: state.ui.borderColor,
colors: state.ui.colors, colors: state.ui.colors,
foregroundColor: state.ui.foregroundColor, foregroundColor: state.ui.foregroundColor,
backgroundColor: state.ui.backgroundColor backgroundColor: state.ui.backgroundColor,
bell: state.ui.bell,
bellSoundURL: state.ui.bellSoundURL
}; };
}, },
(dispatch) => { (dispatch) => {

View file

@ -18,7 +18,8 @@ import {
import { UPDATE_AVAILABLE } from '../constants/updater'; import { UPDATE_AVAILABLE } from '../constants/updater';
import { values } from '../utils/object'; import { values } from '../utils/object';
const allowedCursorShapes = ['BEAM', 'BLOCK', 'UNDERLINE']; const allowedCursorShapes = new Set(['BEAM', 'BLOCK', 'UNDERLINE']);
const allowedBells = new Set(['SOUND', false]);
// TODO: populate `config-default.js` from this :) // TODO: populate `config-default.js` from this :)
const initial = Immutable({ const initial = Immutable({
@ -64,7 +65,9 @@ const initial = Immutable({
foregroundColor: '#fff', foregroundColor: '#fff',
backgroundColor: '#000', backgroundColor: '#000',
updateVersion: null, updateVersion: null,
updateNotes: null updateNotes: null,
bell: 'SOUND',
bellSoundURL: 'lib-resource:hterm/audio/bell'
}); });
const reducer = (state = initial, action) => { const reducer = (state = initial, action) => {
@ -96,7 +99,7 @@ const reducer = (state = initial, action) => {
ret.cursorColor = config.cursorColor; ret.cursorColor = config.cursorColor;
} }
if (allowedCursorShapes.includes(config.cursorShape)) { if (allowedCursorShapes.has(config.cursorShape)) {
ret.cursorShape = config.cursorShape; ret.cursorShape = config.cursorShape;
} }
@ -124,6 +127,14 @@ const reducer = (state = initial, action) => {
ret.termCSS = config.termCSS; ret.termCSS = config.termCSS;
} }
if (allowedBells.has(config.bell)) {
ret.bell = config.bell;
}
if (null !== config.bellSoundURL) {
ret.bellSoundURL = config.bellSoundURL || initial.bellSoundURL;
}
if (null != config.colors) { if (null != config.colors) {
if (Array.isArray(config.colors)) { if (Array.isArray(config.colors)) {
const stateColors = Array.isArray(state.colors) const stateColors = Array.isArray(state.colors)