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 ccdce03
Showing 1 changed file with 58 additions and 39 deletions.
97 changes: 58 additions & 39 deletions ydiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,46 +48,69 @@ class Color(object):
BG8_RED = '\x1b[48;5;88m'
BG8_DARK_GREEN = '\x1b[48;5;22m'
BG8_GREEN = '\x1b[48;5;28m'
BG8_LIGHT_RED = '\x1b[48;5;217m'
BG8_DIMMED_RED = '\x1b[48;5;210m'
BG8_LIGHT_GREEN = '\x1b[48;5;194m'
BG8_DIMMED_GREEN = '\x1b[48;5;157m'


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: [effect...]
'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],
},
'light': {
# kind: [effect...]
'header': [Color.FG_CYAN],
'old_path': [Color.BG8_LIGHT_RED],
'new_path': [Color.BG8_LIGHT_GREEN],
'hunk_header': [Color.FG_CYAN],
'hunk_meta': [Color.FG_BLUE],
'common_line': [Color.RESET],
'old_line': [Color.BG8_LIGHT_RED],
'new_line': [Color.BG8_LIGHT_GREEN],
'deleted_text': [Color.BG8_DIMMED_RED],
'inserted_text': [Color.FG8_GRAY, Color.BG8_DIMMED_GREEN],
'replaced_old_text': [Color.BG8_DIMMED_RED],
'replaced_new_text': [Color.FG8_GRAY, Color.BG8_DIMMED_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 +137,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 +440,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 ccdce03

Please sign in to comment.