diff --git a/zulipterminal/config/gruvbox.py b/zulipterminal/config/gruvbox.py index ed076730aa..dee9612683 100644 --- a/zulipterminal/config/gruvbox.py +++ b/zulipterminal/config/gruvbox.py @@ -1,267 +1,73 @@ -# Colors used in gruvbox-256 -# See https://github.com/morhetz/gruvbox/blob/master/colors/gruvbox.vim -BLACK = "h234" # dark0_hard -WHITE = "h246" # light4_256 -WHITEBOLD = f"{WHITE}, bold" -DARKBLUE = "h24" # faded_blue -DARKRED = "h88" # faded_red -LIGHTBLUE = "h109" # bright_blue -LIGHTBLUEBOLD = f"{LIGHTBLUE}, bold" -YELLOW = "h172" # neutral_yellow -YELLOWBOLD = f"{YELLOW}, bold" -LIGHTGREEN = "h142" # bright_green -LIGHTRED = "h167" # bright_red -LIGHTREDBOLD = f"{LIGHTRED}, bold" -GRAY = "h244" # gray_244 -LIGHTMAGENTA = "h132" # neutral_purple -LIGHTMAGENTABOLD = f"{LIGHTMAGENTA}, bold" +from enum import Enum -# Colors used in gruvbox_dark24 -BLACK24 = "#1d2021" # dark0_hard -WHITE24 = "#a89984" # light4 -WHITEBOLD24 = f"{WHITE24}, bold" -DARKBLUE24 = "#076678" # faded_blue -DARKRED24 = "#9d0006" # faded_red -LIGHTBLUE24 = "#83a598" # bright_blue -LIGHTBLUEBOLD24 = f"{LIGHTBLUE24}, bold" -YELLOW24 = "#d79921" # neutral_yellow -YELLOWBOLD24 = f"{YELLOW24}, bold" -LIGHTGREEN24 = "#b8bb26" # bright_green -LIGHTRED24 = "#fb4934" # bright_red -LIGHTREDBOLD24 = f"{LIGHTRED24}, bold" -GRAY24 = "#928374" # gray_244 -LIGHTMAGENTA24 = "#b16286" # neutral_purple -LIGHTMAGENTABOLD24 = f"{LIGHTMAGENTA24}, bold" +from zulipterminal.config.themes import add_color_prop -styles = { - None: { - 16: ["white", "black"], - 256: [WHITE, BLACK], - 24: [WHITE24, BLACK24], - }, - "selected": { - 16: ["black", "white"], - 256: [BLACK, WHITE], - 24: [BLACK24, WHITE24], - }, - "msg_selected": { - 16: ["black", "white"], - 256: [BLACK, WHITE], - 24: [BLACK24, WHITE24], - }, - "header": { - 16: ["dark cyan", "dark blue"], - 256: ["dark cyan", DARKBLUE], - 24: ["dark cyan", DARKBLUE24], - }, - "general_narrow": { - 16: ["white", "dark blue"], - 256: [WHITE, DARKBLUE], - 24: [WHITE24, DARKBLUE24], - }, - "general_bar": { - 16: ["white", "black"], - 256: [WHITE, BLACK], - 24: [WHITE24, BLACK24], - }, - "name": { - 16: ["yellow, bold", "black"], - 256: [YELLOWBOLD, BLACK], - 24: [YELLOWBOLD24, BLACK24], - }, - "unread": { - 16: ["light magenta", "black"], - 256: [LIGHTMAGENTA, BLACK], - 24: [LIGHTMAGENTA24, BLACK24], - }, - "user_active": { - 16: ["light green", "black"], - 256: [LIGHTGREEN, BLACK], - 24: [LIGHTGREEN24, BLACK24], - }, - "user_idle": { - 16: ["yellow", "black"], - 256: [YELLOW, BLACK], - 24: [YELLOW24, BLACK24], - }, - "user_offline": { - 16: ["white", "black"], - 256: [WHITE, BLACK], - 24: [WHITE24, BLACK24], - }, - "user_inactive": { - 16: ["white", "black"], - 256: [WHITE, BLACK], - 24: [WHITE24, BLACK24], - }, - "title": { - 16: ["white, bold", "black"], - 256: [WHITEBOLD, BLACK], - 24: [WHITEBOLD24, BLACK24], - }, - "column_title": { - 16: ["white, bold", "black"], - 256: [WHITEBOLD, BLACK], - 24: [WHITEBOLD24, BLACK24], - }, - "time": { - 16: ["light blue", "black"], - 256: [LIGHTBLUE, BLACK], - 24: [LIGHTBLUE24, BLACK24], - }, - "bar": { - 16: ["white", "dark gray"], - 256: [WHITE, GRAY], - 24: [WHITE24, GRAY24], - }, - "popup_contrast": { - 16: ["black", "dark gray"], - 256: [BLACK, GRAY], - 24: [BLACK24, GRAY24], - }, - "msg_emoji": { - 16: ["light magenta", "black"], - 256: [LIGHTMAGENTA, BLACK], - 24: [LIGHTMAGENTA24, BLACK24], - }, - "reaction": { - 16: ["light magenta, bold", "black"], - 256: [LIGHTMAGENTABOLD, BLACK], - 24: [LIGHTMAGENTABOLD24, BLACK24], - }, - "reaction_mine": { - 16: ["black", "light magenta"], - 256: [BLACK, LIGHTMAGENTA], - 24: [BLACK24, LIGHTMAGENTA24], - }, - "msg_mention": { - 16: ["light red, bold", "black"], - 256: [LIGHTREDBOLD, BLACK], - 24: [LIGHTREDBOLD24, BLACK24], - }, - "msg_link": { - 16: ["light blue", "black"], - 256: [LIGHTBLUE, BLACK], - 24: [LIGHTBLUE24, BLACK24], - }, - "msg_link_index": { - 16: ["light blue, bold", "black"], - 256: [LIGHTBLUEBOLD, BLACK], - 24: [LIGHTBLUEBOLD24, BLACK24], - }, - "msg_quote": { - 16: ["brown", "black"], - 256: ["brown", BLACK], - 24: ["brown", BLACK24], - }, - "msg_code": { - 16: ["black", "white"], - 256: [BLACK, WHITE], - 24: [BLACK24, WHITE24], - }, - "msg_bold": { - 16: ["white, bold", "black"], - 256: [WHITEBOLD, BLACK], - 24: [WHITEBOLD24, BLACK24], - }, - "msg_time": { - 16: ["black", "white"], - 256: [BLACK, WHITE], - 24: [BLACK24, WHITE24], - }, - "footer": { - 16: ["white", "dark red"], - 256: [WHITE, DARKRED], - 24: [WHITE24, DARKRED24], - }, - "starred": { - 16: ["light red, bold", "black"], - 256: [LIGHTREDBOLD, BLACK], - 24: [LIGHTREDBOLD24, BLACK24], - }, - "popup_category": { - 16: ["light blue, bold", "black"], - 256: [LIGHTBLUE, BLACK], - 24: [LIGHTBLUE24, BLACK24], - }, - "unread_count": { - 16: ["yellow", "black"], - 256: [YELLOW, BLACK], - 24: [YELLOW24, BLACK24], - }, - "starred_count": { - 16: ["light gray", "black"], - 256: [GRAY, BLACK], - 24: [WHITE24, BLACK24], - }, - "table_head": { - 16: ["white, bold", "black"], - 256: [WHITEBOLD, BLACK], - 24: [WHITEBOLD24, BLACK24], - }, - "filter_results": { - 16: ["black", "light green"], - 256: [BLACK, LIGHTGREEN], - 24: [BLACK24, LIGHTGREEN24], - }, - "edit_topic": { - 16: ["black", "dark gray"], - 256: [BLACK, GRAY], - 24: [BLACK24, GRAY24], - }, - "edit_tag": { - 16: ["black", "dark gray"], - 256: [BLACK, GRAY], - 24: [BLACK24, GRAY24], - }, - "edit_author": { - 16: ["yellow", "black"], - 256: [YELLOW, BLACK], - 24: [YELLOW24, BLACK24], - }, - "edit_time": { - 16: ["light blue", "black"], - 256: [LIGHTBLUE, BLACK], - 24: [LIGHTBLUE24, BLACK24], - }, - "current_user": { - 16: ["white", "black"], - 256: [WHITE, BLACK], - 24: [WHITE24, BLACK24], - }, - "muted": { - 16: ["light blue", "black"], - 256: [LIGHTBLUE, BLACK], - 24: [LIGHTBLUE24, BLACK24], - }, - "popup_border": { - 16: ["white", "black"], - 256: [WHITE, BLACK], - 24: [WHITE24, BLACK24], - }, - "area:help": { - 16: ["black", "light green"], - 256: [BLACK, LIGHTGREEN], - 24: [BLACK24, LIGHTGREEN24], - }, - "area:msg": { - 16: ["black", "light red"], - 256: [BLACK, LIGHTRED], - 24: [BLACK24, LIGHTRED24], - }, - "area:stream": { - 16: ["black", "light blue"], - 256: [BLACK, LIGHTBLUE], - 24: [BLACK24, LIGHTBLUE24], - }, - "area:error": { - 16: ["white", "dark red"], - 256: [WHITE, DARKRED], - 24: [WHITE24, DARKRED24], - }, - "search_error": { - 16: ["light red", "black"], - 256: [LIGHTRED, BLACK], - 24: [LIGHTRED24, BLACK24], - }, + +# fmt: off +class Color(Enum): + BLACK = 'h234 #1d2021' + WHITE = 'h246 #a89984' + DARK_BLUE = 'h24 #076678' + DARK_RED = 'h88 #9d0006' + LIGHT_BLUE = 'h109 #83a598' + YELLOW = 'h172 #d79921' + LIGHT_GREEN = 'h142 #b8bb26' + LIGHT_RED = 'h167 #fb4934' + DARK_GRAY = 'h244 #928374' + LIGHT_MAGENTA = 'h132 #b16286' + DARK_CYAN = 'dark_cyan dark_cyan' + BROWN = 'brown brown' + +Color = add_color_prop(Color, "BOLD") +# Use dunder for bold +# Eg: Color.YELLOW__BOLD + +STYLES = { + None : (Color.WHITE, Color.BLACK), + 'selected' : (Color.BLACK, Color.WHITE), + 'msg_selected' : (Color.BLACK, Color.WHITE), + 'header' : (Color.DARK_CYAN, Color.DARK_BLUE), + 'general_narrow' : (Color.WHITE, Color.DARK_BLUE), + 'general_bar' : (Color.WHITE, Color.BLACK), + 'name' : (Color.YELLOW__BOLD, Color.BLACK), + 'unread' : (Color.LIGHT_MAGENTA, Color.BLACK), + 'user_active' : (Color.LIGHT_GREEN, Color.BLACK), + 'user_idle' : (Color.YELLOW, Color.BLACK), + 'user_offline' : (Color.WHITE, Color.BLACK), + 'user_inactive' : (Color.WHITE, Color.BLACK), + 'title' : (Color.WHITE__BOLD, Color.BLACK), + 'column_title' : (Color.WHITE__BOLD, Color.BLACK), + 'time' : (Color.LIGHT_BLUE, Color.BLACK), + 'bar' : (Color.WHITE, Color.DARK_GRAY), + 'popup_contrast' : (Color.BLACK, Color.DARK_GRAY), + 'msg_emoji' : (Color.LIGHT_MAGENTA, Color.BLACK), + 'reaction' : (Color.LIGHT_MAGENTA__BOLD, Color.BLACK), + 'reaction_mine' : (Color.BLACK, Color.LIGHT_MAGENTA), + 'msg_mention' : (Color.LIGHT_RED__BOLD, Color.BLACK), + 'msg_link' : (Color.LIGHT_BLUE, Color.BLACK), + 'msg_link_index' : (Color.LIGHT_BLUE__BOLD, Color.BLACK), + 'msg_quote' : (Color.BROWN, Color.BLACK), + 'msg_code' : (Color.BLACK, Color.WHITE), + 'msg__bold' : (Color.WHITE__BOLD, Color.BLACK), + 'msg_time' : (Color.BLACK, Color.WHITE), + 'footer' : (Color.WHITE, Color.DARK_RED), + 'starred' : (Color.LIGHT_RED__BOLD, Color.BLACK), + 'popup_category' : (Color.LIGHT_BLUE, Color.BLACK), + 'unread_count' : (Color.YELLOW, Color.BLACK), + 'starred_count' : (Color.DARK_GRAY, Color.BLACK), + 'table_head' : (Color.WHITE__BOLD, Color.BLACK), + 'filter_results' : (Color.BLACK, Color.LIGHT_GREEN), + 'edit_topic' : (Color.BLACK, Color.DARK_GRAY), + 'edit_tag' : (Color.BLACK, Color.DARK_GRAY), + 'edit_author' : (Color.YELLOW, Color.BLACK), + 'edit_time' : (Color.LIGHT_BLUE, Color.BLACK), + 'current_user' : (Color.WHITE, Color.BLACK), + 'muted' : (Color.LIGHT_BLUE, Color.BLACK), + 'popup_border' : (Color.WHITE, Color.BLACK), + 'area:help' : (Color.BLACK, Color.LIGHT_GREEN), + 'area:msg' : (Color.BLACK, Color.LIGHT_RED), + 'area:stream' : (Color.BLACK, Color.LIGHT_BLUE), + 'area:error' : (Color.WHITE, Color.DARK_RED), + 'search_error' : (Color.LIGHT_RED, Color.BLACK), } +# fmt: on diff --git a/zulipterminal/config/themes.py b/zulipterminal/config/themes.py index 76681d3711..284ddb5c47 100644 --- a/zulipterminal/config/themes.py +++ b/zulipterminal/config/themes.py @@ -1,5 +1,5 @@ +from enum import Enum from typing import Dict, List, Optional, Tuple -from zulipterminal.config import gruvbox ThemeSpec = List[Tuple[Optional[str], ...]] @@ -544,34 +544,59 @@ def theme_with_monochrome_added(theme: ThemeSpec) -> ThemeSpec: return theme +def add_color_prop(colors, *prop): + """ + Adds properties(Bold, Italics, etc...) to Enum Colors + Use: add_color_prop(Color, 'BOLD', 'ITALICS', 'STRIKETHROUGH') + """ + prop_n = "_".join([p.upper() for p in prop]) + prop_v = " , ".join([p.lower() for p in prop]) + colors = Enum( + "Color", + { + **{c.name: c.value for c in colors}, + **{c.name + f"__{prop_n}": c.value + f" , {prop_v}" for c in colors}, + }, + ) + return colors + + +from zulipterminal.config import gruvbox + ZT_THEMES = {"gruvbox_dark": gruvbox} def generate_theme(theme_name, color_depth): - theme_styles = ZT_THEMES[theme_name].styles + theme_styles = ZT_THEMES[theme_name].STYLES urwid_theme = [] for style_name, style_conf in theme_styles.items(): - # style_conf = theme_styles[style_name] + fg, bg = style_conf + fg_codes = fg.value.split() + bg_codes = bg.value.split() + if color_depth == 1: + # FIXME: Check for completeness of required_styles try: - new_style = [style_name, "", "", required_styles[style_name]] + new_style = (style_name, "", "", required_styles[style_name]) except: pass elif color_depth == 16: - new_style = [style_name] + style_conf[16] + fg_name = fg.name.lower().split("__")[0].replace("_", " ") + bg_name = bg.name.lower().split("__")[0].replace("_", " ") + fg = fg_name + " ".join(fg_codes[2:]) + bg = bg_name + " ".join(bg_codes[2:]) + new_style = (style_name, fg, bg) elif color_depth == 256: - new_style = [style_name] - new_style += style_conf[16] - new_style += [None] - new_style += style_conf[256] + fg = " ".join(fg_codes[:1] + fg_codes[2:]).replace("_", " ") + bg = " ".join(bg_codes[:1] + bg_codes[2:]).replace("_", " ") + new_style = (style_name, "", "", "", fg, bg) elif color_depth == 2 ** 24: - new_style = [style_name] - new_style += style_conf[16] - new_style += [None] - new_style += style_conf[24] - urwid_theme.append(tuple(new_style)) - # print(new_style) + fg = " ".join(fg_codes[1:]).replace("_", " ") + bg = " ".join(bg_codes[1:]).replace("_", " ") + new_style = (style_name, "", "", "", fg, bg) + urwid_theme.append(new_style) + print(new_style) return urwid_theme diff --git a/zulipterminal/scripts/theme_reorg.py b/zulipterminal/scripts/theme_reorg.py index 6e13c33fbd..5fe8bc57a4 100644 --- a/zulipterminal/scripts/theme_reorg.py +++ b/zulipterminal/scripts/theme_reorg.py @@ -1,21 +1,23 @@ +from zulipterminal.config.themes import gruvbox24, gruvbox256 + + def theme_reorg(): theme_f = open("zulipterminal/config/themes.py") lines = theme_f.readlines() with open("zulipterminal/config/gruvbox.py", "w") as f: - f.write("styles = {\n") - for i, style in enumerate(zip(lines[220:312], lines[316:408])): - style256, style24 = style - style256 = style256.split(sep=",") - style256 = [x.strip(" )(") for x in style256] - style24 = style24.split(sep=",") - style24 = [x.strip(" )(") for x in style24] + f.write("from enum import Enum\n\n") + f.write("class Color(Enum):\n") + for color256, color24 in zip(gruvbox256, gruvbox24): + if not color256.name.endswith("BOLD"): + f.write(f"\t {color256.name} = '{color256.value} {color24.value}'\n") + f.write("\nSTYLES = {\n") + for i, style in enumerate(lines[225:317]): + style = style.split(sep=",") + style = [x.strip(" )(#") for x in style] if i % 2 == 0: - f.write("\t" + style256[0] + ": {\n") - f.write(f"\t\t16: [{style256[1]}, {style256[2]}],\n") + f.write("\t" + style[0]) else: - f.write(f"\t\t256: [{style256[1]}, {style256[2]}],\n") - f.write(f"\t\t24: [{style24[1]}, {style24[2]}],\n") - f.write("\t},\n") + f.write(f": (Color.{style[1]}, Color.{style[2]}),\n") f.write("}\n")