From 85cebf7af1712dfc8214564045d68317656cf03b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 25 Jan 2021 13:57:06 +0100 Subject: Merging upstream version 0.12.9. Signed-off-by: Daniel Baumann --- gita/info.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'gita/info.py') diff --git a/gita/info.py b/gita/info.py index 473127a..a8044e9 100644 --- a/gita/info.py +++ b/gita/info.py @@ -37,29 +37,36 @@ def show_colors(): # pragma: no cover """ """ + names = {c.value: c.name for c in Color} for i, c in enumerate(Color, start=1): if c != Color.end: print(f'{c.value}{c.name:<8} ', end='') if i % 9 == 0: print() print(f'{Color.end}') - for situation, c in get_color_encoding().items(): - print(f'{situation:<12}: {c.value}{c.name:<8}{Color.end} ') + for situation, c in sorted(get_color_encoding().items()): + print(f'{situation:<12}: {c}{names[c]:<8}{Color.end} ') @lru_cache() -def get_color_encoding(): +def get_color_encoding() -> Dict[str, str]: """ - + Return color scheme for different local/remote situations. """ - # TODO: add config file - return { - 'no-remote': Color.white, - 'in-sync': Color.green, - 'diverged': Color.red, - 'local-ahead': Color.purple, - 'remote-ahead': Color.yellow, + # custom settings + yml_config = Path(common.get_config_fname('color.yml')) + if yml_config.is_file(): + with open(yml_config, 'r') as stream: + colors = yaml.load(stream, Loader=yaml.FullLoader) + else: + colors = { + 'no-remote': Color.white.value, + 'in-sync': Color.green.value, + 'diverged': Color.red.value, + 'local-ahead': Color.purple.value, + 'remote-ahead': Color.yellow.value, } + return colors def get_info_funcs() -> List[Callable[[str], str]]: @@ -82,20 +89,20 @@ def get_info_items() -> List[str]: """ Return the information items to be displayed in the `gita ll` command. """ - # default settings - display_items = ['branch', 'commit_msg'] - # custom settings yml_config = Path(common.get_config_fname('info.yml')) if yml_config.is_file(): with open(yml_config, 'r') as stream: display_items = yaml.load(stream, Loader=yaml.FullLoader) display_items = [x for x in display_items if x in ALL_INFO_ITEMS] + else: + # default settings + display_items = ['branch', 'commit_msg'] return display_items def get_path(path): - return Color.cyan + path + Color.end + return f'{Color.cyan}{path}{Color.end}' def get_head(path: str) -> str: -- cgit v1.2.3