Fix color configuration with an array (#2729)

Fixes #2728
This commit is contained in:
CHaBou 2018-03-21 10:00:29 +01:00 committed by GitHub
parent 500c8b0e05
commit dc33d4846b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 16 deletions

View file

@ -4,6 +4,7 @@ const {_import, getDefaultConfig} = require('./config/import');
const _openConfig = require('./config/open');
const win = require('./config/windows');
const {cfgPath, cfgDir} = require('./config/paths');
const {getColorMap} = require('./utils/colors');
const watchers = [];
let cfg = {};
@ -129,6 +130,7 @@ const checkDeprecatedConfig = function() {
exports.fixConfigDefaults = decoratedConfig => {
const defaultConfig = getDefaultConfig().config;
decoratedConfig.colors = getColorMap(decoratedConfig.colors) || {};
// We must have default colors for xterm css.
decoratedConfig.colors = Object.assign({}, defaultConfig.colors, decoratedConfig.colors);
return decoratedConfig;

View file

@ -19,13 +19,14 @@ const colorList = [
'grayscale'
];
export default function getColorList(colors) {
// For backwards compatibility, return early if it's already an array
if (Array.isArray(colors)) {
exports.getColorMap = colors => {
if (!Array.isArray(colors)) {
return colors;
}
return colorList.map(colorName => {
return colors[colorName];
});
}
return colors.reduce((result, color, index) => {
if (index < colorList.length) {
result[colorList[index]] = color;
}
return result;
}, {});
};

View file

@ -20,7 +20,6 @@ import {
SESSION_SET_CWD
} from '../constants/sessions';
import {UPDATE_AVAILABLE} from '../constants/updater';
import {values} from '../utils/object';
const allowedCursorShapes = new Set(['BEAM', 'BLOCK', 'UNDERLINE']);
const allowedCursorBlinkValues = new Set([true, false]);
@ -200,13 +199,7 @@ const reducer = (state = initial, action) => {
}
if (config.colors) {
if (Array.isArray(config.colors)) {
const stateColors = Array.isArray(state.colors) ? state.colors : values(state.colors);
if (stateColors.toString() !== config.colors.toString()) {
ret.colors = config.colors;
}
} else if (JSON.stringify(state.colors) !== JSON.stringify(config.colors)) {
if (JSON.stringify(state.colors) !== JSON.stringify(config.colors)) {
ret.colors = config.colors;
}
}