Improve support for inverted mode for PNG

pull/601/head
Igor Chubin 4 years ago
parent 5ef9e3eddb
commit 3c1ef6f681

@ -85,14 +85,17 @@ def render_ansi(text, options=None):
return _gen_term(buf, graphemes, options=options) return _gen_term(buf, graphemes, options=options)
def _color_mapping(color): def _color_mapping(color, inverse=False):
"""Convert pyte color to PIL color """Convert pyte color to PIL color
Return: tuple of color values (R,G,B) Return: tuple of color values (R,G,B)
""" """
if color == 'default': if color == 'default':
if inverse:
return 'black'
return 'lightgray' return 'lightgray'
if color in ['green', 'black', 'cyan', 'blue', 'brown']: if color in ['green', 'black', 'cyan', 'blue', 'brown']:
return color return color
try: try:
@ -185,7 +188,7 @@ def _gen_term(buf, graphemes, options=None):
bg_color = 0 bg_color = 0
if "background" in options: if "background" in options:
bg_color = _color_mapping(options["background"]) bg_color = _color_mapping(options["background"], options.get("inverted_colors"))
image = Image.new('RGB', (cols * CHAR_WIDTH, rows * CHAR_HEIGHT), color=bg_color) image = Image.new('RGB', (cols * CHAR_WIDTH, rows * CHAR_HEIGHT), color=bg_color)
@ -203,12 +206,12 @@ def _gen_term(buf, graphemes, options=None):
for line in buf: for line in buf:
x_pos = 0 x_pos = 0
for char in line: for char in line:
current_color = _color_mapping(char.fg) current_color = _color_mapping(char.fg, options.get("inverted_colors"))
if char.bg != 'default': if char.bg != 'default':
draw.rectangle( draw.rectangle(
((x_pos, y_pos), ((x_pos, y_pos),
(x_pos+CHAR_WIDTH, y_pos+CHAR_HEIGHT)), (x_pos+CHAR_WIDTH, y_pos+CHAR_HEIGHT)),
fill=_color_mapping(char.bg)) fill=_color_mapping(char.bg, options.get("inverted_colors")))
if char.data == "!": if char.data == "!":
try: try:

Loading…
Cancel
Save