summaryrefslogtreecommitdiff
path: root/cmd2/rl_utils.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-06-22 02:26:39 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-06-22 02:26:39 -0400
commita0d7df08b03719274b326b12a03979094e720098 (patch)
tree7309b7485ff808a585fb2adbc351228b8cbe57c3 /cmd2/rl_utils.py
parent52795b7071e13a505c9131084f0d80d1a2dfc1f6 (diff)
downloadcmd2-git-a0d7df08b03719274b326b12a03979094e720098.tar.gz
Corrected how we force a redisplay in pyreadline
Diffstat (limited to 'cmd2/rl_utils.py')
-rw-r--r--cmd2/rl_utils.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/cmd2/rl_utils.py b/cmd2/rl_utils.py
index 55ca4a12..7e49ea47 100644
--- a/cmd2/rl_utils.py
+++ b/cmd2/rl_utils.py
@@ -75,16 +75,17 @@ elif 'gnureadline' in sys.modules or 'readline' in sys.modules:
readline_lib = ctypes.CDLL(readline.__file__)
+# noinspection PyProtectedMember
def rl_force_redisplay() -> None:
"""
- Causes readline to redraw prompt and input line
+ Causes readline to display the prompt and input text wherever the cursor is and start
+ reading input from this location. This is the proper way to restore the input line after
+ printing to the screen
"""
if not sys.stdout.isatty():
return
if rl_type == RlType.GNU: # pragma: no cover
- # rl_forced_update_display() is the proper way to redraw the prompt and line, but we
- # have to use ctypes to do it since Python's readline API does not wrap the function
readline_lib.rl_forced_update_display()
# After manually updating the display, readline asks that rl_display_fixed be set to 1 for efficiency
@@ -92,5 +93,6 @@ def rl_force_redisplay() -> None:
display_fixed.value = 1
elif rl_type == RlType.PYREADLINE: # pragma: no cover
- # noinspection PyProtectedMember
+ # Call _print_prompt() first to set the new location of the prompt
readline.rl.mode._print_prompt()
+ readline.rl.mode._update_line()