Loading cccli/cli.py +4 −8 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ class Cli(object): self.printer.history.maxsize(self.settings.get("hsize", None)) self.printer.debug("Loaded history: %s"%len(self.printer.history)) # enable completion self.printer.completion.set_completer(self._completer) self.printer.completion.set_completer(self._command_completer) # set prompt # load alias self.alias.load(self.settings.get("alias", "")) Loading Loading @@ -155,17 +155,13 @@ class Cli(object): self.printer.error("%s: %s"%(type(e), str(e))) self.printer.warn("This is a not expected error, please report it!") def _completer(self, texte, state): def _command_completer(self, texte): '''Return the list of completion''' comp = self.printer.completion stripped = comp.get_buf()[:comp.get_begin() + 1].lstrip() if state == 0 and texte == "" and stripped != "": if texte == "" and stripped != "": return None cl = [ c for c in Command.list() if c.startswith(texte) ] if state < len(cl): return cl[state] return None return [ c for c in Command.list() if c.startswith(texte) ] class CliHandler(RpcHandler): '''Handle RPC incoming request''' Loading cccli/printer.py +16 −2 Original line number Diff line number Diff line Loading @@ -220,6 +220,8 @@ class Completion(object): '''Handle completion functions''' def __init__(self): self.readline = None self.compfunc = None self.complist = list() def __getattribute__(self, name): r = object.__getattribute__(self, "readline") Loading @@ -241,7 +243,19 @@ class Completion(object): '''Get the ending index of the readline tab-completion scope''' return self.readline.get_begidx() def _completer(self, text, state): '''Readline real completer''' if state == 0: if self.compfunc is not None: self.complist = list(self.compfunc(text)) try: return self.complist[state] except IndexError: self.complist = list() return None def set_completer(self, func): '''Set completer function''' self.readline.set_completer(func) '''Set completer custom function which return a list of possibilities''' self.compfunc = func self.readline.set_completer(self._completer) self.readline.parse_and_bind("tab: complete") Loading
cccli/cli.py +4 −8 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ class Cli(object): self.printer.history.maxsize(self.settings.get("hsize", None)) self.printer.debug("Loaded history: %s"%len(self.printer.history)) # enable completion self.printer.completion.set_completer(self._completer) self.printer.completion.set_completer(self._command_completer) # set prompt # load alias self.alias.load(self.settings.get("alias", "")) Loading Loading @@ -155,17 +155,13 @@ class Cli(object): self.printer.error("%s: %s"%(type(e), str(e))) self.printer.warn("This is a not expected error, please report it!") def _completer(self, texte, state): def _command_completer(self, texte): '''Return the list of completion''' comp = self.printer.completion stripped = comp.get_buf()[:comp.get_begin() + 1].lstrip() if state == 0 and texte == "" and stripped != "": if texte == "" and stripped != "": return None cl = [ c for c in Command.list() if c.startswith(texte) ] if state < len(cl): return cl[state] return None return [ c for c in Command.list() if c.startswith(texte) ] class CliHandler(RpcHandler): '''Handle RPC incoming request''' Loading
cccli/printer.py +16 −2 Original line number Diff line number Diff line Loading @@ -220,6 +220,8 @@ class Completion(object): '''Handle completion functions''' def __init__(self): self.readline = None self.compfunc = None self.complist = list() def __getattribute__(self, name): r = object.__getattribute__(self, "readline") Loading @@ -241,7 +243,19 @@ class Completion(object): '''Get the ending index of the readline tab-completion scope''' return self.readline.get_begidx() def _completer(self, text, state): '''Readline real completer''' if state == 0: if self.compfunc is not None: self.complist = list(self.compfunc(text)) try: return self.complist[state] except IndexError: self.complist = list() return None def set_completer(self, func): '''Set completer function''' self.readline.set_completer(func) '''Set completer custom function which return a list of possibilities''' self.compfunc = func self.readline.set_completer(self._completer) self.readline.parse_and_bind("tab: complete")