Skip to content

Commit c7feaa6

Browse files
authored
Merge pull request #447 from python-cmd2/pyreadline
Corrected how we force a redisplay in pyreadline
2 parents 52795b7 + a0d7df0 commit c7feaa6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

cmd2/rl_utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,24 @@ def pyreadline_remove_history_item(pos: int) -> None:
7575
readline_lib = ctypes.CDLL(readline.__file__)
7676

7777

78+
# noinspection PyProtectedMember
7879
def rl_force_redisplay() -> None:
7980
"""
80-
Causes readline to redraw prompt and input line
81+
Causes readline to display the prompt and input text wherever the cursor is and start
82+
reading input from this location. This is the proper way to restore the input line after
83+
printing to the screen
8184
"""
8285
if not sys.stdout.isatty():
8386
return
8487

8588
if rl_type == RlType.GNU: # pragma: no cover
86-
# rl_forced_update_display() is the proper way to redraw the prompt and line, but we
87-
# have to use ctypes to do it since Python's readline API does not wrap the function
8889
readline_lib.rl_forced_update_display()
8990

9091
# After manually updating the display, readline asks that rl_display_fixed be set to 1 for efficiency
9192
display_fixed = ctypes.c_int.in_dll(readline_lib, "rl_display_fixed")
9293
display_fixed.value = 1
9394

9495
elif rl_type == RlType.PYREADLINE: # pragma: no cover
95-
# noinspection PyProtectedMember
96+
# Call _print_prompt() first to set the new location of the prompt
9697
readline.rl.mode._print_prompt()
98+
readline.rl.mode._update_line()

0 commit comments

Comments
 (0)