From 3daba1b070212164afc6fb951741af5c4a3ae652 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 14 Dec 2021 22:51:04 +0100 Subject: [PATCH] webconfig: Stop translating named colors If the theme says "brgreen", that's what we want the variable to say after. This used to translate it through our palette, so it ended up as 00ff00, which isn't the same. This still keeps the idea that colors that aren't in the palette are better, and it does it in a slightly roundabout way (translate color string to rgb string, see if the rgb string is a key in that translation dictionary), but it should work for now. --- share/tools/web_config/js/colorutils.js | 2 +- share/tools/web_config/js/controllers.js | 2 +- share/tools/web_config/webconfig.py | 22 ++++++++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/share/tools/web_config/js/colorutils.js b/share/tools/web_config/js/colorutils.js index 8497bd556..4fff5e606 100644 --- a/share/tools/web_config/js/colorutils.js +++ b/share/tools/web_config/js/colorutils.js @@ -218,7 +218,7 @@ function interpret_color(str) { if (str == 'brpurple') return '#ff00ff'; if (str == 'brcyan') return '#00ffff'; if (str == 'brwhite') return '#ffffff'; - if (str == 'normal') return ''; + if (str == 'normal') return '#ffffff'; if (str == 'reset') return ''; return '#' + str } diff --git a/share/tools/web_config/js/controllers.js b/share/tools/web_config/js/controllers.js index bb74355d5..ca5319f27 100644 --- a/share/tools/web_config/js/controllers.js +++ b/share/tools/web_config/js/controllers.js @@ -105,7 +105,7 @@ controllers.controller("colorsController", function($scope, $http) { var cols = []; for (var i in data) { - currentScheme[data[i].name] = data[i].color; + currentScheme[data[i].name] = interpret_color(data[i].color).replace(/#/, ''); // HACK: For some reason the colors array is cleared later // So we cheesily encode the actual objects as colordata-, so we can send them. // TODO: We should switch to keeping the objects, and also displaying them diff --git a/share/tools/web_config/webconfig.py b/share/tools/web_config/webconfig.py index f2e245355..7b33ec650 100755 --- a/share/tools/web_config/webconfig.py +++ b/share/tools/web_config/webconfig.py @@ -191,7 +191,7 @@ def better_color(c1, c2): def parse_color(color_str): """A basic function to parse a color string, for example, 'red' '--bold'.""" comps = color_str.split(" ") - color = "normal" + color = "" background_color = "" bold, underline, italics, dim, reverse = False, False, False, False, False for comp in comps: @@ -209,20 +209,26 @@ def parse_color(color_str): reverse = True elif comp.startswith("--background"): # Background color - background_color = better_color( - background_color, parse_one_color(comp[len("--background=") :]) - ) + c = comp[len("--background=") :] + parsed_c = parse_one_color(c) + # We prefer the unparsed version - if it says "brgreen", we use brgreen, + # instead of 00ff00 + if better_color(background_color, parsed_c) == parsed_c: + background_color = c elif comp.startswith("-b"): # Background color in short. skip = len("-b") if comp[len("-b=")] in ["=", " "]: skip += 1 - background_color = better_color( - background_color, parse_one_color(comp[skip :]) - ) + c = comp[skip :] + parsed_c = parse_one_color(c) + if better_color(background_color, parsed_c) == parsed_c: + background_color = c else: # Regular color - color = better_color(color, parse_one_color(comp)) + parsed_c = parse_one_color(comp) + if better_color(color, parsed_c) == parsed_c: + color = comp return { "color": color,