summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Lin <anselor@gmail.com>2018-04-17 00:02:14 -0400
committerEric Lin <anselor@gmail.com>2018-04-17 00:02:14 -0400
commitdac2680f8433b94fb24fcfad635a096fd23386e9 (patch)
treec9dee4a250284ce33ef667140776f17c1e5ee20d
parent07c283eb484c9f2513f23594b364ad331b2b0e81 (diff)
downloadcmd2-git-dac2680f8433b94fb24fcfad635a096fd23386e9.tar.gz
Created a common prompt reprint implementation for all supported platforms.
-rwxr-xr-xAutoCompleter.py6
-rwxr-xr-xcmd2.py7
2 files changed, 11 insertions, 2 deletions
diff --git a/AutoCompleter.py b/AutoCompleter.py
index 83228b3b..671195c9 100755
--- a/AutoCompleter.py
+++ b/AutoCompleter.py
@@ -488,8 +488,10 @@ class AutoCompleter(object):
out_str += '\n{0: <{width}}'.format('', width=pref_len).join(help_lines)
print('\nHint:' + out_str + '\n')
- from cmd2 import readline_lib
- readline_lib.rl_forced_update_display()
+ # Moving this import here improves the performance when using AutoCompleter in a
+ # bash completion function. Loading cmd2 results in a lag of about half a second to a second.
+ from cmd2 import reprint_prompt
+ reprint_prompt()
# noinspection PyUnusedLocal
@staticmethod
diff --git a/cmd2.py b/cmd2.py
index 54eff811..6a2449a5 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -392,6 +392,13 @@ def write_to_paste_buffer(txt):
pyperclip.copy(txt)
+def reprint_prompt():
+ if rl_type == RlType.GNU:
+ readline_lib.rl_forced_update_display()
+ elif rl_type == RlType.PYREADLINE:
+ readline.rl.mode._print_prompt()
+
+
class ParsedString(str):
"""Subclass of str which also stores a pyparsing.ParseResults object containing structured parse results."""
# pyarsing.ParseResults - structured parse results, to provide multiple means of access to the parsed data