Skip to content

Commit

Permalink
Fix color configuration with an array (#2729)
Browse files Browse the repository at this point in the history
Fixes #2728
  • Loading branch information
chabou authored Mar 21, 2018
1 parent 500c8b0 commit dc33d48
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
2 changes: 2 additions & 0 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions lib/utils/colors.js → app/utils/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}, {});
};
9 changes: 1 addition & 8 deletions lib/reducers/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit dc33d48

Please sign in to comment.