diff options
author | Martin Braun <martin.braun@ettus.com> | 2018-02-03 16:58:15 +0100 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2018-02-03 16:58:43 +0100 |
commit | db7e26bc73fd71bc88249131f57f7edef308fa63 (patch) | |
tree | d084ad2615012d53c50a230821761349eb978d56 /gr-utils/python/modtool/util_functions.py | |
parent | 3c63f7334d6de70d655aa97fcccbfb950645f4d4 (diff) | |
parent | a35e10870bbb9a71b3ab66b1dc58135e08c9543e (diff) |
Merge branch 'master' into next
Diffstat (limited to 'gr-utils/python/modtool/util_functions.py')
-rw-r--r-- | gr-utils/python/modtool/util_functions.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gr-utils/python/modtool/util_functions.py b/gr-utils/python/modtool/util_functions.py index de7f3d29b6..59f8984ca3 100644 --- a/gr-utils/python/modtool/util_functions.py +++ b/gr-utils/python/modtool/util_functions.py @@ -22,6 +22,7 @@ import re import sys +import readline # None of these must depend on other modtool stuff! @@ -135,3 +136,29 @@ def ask_yes_no(question, default): return default else: return not default + +class SequenceCompleter(object): + """ A simple completer function wrapper to be used with readline, e.g. + option_iterable = ("search", "seek", "destroy") + readline.set_completer(SequenceCompleter(option_iterable).completefunc) + """ + + def __init__(self, sequence): + self._seq = sequence + self._tmp_matches = [] + + def completefunc(self, text, state): + if not text and state < len(self._seq): + return self._seq[state] + if not state: + self._tmp_matches = filter(lambda candidate: candidate.startswith(text), self._seq) + if state < len(self._tmp_matches): + return self._tmp_matches[state] + + def __enter__(self): + self._old_completer = readline.get_completer() + readline.set_completer(self.completefunc) + readline.parse_and_bind("tab: complete") + + def __exit__(self): + readline.set_completer(self._old_completer) |