132132 rl_escape_prompt ,
133133 rl_get_point ,
134134 rl_get_prompt ,
135+ rl_in_search_mode ,
135136 rl_set_prompt ,
136137 rl_type ,
137138 rl_warning ,
@@ -3295,6 +3296,12 @@ def _set_up_cmd2_readline(self) -> _SavedReadlineSettings:
32953296 """
32963297 readline_settings = _SavedReadlineSettings ()
32973298
3299+ if rl_type == RlType .GNU :
3300+ # To calculate line count when printing async_alerts, we rely on commands wider than
3301+ # the terminal to wrap across multiple lines. The default for horizontal-scroll-mode
3302+ # is "off" but a user may have overridden it in their readline initialization file.
3303+ readline .parse_and_bind ("set horizontal-scroll-mode off" )
3304+
32983305 if self ._completion_supported ():
32993306 # Set up readline for our tab completion needs
33003307 if rl_type == RlType .GNU :
@@ -5309,17 +5316,20 @@ def async_alert(self, alert_msg: str, new_prompt: Optional[str] = None) -> None:
53095316 if new_prompt is not None :
53105317 self .prompt = new_prompt
53115318
5312- # Check if the prompt to display has changed from what's currently displayed
53135319 cur_onscreen_prompt = rl_get_prompt ()
5314- new_onscreen_prompt = self .continuation_prompt if self ._at_continuation_prompt else self .prompt
53155320
5316- if new_onscreen_prompt != cur_onscreen_prompt :
5317- update_terminal = True
5321+ # We won't change the onscreen prompt while readline is in search mode (e.g. Ctrl-r)
5322+ if not rl_in_search_mode ():
5323+ # Check if the prompt to display has changed from what's currently displayed
5324+ new_onscreen_prompt = self .continuation_prompt if self ._at_continuation_prompt else self .prompt
5325+ if new_onscreen_prompt != cur_onscreen_prompt :
5326+ update_terminal = True
5327+ rl_set_prompt (new_onscreen_prompt )
53185328
53195329 if update_terminal :
53205330 import shutil
53215331
5322- # Generate the string which will replace the current prompt and input lines with the alert
5332+ # Print a string which replaces the current prompt and input lines with the alert
53235333 terminal_str = ansi .async_alert_str (
53245334 terminal_columns = shutil .get_terminal_size ().columns ,
53255335 prompt = cur_onscreen_prompt ,
@@ -5333,9 +5343,6 @@ def async_alert(self, alert_msg: str, new_prompt: Optional[str] = None) -> None:
53335343 elif rl_type == RlType .PYREADLINE :
53345344 readline .rl .mode .console .write (terminal_str )
53355345
5336- # Update Readline's prompt before we redraw it
5337- rl_set_prompt (new_onscreen_prompt )
5338-
53395346 # Redraw the prompt and input lines below the alert
53405347 rl_force_redisplay ()
53415348
0 commit comments