From b7fa4e46593151086a4186c9d90dc72b809c9b45 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Tue, 2 Jul 2019 10:47:52 -0400 Subject: Moved basic_complete to utils --- cmd2/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'cmd2/utils.py') diff --git a/cmd2/utils.py b/cmd2/utils.py index 812fa227..3ba1be72 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -615,3 +615,19 @@ class RedirectionSavedState(object): # If the command created a process to pipe to, then then is its reader self.pipe_proc_reader = None + + +# noinspection PyUnusedLocal +def basic_complete(text: str, line: str, begidx: int, endidx: int, match_against: Iterable) -> List[str]: + """ + Basic tab completion function that matches against a list of strings without considering line contents + or cursor position. The args required by this function are defined in the header of Pythons's cmd.py. + + :param text: the string prefix we are attempting to match (all returned matches must begin with it) + :param line: the current input line with leading whitespace removed + :param begidx: the beginning index of the prefix text + :param endidx: the ending index of the prefix text + :param match_against: the strings being matched against + :return: a list of possible tab completions + """ + return [cur_match for cur_match in match_against if cur_match.startswith(text)] -- cgit v1.2.1