@@ -26,16 +26,17 @@ complex output.
2626
2727## Ordinary Output
2828
29- The ` cmd2.Cmd.poutput ` method is similar to the Python
30- [ built-in print function ] ( https://docs.python.org/3/library/functions.html#print ) .
31- ` cmd2.Cmd.poutput ` adds two conveniences:
29+ The [ poutput ] [ cmd2.Cmd.poutput ] method is similar to the Python built-in
30+ [ print] ( https://docs.python.org/3/library/functions.html#print ) function. ` poutput ` adds a few
31+ conveniences:
3232
33331 . Since users can pipe output to a shell command, it catches ` BrokenPipeError ` and outputs the
3434 contents of ` self.broken_pipe_warning ` to ` stderr ` . ` self.broken_pipe_warning ` defaults to an
3535 empty string so this method will just swallow the exception. If you want to show an error
3636 message, put it in ` self.broken_pipe_warning ` when you initialize ` cmd2.Cmd ` .
37372 . It examines and honors the [ allow_style] ( ./settings.md#allow_style ) setting. See
3838 [ Colored Output] ( #colored-output ) below for more details.
39+ 3 . It allows printing arbitrary ` rich ` renderable objects which can get visually quite complex.
3940
4041Here's a simple command that shows this method in action:
4142
@@ -48,20 +49,22 @@ def do_echo(self, args):
4849## Error Messages
4950
5051When an error occurs in your program, you can display it on ` sys.stderr ` by calling the
51- ` .cmd2.Cmd.perror ` method. By default this method applies ` Cmd2Style.ERROR ` to the output.
52+ [ perror] [ cmd2.Cmd.perror ] method. By default this method applies
53+ [ Cmd2Style.ERROR] [ cmd2.Cmd2Style.ERROR ] to the output.
5254
5355## Warning Messages
5456
55- ` cmd2.Cmd.pwarning ` is just like ` cmd2.Cmd.perror ` but applies ` Cmd2Style.WARNING ` to the output.
57+ [ pwarning] [ cmd2.Cmd.pwarning ] is just like ` cmd2.Cmd.perror ` but applies ` Cmd2Style.WARNING ` to the
58+ output.
5659
5760## Feedback
5861
5962You may have the need to display information to the user which is not intended to be part of the
6063generated output. This could be debugging information or status information about the progress of
6164long running commands. It's not output, it's not error messages, it's feedback. If you use the
6265[ Timing] ( ./settings.md#timing ) setting, the output of how long it took the command to run will be
63- output as feedback. You can use the ` cmd2.Cmd.pfeedback ` method to produce this type of output, and
64- several [ Settings] ( ./settings.md ) control how it is handled.
66+ output as feedback. You can use the [ pfeedback ] [ cmd2.Cmd.pfeedback ] method to produce this type of
67+ output, and several [ Settings] ( ./settings.md ) control how it is handled.
6568
6669If the [ quiet] ( ./settings.md#quiet ) setting is ` True ` , then calling ` cmd2.Cmd.pfeedback ` produces no
6770output. If [ quiet] ( ./settings.md#quiet ) is ` False ` , the
@@ -71,17 +74,19 @@ send the output to `stdout` or `stderr`.
7174## Exceptions
7275
7376If your app catches an exception and you would like to display the exception to the user, the
74- ` cmd2.Cmd.pexcept ` method can help. The default behavior is to just display the message contained
75- within the exception. However, if the [ debug] ( ./settings.md#debug ) setting is ` True ` , then the
76- entire stack trace will be displayed.
77+ [ pexcept ] [ cmd2.Cmd.pexcept ] method can help. The default behavior is to just display the message
78+ contained within the exception. However, if the [ debug] ( ./settings.md#debug ) setting is ` True ` , then
79+ the entire stack trace will be displayed.
7780
7881## Paging Output
7982
8083If you know you are going to generate a lot of output, you may want to display it in a way that the
8184user can scroll forwards and backwards through it. If you pass all of the output to be displayed in
82- a single call to ` .cmd2.Cmd.ppaged ` , it will be piped to an operating system appropriate shell
83- command to page the output. On Windows, the output is piped to ` more ` ; on Unix-like operating
84- systems like MacOS and Linux, it is piped to ` less ` .
85+ a single call to [ ppaged] [ cmd2.Cmd.ppaged ] , it will be piped to an operating system appropriate
86+ shell command to page the output. On Windows, the output is piped to
87+ [ more] ( https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/more ) ; on
88+ Unix-like operating systems like MacOS and Linux, it is piped to
89+ [ less] ( https://man7.org/linux/man-pages/man1/less.1.html ) .
8590
8691## Colored Output
8792
@@ -102,20 +107,21 @@ all colors available to your `cmd2` application.
102107
103108### Custom Themes
104109
105- ` cmd2 ` uses a ` rich ` ` Theme ` object to define styles for various UI elements. You can define your
106- own custom theme using ` cmd2.rich_utils.set_theme ` . See the
110+ ` cmd2 ` uses a ` rich ` [ Theme] ( https://rich.readthedocs.io/en/stable/reference/theme.html ) object to
111+ define styles for various UI elements. You can define your own custom theme using
112+ [ cmd2.rich_utils.set_theme] [ ] . See the
107113[ rich_theme.py] ( https://github.com/python-cmd2/cmd2/blob/main/examples/rich_theme.py ) example for
108114more information.
109115
110116After adding the desired escape sequences to your output, you should use one of these methods to
111117present the output to the user:
112118
113- - ` cmd2.Cmd.poutput `
114- - ` cmd2.Cmd.perror `
115- - ` cmd2.Cmd.pwarning `
116- - ` cmd2.Cmd.pexcept `
117- - ` cmd2.Cmd.pfeedback `
118- - ` cmd2.Cmd.ppaged `
119+ - [ cmd2.Cmd.poutput] [ ]
120+ - [ cmd2.Cmd.perror] [ ]
121+ - [ cmd2.Cmd.pwarning] [ ]
122+ - [ cmd2.Cmd.pexcept] [ ]
123+ - [ cmd2.Cmd.pfeedback] [ ]
124+ - [ cmd2.Cmd.ppaged] [ ]
119125
120126These methods all honor the [ allow_style] ( ./settings.md#allow_style ) setting, which users can modify
121127to control whether these escape codes are passed through to the terminal or not.
@@ -125,9 +131,9 @@ to control whether these escape codes are passed through to the terminal or not.
125131If you would like to generate output which is left, center, or right aligned within a specified
126132width or the terminal width, the following functions can help:
127133
128- - ` cmd2.string_utils.align_left `
129- - ` cmd2.string_utils.align_center `
130- - ` cmd2.string_utils.align_right `
134+ - [ cmd2.string_utils.align_left] [ ]
135+ - [ cmd2.string_utils.align_center] [ ]
136+ - [ cmd2.string_utils.align_right] [ ]
131137
132138These functions differ from Python's string justifying functions in that they support characters
133139with display widths greater than 1. Additionally, ANSI style sequences are safely ignored and do not
@@ -141,6 +147,6 @@ you can pad it appropriately with spaces. However, there are categories of Unico
141147occupy 2 cells, and other that occupy 0. To further complicate matters, you might have included ANSI
142148escape sequences in the output to generate colors on the terminal.
143149
144- The ` cmd2.string_utils.str_width ` function solves both of these problems. Pass it a string, and
150+ The [ cmd2.string_utils.str_width] [ ] function solves both of these problems. Pass it a string, and
145151regardless of which Unicode characters and ANSI text style escape sequences it contains, it will
146152tell you how many characters on the screen that string will consume when printed.
0 commit comments