Skip to content

Commit 64232fb

Browse files
committed
Updated docs.
1 parent 68f2910 commit 64232fb

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ prompt is displayed.
6969
displaying realtime status information while the prompt is displayed, see the
7070
`cmd2.Cmd2.get_bottom_toolbar` method that can be overridden as well as the updated
7171
`getting_started.py` example
72-
- Added `cmd2.Cmd._in_prompt` flag that is set to `True` when the prompt is displayed and the
73-
application is waiting for user input
7472
- New `cmd2.Cmd` methods
7573
- **get_bottom_toolbar**: populates bottom toolbar if `bottom_toolbar` is `True`
7674
- **get_rprompt**: override to populate right prompt

cmd2/cmd2.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ class AsyncAlert:
286286
"""Contents of an asynchonous alert which display while user is at prompt.
287287
288288
:param msg: an optional message to be printed above the prompt.
289-
:param prompt: an optional string to dynamically replace the current prompt.
289+
:param prompt: an optional string to dynamically replace the active prompt.
290+
291+
:ivar timestamp: monotonic creation time of the alert. If an alert was created
292+
before the active prompt started, the prompt update is ignored
293+
to avoid a stale display but the msg will still be displayed.
290294
"""
291295

292296
msg: str | None = None
@@ -3367,7 +3371,7 @@ def _process_alerts(self) -> None:
33673371
# Get the next alert while still holding the condition lock.
33683372
alert = self._alert_queue.get()
33693373

3370-
# Only apply prompt changes generated after the current prompt started.
3374+
# Only apply prompt changes generated after the active prompt started.
33713375
prompt_updated = False
33723376
if (alert.prompt is not None and
33733377
alert.prompt != self.prompt and
@@ -3376,7 +3380,7 @@ def _process_alerts(self) -> None:
33763380
prompt_updated = True
33773381

33783382
if alert.msg:
3379-
# Print the message above the current prompt.
3383+
# Print the message above the active prompt.
33803384
with patch_stdout():
33813385
print_formatted_text(pt_filter_style(alert.msg))
33823386

@@ -5313,7 +5317,7 @@ def add_alert(self, *, msg: str | None = None, prompt: str | None = None) -> Non
53135317
add_alert(msg="Done", prompt="> ") # Update both
53145318
53155319
:param msg: an optional message to be printed above the prompt.
5316-
:param prompt: an optional string to dynamically replace the current prompt.
5320+
:param prompt: an optional string to dynamically replace the active prompt.
53175321
53185322
"""
53195323
if msg is None and prompt is None:

docs/features/prompt.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,25 @@ for an example of dynamically updating the prompt.
2929
## Asynchronous Feedback
3030

3131
`cmd2` provides a function to deliver asynchronous feedback to the user without interfering with the
32-
command line. This means the feedback is provided to the user when they are still entering text at
33-
the prompt.
32+
command line. This allows feedback to be provided while the user is still entering text at the prompt.
3433

3534
- [cmd2.Cmd.add_alert][]
3635

37-
`cmd2` also provides a function to change the title of the terminal window. This feature requires
38-
the application be running in a terminal that supports VT100 control characters. Linux, Mac, and
39-
Windows 10 and greater all support these.
36+
### Asynchronous Feedback Mechanisms
37+
38+
Alerts can interact with the CLI in two ways:
39+
40+
1. **Message Printing**: It can print a message directly above the current prompt line.
41+
1. **Prompt Updates**: It can dynamically replace the text of the active prompt to reflect changing
42+
state.
43+
44+
> **Note**: To ensure the user interface remains accurate, a prompt update is ignored if the alert
45+
> was created before the active prompt started. This prevents older alerts from overwriting a newer
46+
> prompt, though the alert's message will still be printed.
47+
48+
### Terminal Window Management
49+
50+
`cmd2` also provides a function to change the title of the terminal window.
4051

4152
- [cmd2.Cmd.set_window_title][]
4253

0 commit comments

Comments
 (0)