Skip to content

Commit

Permalink
Use list instead of tuple in theme color codes
Browse files Browse the repository at this point in the history
Requiring a trailing comma is annoying.
  • Loading branch information
ymattw committed Nov 11, 2024
1 parent 41764d7 commit 4639b9b
Showing 1 changed file with 35 additions and 39 deletions.
74 changes: 35 additions & 39 deletions ydiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,42 @@ class Color(object):

THEMES = {
'default': {
# kind: (effects,)
'header': (Color.FG_CYAN,),
'old_path': (Color.FG_YELLOW,),
'new_path': (Color.FG_YELLOW,),
'hunk_header': (Color.FG_CYAN,),
'hunk_meta': (Color.FG_BLUE,),
'common_line': (Color.RESET,),
'old_line': (Color.FG_RED,),
'new_line': (Color.FG_GREEN,),
'deleted_text': (Color.REVERSE, Color.FG_RED,),
'inserted_text': (Color.REVERSE, Color.FG_GREEN,),
'replaced_old_text': (Color.REVERSE, Color.FG_RED,),
'replaced_new_text': (Color.REVERSE, Color.FG_GREEN,),
'old_line_number': (Color.FG_YELLOW,),
'new_line_number': (Color.FG_YELLOW,),
'file_separator': (Color.FG_BRIGHT_CYAN,),
'wrap_marker': (Color.FG_BRIGHT_MAGENTA,),
# kind: [effect...]
'header': [Color.FG_CYAN],
'old_path': [Color.FG_YELLOW],
'new_path': [Color.FG_YELLOW],
'hunk_header': [Color.FG_CYAN],
'hunk_meta': [Color.FG_BLUE],
'common_line': [Color.RESET],
'old_line': [Color.FG_RED],
'new_line': [Color.FG_GREEN],
'deleted_text': [Color.REVERSE, Color.FG_RED],
'inserted_text': [Color.REVERSE, Color.FG_GREEN],
'replaced_old_text': [Color.REVERSE, Color.FG_RED],
'replaced_new_text': [Color.REVERSE, Color.FG_GREEN],
'old_line_number': [Color.FG_YELLOW],
'new_line_number': [Color.FG_YELLOW],
'file_separator': [Color.FG_BRIGHT_CYAN],
'wrap_marker': [Color.FG_BRIGHT_MAGENTA],
},
'dark': {
# kind: (effects,)
'header': (Color.FG_CYAN,),
'old_path': (Color.BG8_DARK_RED,),
'new_path': (Color.BG8_DARK_GREEN,),
'hunk_header': (Color.FG_CYAN,),
'hunk_meta': (Color.FG_BLUE,),
'common_line': (Color.RESET,),
'old_line': (Color.BG8_DARK_RED,),
'new_line': (Color.BG8_DARK_GREEN,),
'deleted_text': (Color.BG8_RED,),
'inserted_text': (Color.FG8_GRAY, Color.BG8_GREEN,),
'replaced_old_text': (Color.BG8_RED,),
'replaced_new_text': (Color.FG8_GRAY, Color.BG8_GREEN,),
'old_line_number': (Color.FG_YELLOW,),
'new_line_number': (Color.FG_YELLOW,),
'file_separator': (Color.FG_BRIGHT_CYAN,),
'wrap_marker': (Color.FG_BRIGHT_MAGENTA,),
# kind: [effects...]
'header': [Color.FG_CYAN],
'old_path': [Color.BG8_DARK_RED],
'new_path': [Color.BG8_DARK_GREEN],
'hunk_header': [Color.FG_CYAN],
'hunk_meta': [Color.FG_BLUE],
'common_line': [Color.RESET],
'old_line': [Color.BG8_DARK_RED],
'new_line': [Color.BG8_DARK_GREEN],
'deleted_text': [Color.BG8_RED],
'inserted_text': [Color.FG8_GRAY, Color.BG8_GREEN],
'replaced_old_text': [Color.BG8_RED],
'replaced_new_text': [Color.FG8_GRAY, Color.BG8_GREEN],
'old_line_number': [Color.FG_YELLOW],
'new_line_number': [Color.FG_YELLOW],
'file_separator': [Color.FG_BRIGHT_CYAN],
'wrap_marker': [Color.FG_BRIGHT_MAGENTA],
},
}

Expand All @@ -114,10 +114,6 @@ def colorize(text, kind, theme='default'):
return base_color + text + Color.RESET


def theme_color_codes(theme):
return set(x for x in sum(THEMES[theme].values(), start=()) if x)


def strsplit(text, width, color_codes):
r"""Splits a string into two substrings, respecting involved color codes.
Expand Down Expand Up @@ -421,7 +417,7 @@ def __init__(self, side_by_side=False, width=0, tab_width=8, wrap=False,
self._tab_width = tab_width
self._wrap = wrap
self._theme = theme
self._codes = theme_color_codes(theme)
self._codes = set(sum(THEMES[theme].values(), start=[]))

def markup(self, diff):
"""Returns a generator"""
Expand Down

0 comments on commit 4639b9b

Please sign in to comment.