@@ -298,8 +298,8 @@ class AsyncAlert:
298298 :param prompt: an optional string to dynamically replace the current prompt.
299299
300300 :ivar timestamp: monotonic creation time of the alert. If an alert was created
301- before the current prompt was rendered, the prompt update is ignored
302- to avoid a stale display but the msg will still be displayed.
301+ before the current prompt was rendered, its prompt data is ignored
302+ to avoid a stale display, but its msg data will still be displayed.
303303 """
304304
305305 msg : str | None = None
@@ -2634,7 +2634,11 @@ def _raise_keyboard_interrupt(self) -> None:
26342634 raise KeyboardInterrupt ("Got a keyboard interrupt" )
26352635
26362636 def pre_prompt (self ) -> None :
2637- """Ran just before the prompt is displayed (and after the event loop has started)."""
2637+ """Ran just before the prompt is displayed (and after the event loop has started).
2638+
2639+ This is the ideal location to update `self.prompt` or any other state that should
2640+ be current when the prompt appears.
2641+ """
26382642
26392643 def precmd (self , statement : Statement | str ) -> Statement :
26402644 """Ran just before the command is executed by [cmd2.Cmd.onecmd][] and after adding it to history (cmd Hook method).
@@ -3475,10 +3479,10 @@ def get_prompt() -> str | ANSI:
34753479
34763480 def _pre_prompt () -> None :
34773481 """Run standard pre-prompt processing and activate the background alerter."""
3478- self .pre_prompt ()
3479-
3480- # Record when this prompt was rendered.
3482+ # Record prompt start time so any async prompt updates queued during
3483+ # pre_prompt() are considered current.
34813484 self ._alert_prompt_timestamp = time .monotonic ()
3485+ self .pre_prompt ()
34823486
34833487 # Start alerter thread if it's not already running.
34843488 if self ._alert_thread is None or not self ._alert_thread .is_alive ():
0 commit comments