mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-16 21:58:39 -09:00
refactor `validateColor`: remove unnecessary variable declaration
This commit is contained in:
parent
e2b270b172
commit
125fdd98e5
1 changed files with 12 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ import Color from 'color';
|
||||||
import hterm from '../hterm';
|
import hterm from '../hterm';
|
||||||
import Component from '../component';
|
import Component from '../component';
|
||||||
import { getColorList } from '../utils/colors';
|
import { getColorList } from '../utils/colors';
|
||||||
|
import notify from '../utils/notify';
|
||||||
|
|
||||||
export default class Term extends Component {
|
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-family', props.fontFamily);
|
||||||
this.term.prefs_.set('font-size', props.fontSize);
|
this.term.prefs_.set('font-size', props.fontSize);
|
||||||
this.term.prefs_.set('font-smoothing', props.fontSmoothing);
|
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('enable-clipboard-notice', false);
|
||||||
this.term.prefs_.set('foreground-color', props.foregroundColor);
|
this.term.prefs_.set('foreground-color', props.foregroundColor);
|
||||||
this.term.prefs_.set('background-color', props.backgroundColor);
|
this.term.prefs_.set('background-color', props.backgroundColor);
|
||||||
|
|
@ -158,6 +159,15 @@ export default class Term extends Component {
|
||||||
return URL.createObjectURL(blob);
|
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) {
|
componentWillReceiveProps (nextProps) {
|
||||||
if (this.props.url !== nextProps.url) {
|
if (this.props.url !== nextProps.url) {
|
||||||
// when the url prop changes, we make sure
|
// when the url prop changes, we make sure
|
||||||
|
|
@ -201,7 +211,7 @@ export default class Term extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.props.cursorColor !== nextProps.cursorColor) {
|
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) {
|
if (this.props.cursorShape !== nextProps.cursorShape) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue