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
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ While you could send output directly to `sys.stdout`, `cmd2.Cmd`{.interpreted-te
16
16
The `cmd2.Cmd.poutput` method is similar to the Python [built-in print function](https://docs.python.org/3/library/functions.html#print). `cmd2.Cmd.poutput` adds two conveniences:
17
17
18
18
1. Since users can pipe output to a shell command, it catches `BrokenPipeError` and outputs the contents of `self.broken_pipe_warning` to `stderr`. `self.broken_pipe_warning` defaults to an empty string so this method will just swallow the exception. If you want to show an error message, put it in `self.broken_pipe_warning` when you initialize `cmd2.Cmd`.
19
-
2. It examines and honors the [allow_style](./settings.md#allowstylestyle) setting. See [Colored Output](#colored-output) below for more details.
19
+
2. It examines and honors the [allow_style](./settings.md#allow_style) setting. See [Colored Output](#colored-output) below for more details.
20
20
21
21
Here's a simple command that shows this method in action:
22
22
@@ -38,7 +38,7 @@ When an error occurs in your program, you can display it on `sys.stderr` by call
38
38
39
39
You may have the need to display information to the user which is not intended to be part of the generated output. This could be debugging information or status information about the progress of long running commands. It's not output, it's not error messages, it's feedback. If you use the [Timing](./settings.md#timing) setting, the output of how long it took the command to run will be output as feedback. You can use the `cmd2.Cmd.pfeedback` method to produce this type of output, and several [Settings](./settings.md) control how it is handled.
40
40
41
-
If the [quiet](./settings.md#quiet) setting is `True`, then calling `cmd2.Cmd.pfeedback` produces no output. If [quiet](./settings.md#quiet) is `False`, the [feedback_to_output](./settings.md#feedbackto_outputto_output) setting is consulted to determine whether to send the output to `stdout` or `stderr`.
41
+
If the [quiet](./settings.md#quiet) setting is `True`, then calling `cmd2.Cmd.pfeedback` produces no output. If [quiet](./settings.md#quiet) is `False`, the [feedback_to_output](./settings.md#feedback_to_output) setting is consulted to determine whether to send the output to `stdout` or `stderr`.
42
42
43
43
## Exceptions
44
44
@@ -56,22 +56,22 @@ You can add your own [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_
56
56
57
57
After adding the desired escape sequences to your output, you should use one of these methods to present the output to the user:
58
58
59
-
-`cmd2.Cmd.poutput`
60
-
-`cmd2.Cmd.perror`
61
-
-`cmd2.Cmd.pwarning`
62
-
-`cmd2.Cmd.pexcept`
63
-
-`cmd2.Cmd.pfeedback`
64
-
-`cmd2.Cmd.ppaged`
59
+
-`cmd2.Cmd.poutput`
60
+
-`cmd2.Cmd.perror`
61
+
-`cmd2.Cmd.pwarning`
62
+
-`cmd2.Cmd.pexcept`
63
+
-`cmd2.Cmd.pfeedback`
64
+
-`cmd2.Cmd.ppaged`
65
65
66
-
These methods all honor the [allow_style](./settings.md#allowstylestyle) setting, which users can modify to control whether these escape codes are passed through to the terminal or not.
66
+
These methods all honor the [allow_style](./settings.md#allow_style) setting, which users can modify to control whether these escape codes are passed through to the terminal or not.
67
67
68
68
## Aligning Text
69
69
70
70
If you would like to generate output which is left, center, or right aligned within a specified width or the terminal width, the following functions can help:
71
71
72
-
-`cmd2.utils.align_left`
73
-
-`cmd2.utils.align_center`
74
-
-`cmd2.utils.align_right`
72
+
-`cmd2.utils.align_left`
73
+
-`cmd2.utils.align_center`
74
+
-`cmd2.utils.align_right`
75
75
76
76
These functions differ from Python's string justifying functions in that they support characters with display widths greater than 1. Additionally, ANSI style sequences are safely ignored and do not count toward the display width. This means colored text is supported. If text has line breaks, then each line is aligned independently.
0 commit comments