diff --git a/lib/components/term.js b/lib/components/term.js index 4bb212b9..73474455 100644 --- a/lib/components/term.js +++ b/lib/components/term.js @@ -4,6 +4,7 @@ import Color from 'color'; import hterm from '../hterm'; import Component from '../component'; import { getColorList } from '../utils/colors'; +import notify from '../utils/notify'; export default class Term extends Component { @@ -28,7 +29,7 @@ export default class Term extends Component { this.term.prefs_.set('font-family', props.fontFamily); this.term.prefs_.set('font-size', props.fontSize); this.term.prefs_.set('font-smoothing', props.fontSmoothing); - this.term.prefs_.set('cursor-color', Color(props.cursorColor).rgbString()); + this.term.prefs_.set('cursor-color', this.validateColor(props.cursorColor, 'rgba(255,255,255,0.5)')); this.term.prefs_.set('enable-clipboard-notice', false); this.term.prefs_.set('foreground-color', props.foregroundColor); this.term.prefs_.set('background-color', props.backgroundColor); @@ -158,6 +159,15 @@ export default class Term extends Component { return URL.createObjectURL(blob); } + validateColor (color, alternative = 'rgb(255,255,255)') { + try { + return Color(color).rgbString(); + } catch (err) { + notify(`color "${color}" is invalid`); + } + return alternative; + } + componentWillReceiveProps (nextProps) { if (this.props.url !== nextProps.url) { // when the url prop changes, we make sure @@ -201,7 +211,7 @@ export default class Term extends Component { } if (this.props.cursorColor !== nextProps.cursorColor) { - this.term.prefs_.set('cursor-color', Color(nextProps.cursorColor).rgbString()); + this.term.prefs_.set('cursor-color', this.validateColor(nextProps.cursorColor, 'rgba(255,255,255,0.5)')); } if (this.props.cursorShape !== nextProps.cursorShape) {