132
132
rl_escape_prompt ,
133
133
rl_get_point ,
134
134
rl_get_prompt ,
135
+ rl_in_search_mode ,
135
136
rl_set_prompt ,
136
137
rl_type ,
137
138
rl_warning ,
@@ -3295,6 +3296,12 @@ def _set_up_cmd2_readline(self) -> _SavedReadlineSettings:
3295
3296
"""
3296
3297
readline_settings = _SavedReadlineSettings ()
3297
3298
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
+
3298
3305
if self ._completion_supported ():
3299
3306
# Set up readline for our tab completion needs
3300
3307
if rl_type == RlType .GNU :
@@ -5309,17 +5316,20 @@ def async_alert(self, alert_msg: str, new_prompt: Optional[str] = None) -> None:
5309
5316
if new_prompt is not None :
5310
5317
self .prompt = new_prompt
5311
5318
5312
- # Check if the prompt to display has changed from what's currently displayed
5313
5319
cur_onscreen_prompt = rl_get_prompt ()
5314
- new_onscreen_prompt = self .continuation_prompt if self ._at_continuation_prompt else self .prompt
5315
5320
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 )
5318
5328
5319
5329
if update_terminal :
5320
5330
import shutil
5321
5331
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
5323
5333
terminal_str = ansi .async_alert_str (
5324
5334
terminal_columns = shutil .get_terminal_size ().columns ,
5325
5335
prompt = cur_onscreen_prompt ,
@@ -5333,9 +5343,6 @@ def async_alert(self, alert_msg: str, new_prompt: Optional[str] = None) -> None:
5333
5343
elif rl_type == RlType .PYREADLINE :
5334
5344
readline .rl .mode .console .write (terminal_str )
5335
5345
5336
- # Update Readline's prompt before we redraw it
5337
- rl_set_prompt (new_onscreen_prompt )
5338
-
5339
5346
# Redraw the prompt and input lines below the alert
5340
5347
rl_force_redisplay ()
5341
5348
0 commit comments