Always output HTML colors as hex codes.
This commit is contained in:
parent
8bb383220f
commit
d7485cc746
2 changed files with 23 additions and 27 deletions
|
@ -576,22 +576,22 @@ def color_weechat_to_html(color):
|
||||||
# type: (str) -> str
|
# type: (str) -> str
|
||||||
# yapf: disable
|
# yapf: disable
|
||||||
weechat_basic_colors = {
|
weechat_basic_colors = {
|
||||||
"black": "black", # 0
|
"black": "0",
|
||||||
"red": "maroon", # 1
|
"red": "1",
|
||||||
"green": "green", # 2
|
"green": "2",
|
||||||
"brown": "olive", # 3
|
"brown": "3",
|
||||||
"blue": "navy", # 4
|
"blue": "4",
|
||||||
"magenta": "purple", # 5
|
"magenta": "5",
|
||||||
"cyan": "teal", # 6
|
"cyan": "6",
|
||||||
"default": "silver", # 7
|
"default": "7",
|
||||||
"gray": "gray", # 8
|
"gray": "8",
|
||||||
"lightred": "red", # 9
|
"lightred": "9",
|
||||||
"lightgreen": "lime", # 11
|
"lightgreen": "10",
|
||||||
"yellow": "yellow", # 12
|
"yellow": "11",
|
||||||
"lightblue": "blue", # 13
|
"lightblue": "12",
|
||||||
"lightmagenta": "fuchsia", # 14
|
"lightmagenta": "13",
|
||||||
"lightcyan": "aqua", # 15
|
"lightcyan": "14",
|
||||||
"white": "white", # 16
|
"white": "15",
|
||||||
}
|
}
|
||||||
hex_colors = {
|
hex_colors = {
|
||||||
"0": "#000000",
|
"0": "#000000",
|
||||||
|
@ -851,14 +851,9 @@ def color_weechat_to_html(color):
|
||||||
"254": "#e4e4e4",
|
"254": "#e4e4e4",
|
||||||
"255": "#eeeeee"
|
"255": "#eeeeee"
|
||||||
}
|
}
|
||||||
|
|
||||||
# yapf: enable
|
# yapf: enable
|
||||||
|
|
||||||
if color in weechat_basic_colors:
|
if color in weechat_basic_colors:
|
||||||
return weechat_basic_colors[color]
|
return hex_colors[weechat_basic_colors[color]]
|
||||||
|
else:
|
||||||
hex_color = hex_colors[color]
|
return hex_colors[color]
|
||||||
|
|
||||||
try:
|
|
||||||
return webcolors.hex_to_name(hex_color)
|
|
||||||
except ValueError:
|
|
||||||
return hex_color
|
|
||||||
|
|
|
@ -22,5 +22,6 @@ def test_prism():
|
||||||
|
|
||||||
@given(sampled_from(first_16_html_colors))
|
@given(sampled_from(first_16_html_colors))
|
||||||
def test_color_conversion(color_name):
|
def test_color_conversion(color_name):
|
||||||
assert color_weechat_to_html(
|
hex_color = color_weechat_to_html(color_html_to_weechat(color_name))
|
||||||
color_html_to_weechat(color_name)) == color_name
|
new_color_name = webcolors.hex_to_name(hex_color, spec='html4')
|
||||||
|
assert new_color_name == color_name
|
||||||
|
|
Loading…
Reference in a new issue