summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-06-06 19:15:58 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-06-06 19:15:58 -0400
commitadb62d8be6b89b0d8beb1e4866ef16e1026f3c10 (patch)
tree35f6659dda5d459136555bb177389860b45c45b7 /cmd2/cmd2.py
parentbe9ffc54823f29982a7815e5ce6c11ef359f1b0a (diff)
downloadcmd2-git-adb62d8be6b89b0d8beb1e4866ef16e1026f3c10.tar.gz
Added ability to print a header above tab-completion suggestions
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 387dbe9d..f12d4884 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -495,6 +495,9 @@ class Cmd(cmd.Cmd):
# will be added if there is an unmatched opening quote
self.allow_closing_quote = True
+ # An optional header that prints above the tab-completion suggestions
+ self.completion_header = ''
+
# If the tab-completion suggestions should be displayed in a way that is different than the actual match values,
# then place those results in this list. The full matches still must be returned from your completer function.
# For an example, look at path_complete() which uses this to show only the basename of paths as the
@@ -661,6 +664,7 @@ class Cmd(cmd.Cmd):
"""
self.allow_appended_space = True
self.allow_closing_quote = True
+ self.completion_header = ''
self.display_matches = []
self.matches_delimited = False
@@ -1254,6 +1258,10 @@ class Cmd(cmd.Cmd):
strings_array[1:-1] = encoded_matches
strings_array[-1] = None
+ # Print the header if one exists
+ if self.completion_header:
+ self.stdout.write('\n' + self.completion_header)
+
# Call readline's display function
# rl_display_match_list(strings_array, number of completion matches, longest match length)
readline_lib.rl_display_match_list(strings_array, len(encoded_matches), longest_match_length)
@@ -1279,6 +1287,10 @@ class Cmd(cmd.Cmd):
# Add padding for visual appeal
matches_to_display, _ = self._pad_matches_to_display(matches_to_display)
+ # Print the header if one exists
+ if self.completion_header:
+ readline.rl.mode.console.write('\n' + self.completion_header)
+
# Display matches using actual display function. This also redraws the prompt and line.
orig_pyreadline_display(matches_to_display)