From: Dustin Walde Date: Sat, 23 Sep 2023 03:56:37 +0000 (-0700) Subject: Use colored bullets on list X-Git-Url: https://git.walde.dev/?a=commitdiff_plain;h=aef0760598fb2411b0c783e3ec8abb8bf92e774b;p=punch Use colored bullets on list --- diff --git a/src/punch.py b/src/punch.py index e19558f..ada20ae 100644 --- a/src/punch.py +++ b/src/punch.py @@ -25,6 +25,18 @@ logging.getLogger().addHandler(logging.StreamHandler(sys.stdout)) logger = logging.getLogger(__name__) +def col_str_tuple(col): + if len(col) == 4: + return (int(col[1]*2, 16), + int(col[2]*2, 16), + int(col[3]*2, 16)) + elif len(col) == 7: + return (int(col[1:3], 16), + int(col[3:5], 16), + int(col[5:], 16)) + else: + return (0,0,0) + def print_usage(command: Optional[str] = None): if command is None: print("Punch usage:") @@ -66,14 +78,16 @@ def list_all(puncher: Puncher) -> None: category, depth = stack.pop() if depth >= 0: print("\t"*depth, end='') + col = col_str_tuple(category.color) + col_str = f'\033[38;2;{col[0]};{col[1]};{col[2]}m●\033[39m' if category.is_group: - print('> ' + category.name) + print(f'{col_str} ' + category.name) else: last_entry = puncher.get_last_entry(category.abbr) if last_entry is None or last_entry.is_complete: - print('| ' + category.abbr + "\t" + category.name) + print(f'{col_str} ' + category.abbr + "\t" + category.name) else: - print('| ' + category.abbr + "\t" + category.name + print(f'{col_str} ' + category.abbr + "\t" + category.name + f"\t punched in at {last_entry.t_in}") if category.children is not None: for child in reversed(category.children):