From 239ed97d7e87bf82d6968415c2881ecda1fd1f6a Mon Sep 17 00:00:00 2001 From: Sebastian Schildt Date: Thu, 26 Aug 2021 23:30:20 +0200 Subject: [PATCH] Enable autocompletion for / paths as well and improve description with node type Signed-off-by: Sebastian Schildt --- kuksa_viss_client/__main__.py | 42 ++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/kuksa_viss_client/__main__.py b/kuksa_viss_client/__main__.py index 1119d06b6..aeab55f65 100755 --- a/kuksa_viss_client/__main__.py +++ b/kuksa_viss_client/__main__.py @@ -28,14 +28,20 @@ class TestClient(Cmd): def get_childtree(self, pathText): childVssTree = self.vssTree - if "." in pathText: + + paths = [pathText] + if "/" in pathText: + paths = pathText.split("/") + elif "." in pathText: paths = pathText.split(".") - for path in paths[:-1]: - if path in childVssTree: - childVssTree = childVssTree[path] - elif 'children' in childVssTree and path in childVssTree['children']: - childVssTree = childVssTree['children'][path] - if 'children' in childVssTree: + + for path in paths[:-1]: + if path in childVssTree: + childVssTree = childVssTree[path] + elif 'children' in childVssTree and path in childVssTree['children']: + childVssTree = childVssTree['children'][path] + + if 'children' in childVssTree: childVssTree = childVssTree['children'] return childVssTree @@ -49,17 +55,31 @@ def path_completer(self, text, line, begidx, endidx): self.pathCompletionItems = [] childTree = self.get_childtree(text) prefix = "" - if "." in text: + seperator="/" + + if "/" in text: + prefix = text[:text.rfind("/")]+"/" + elif "." in text: prefix = text[:text.rfind(".")]+"." + seperator="." + for key in childTree: child = childTree[key] if isinstance(child, dict): description = "" + nodetype = "unknown" + if 'description' in child: - description = "("+child['description']+")" - self.pathCompletionItems.append(CompletionItem(prefix + key, description)) + description = child['description'] + + if 'type' in child: + nodetype=child['type'].capitalize() + + self.pathCompletionItems.append(CompletionItem(prefix + key, nodetype+": "+ description)) + if 'children' in child: - self.pathCompletionItems.append(CompletionItem(prefix + key + ".", "(children...)")) + self.pathCompletionItems.append(CompletionItem(prefix + key+seperator, "Children of branch "+prefix+key)) + return basic_complete(text, line, begidx, endidx, self.pathCompletionItems)