You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/features/generating_output.md
+29-3Lines changed: 29 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,10 +19,31 @@ output you generate must be sent to `self.stdout`. You can use the methods descr
19
19
everything will work fine. [cmd2.Cmd][] also includes a number of output related methods which you
20
20
may use to enhance the output your application produces.
21
21
22
-
Since `cmd2` has a dependency on the [rich](https://github.com/Textualize/rich) library, all of
23
-
`cmd2`'s output methods can natively render `rich`
22
+
Since `cmd2` has a dependency on the [rich](https://github.com/Textualize/rich) library, the
23
+
following [cmd2.Cmd][] output methods can natively render `rich`
24
24
[renderable objects](https://rich.readthedocs.io/en/latest/protocol.html), enabling beautiful and
25
-
complex output.
25
+
complex output:
26
+
27
+
-[poutput][cmd2.Cmd.poutput]
28
+
-[perror][cmd2.Cmd.perror]
29
+
-[psuccess][cmd2.Cmd.psuccess]
30
+
-[pwarning][cmd2.Cmd.pwarning]
31
+
-[pfeedback][cmd2.Cmd.pfeedback]
32
+
-[ppaged][cmd2.Cmd.ppaged]
33
+
34
+
!!! tip "Advanced output customization"
35
+
36
+
Each of the above methods accepts additional optional parameters that help control how the output is
37
+
formatted:
38
+
39
+
- `sep`: string to write between printed text. Defaults to " "
40
+
- `end`: string to write at end of printed text. Defaults to a newline
41
+
- `style`: optional style to apply to output
42
+
- `soft_wrap`: Enable soft wrap mode. If True, lines of text will not be word-wrapped or cropped to fit the terminal width. Defaults to True
43
+
- `emoji`: If True, Rich will replace emoji codes (e.g., 😃) with their corresponding Unicode characters. Defaults to False
44
+
- `markup`: If True, Rich will interpret strings with tags (e.g., [bold]hello[/bold]) as styled output. Defaults to False
45
+
- `highlight`: If True, Rich will automatically apply highlighting to elements within strings, such as common Python data types like numbers, booleans, or None.
46
+
- `rich_print_kwargs`: optional additional keyword arguments to pass to Rich's `Console.print()`
26
47
27
48
## Ordinary Output
28
49
@@ -140,6 +161,11 @@ with display widths greater than 1. Additionally, ANSI style sequences are safel
140
161
count toward the display width. This means colored text is supported. If text has line breaks, then
141
162
each line is aligned independently.
142
163
164
+
!!! tip "Advanced alignment customization"
165
+
166
+
You can also control output alignment using the `rich_print_kwargs.justify` member when calling
167
+
`cmd2`'s print methods.
168
+
143
169
## Columnar Output
144
170
145
171
When generating output in multiple columns, you often need to calculate the width of each item so
0 commit comments