From 5d8be65e92141c86b960692bfb4a68610f6f1a59 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Sat, 20 Jun 2020 19:03:52 +0800 Subject: Show path in tree view --- git-gmi/git.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'git-gmi/git.py') diff --git a/git-gmi/git.py b/git-gmi/git.py index 9721a6f..034c2b2 100644 --- a/git-gmi/git.py +++ b/git-gmi/git.py @@ -111,8 +111,7 @@ class GitGmiRepo: refs = self.get_refs() for ref in refs: response += ( - f"## {ref['shorthand']}\n" - f"=> tree/{ref['shorthand']}/ view tree\n\n" + f"## {ref['shorthand']}\n=> tree/{ref['shorthand']}/ view tree\n\n" ) return response @@ -169,7 +168,7 @@ class GitGmiRepo: { "type": "dir", "name": item[0], - "size": len(item[1]), # number of objects in dir + "items": len(item[1]), # number of objects in dir } ) @@ -188,13 +187,19 @@ class GitGmiRepo: def view_tree(self, branch: str, location=[]) -> str: # actual Gemini response # consists of a header and a body - response = f"{STATUS_SUCCESS} {META_GEMINI}\n" + self.generate_header() tree = self.get_tree(branch) contents = self.list_tree(tree, location) + items = len(contents) + response = ( + f"{STATUS_SUCCESS} {META_GEMINI}\n" + + self.generate_header() + + f"## {self.name}{'/' if location else ''}{'/'.join(location)}/" + f" | {items} {'items' if items > 1 else 'item'}\n\n" + ) for item in contents: if item["type"] == "dir": response += ( - f"=> {item['name']}/ {item['name']}/ | {item['size']} items\n" + f"=> {item['name']}/ {item['name']}/ | {item['items']} items\n" ) elif item["type"] == "file": response += f"=> {item['name']} {item['name']} | {convert_filesize(item['size'])}\n" -- cgit v1.2.3