diff options
author | Frederick Yin <fkfd@macaw.me> | 2020-06-20 19:03:52 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@macaw.me> | 2020-06-20 19:03:52 +0800 |
commit | 5d8be65e92141c86b960692bfb4a68610f6f1a59 (patch) | |
tree | 07ab1f1953315e7585a2846090c4a85da915bfe2 /git-gmi | |
parent | c6d86838dcd22296278b249d995b0b38632a82bf (diff) |
Show path in tree view
Diffstat (limited to 'git-gmi')
-rw-r--r-- | git-gmi/git.py | 15 |
1 files changed, 10 insertions, 5 deletions
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" |