Skip to content

Commit c0942f1

Browse files
authored
Merge pull request #879 from python-cmd2/prompt_docs
Updated Sphinx documentation related to prompt
2 parents cf23131 + a3ff5a5 commit c0942f1

File tree

3 files changed

+51
-20
lines changed

3 files changed

+51
-20
lines changed

docs/api/cmd.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,26 @@ cmd2.Cmd
66

77
.. automethod:: __init__
88

9+
.. attribute:: continuation_prompt
10+
11+
Use as prompt for multiline commands on the 2nd+ line of input.
12+
Default: ``>``.
13+
14+
.. attribute:: default_error
15+
16+
The error message displayed when a non-existent command is run.
17+
Default: ``{} is not a recognized command, alias, or macro``
18+
919
.. attribute:: help_error
1020

1121
The error message displayed to the user when they request help for a
1222
command with no help defined.
23+
Default: ``No help on {}``
1324

14-
.. attribute:: default_error
25+
.. attribute:: prompt
1526

16-
The error message displayed when a non-existent command is run.
27+
The prompt issued to solicit input.
28+
Default: ``(Cmd)``.
1729

1830
.. attribute:: settable
1931

docs/features/multiline_commands.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Continuation prompt
1717
When a user types a :ref:`Multiline Command
1818
<features/multiline_commands:Multiline Commands>` it may span more than one
1919
line of input. The prompt for the first line of input is specified by the
20-
``cmd2.Cmd.prompt`` instance attribute - see
20+
:attr:`cmd2.Cmd.prompt` instance attribute - see
2121
:ref:`features/prompt:Customizing the Prompt`. The prompt for subsequent lines
22-
of input is defined by the ``cmd2.Cmd.continuation_prompt`` attribute.
22+
of input is defined by the :attr:`cmd2.Cmd.continuation_prompt` attribute.
2323

2424
Use cases
2525
---------

docs/features/prompt.rst

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
11
Prompt
22
======
33

4-
``cmd2`` can issue a prompt before soliciting user input.
4+
``cmd2`` issues a configurable prompt before soliciting user input.
55

66
Customizing the Prompt
77
----------------------
88

9-
This prompt can be configured by setting the `cmd2.Cmd.prompt` instance
9+
This prompt can be configured by setting the :attr:`cmd2.Cmd.prompt` instance
1010
attribute. This contains the string which should be printed as a prompt
11-
for user input.
11+
for user input. See the Pirate_ example for the simple use case of statically
12+
setting the prompt.
13+
14+
.. _Pirate: https://github.com/python-cmd2/cmd2/blob/master/examples/pirate.py#L33
15+
16+
Continuation Prompt
17+
-------------------
18+
19+
When a user types a
20+
:ref:`Multiline Command <features/multiline_commands:Multiline Commands>`
21+
it may span more than one line of input. The prompt for the first line of input
22+
is specified by the :attr:`cmd2.Cmd.prompt` instance attribute. The prompt for
23+
subsequent lines of input is defined by the
24+
:attr:`cmd2.Cmd.continuation_prompt` attribute.See the Initialization_ example
25+
for a demonstration of customizing the continuation prompt.
26+
27+
.. _Initialization: https://github.com/python-cmd2/cmd2/blob/master/examples/initialization.py#L33
28+
29+
Updating the prompt
30+
-------------------
31+
32+
If you wish to update the prompt between commands, you can do so using one of
33+
the :ref:`Application Lifecycle Hooks <features/hooks:Hooks>` such as a
34+
:ref:`Postcommand hook <features/hooks:Postcommand Hooks>`. See
35+
PythonScripting_ for an example of dynamically updating the prompt.
36+
37+
.. _PythonScripting: https://github.com/python-cmd2/cmd2/blob/master/examples/python_scripting.py#L34-L48
1238

1339
Asynchronous Feedback
1440
---------------------
@@ -20,26 +46,19 @@ functionality, the application must be running in a terminal that supports
2046
VT100 control characters and readline. Linux, Mac, and Windows 10 and greater
2147
all support these.
2248

23-
async_alert()
24-
Used to display an important message to the user while they are at the
25-
prompt in between commands. To the user it appears as if an alert message
26-
is printed above the prompt and their current input text and cursor
27-
location is left alone.
49+
.. automethod:: cmd2.Cmd.async_alert
50+
:noindex:
2851

29-
async_update_prompt()
30-
Updates the prompt while the user is still typing at it. This is good for
31-
alerting the user to system changes dynamically in between commands. For
32-
instance you could alter the color of the prompt to indicate a system
33-
status or increase a counter to report an event.
52+
.. automethod:: cmd2.Cmd.async_update_prompt
53+
:noindex:
3454

3555
``cmd2`` also provides a function to change the title of the terminal window.
3656
This feature requires the application be running in a terminal that supports
3757
VT100 control characters. Linux, Mac, and Windows 10 and greater all support
3858
these.
3959

40-
set_window_title()
41-
Sets the terminal window title
42-
60+
.. automethod:: cmd2.Cmd.set_window_title
61+
:noindex:
4362

4463
The easiest way to understand these functions is to see the AsyncPrinting_
4564
example for a demonstration.

0 commit comments

Comments
 (0)