From 2108ddb34c701c15a2610bd295a0a1ab24cb024f Mon Sep 17 00:00:00 2001 From: Dong Zhou Date: Thu, 13 Jun 2024 11:54:28 -0400 Subject: [PATCH] add gita info set-length subcommand (#278) --- gita/__main__.py | 20 ++++++++++++++++++++ gita/info.py | 17 +++++++++++------ setup.py | 2 +- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/gita/__main__.py b/gita/__main__.py index 24d6bf8..6809f15 100644 --- a/gita/__main__.py +++ b/gita/__main__.py @@ -147,6 +147,21 @@ def f_info(args: argparse.Namespace): with open(csv_config, "w", newline="") as f: writer = csv.writer(f) writer.writerow(to_display) + elif cmd == "set-length": + csv_config = common.get_config_fname("layout.csv") + print(f"Settings are in {csv_config}") + defaults = { + "branch": 19, + "symbols": 5, + "branch_name": 27, + "commit_msg": 0, + "commit_time": 0, # 0 means no limit + "path": 30, + } + with open(csv_config, "w", newline="") as f: + writer = csv.DictWriter(f, fieldnames=defaults) + writer.writeheader() + writer.writerow(defaults) def f_clone(args: argparse.Namespace): @@ -616,6 +631,11 @@ def main(argv=None): info_cmds.add_parser("rm", description="Disable information item.").add_argument( "info_item", choices=info.ALL_INFO_ITEMS, help="information item to delete" ) + info_cmds.add_parser( + "set-length", + description="Set default column widths for information items. " + "The settings are in layout.csv", + ) ll_doc = f""" status symbols: +: staged changes diff --git a/gita/info.py b/gita/info.py index 875acf4..0a253a0 100644 --- a/gita/info.py +++ b/gita/info.py @@ -16,6 +16,7 @@ class Truncate: exist or the requested field doesn't exist then don't truncate """ + widths = {} def __init__(self): @@ -25,17 +26,21 @@ def __init__(self): reader = csv.DictReader(f) self.widths = next(reader) - #Ensure the Dict type is Dict[str, int] to reduce casting elsewhere - for e in self.widths: - self.widths[e] = int(self.widths[e]) + # Ensure the Dict type is Dict[str, int] to reduce casting elsewhere + for e, width in self.widths.items(): + self.widths[e] = int(width) def truncate(self, field: str, message: str): - if field not in self.widths: + # 0 means no width limit applied + if not self.widths.get(field): return message length = 3 if self.widths[field] < 3 else self.widths[field] - return message[:length-3] + '...' if len(message) > length else message.ljust(length) - + return ( + message[: length - 3] + "..." + if len(message) > length + else message.ljust(length) + ) class Color(Enum): diff --git a/setup.py b/setup.py index 6640d25..394d0c2 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name="gita", packages=["gita"], - version="0.16.7.1", + version="0.16.7.2", license="MIT", description="Manage multiple git repos with sanity", long_description=long_description,