Skip to content

Commit af0d8c4

Browse files
committed
Eliminate feedback_to_output settable and have pfeedback always print to stdout
1 parent 46dd594 commit af0d8c4

7 files changed

Lines changed: 27 additions & 71 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ prompt is displayed.
108108
treated as command output and sent to `self.stdout`, allowing them to be captured.
109109
- Verbose help table descriptions are no longer generated from help function output. The system
110110
now relies exclusively on command function docstrings.
111+
- Removed `feedback_to_output` settable and changed `cmd2.Cmd.pfeedback` to always print to
112+
`self.stdout`
111113
- Enhancements
112114
- New `cmd2.Cmd` parameters
113115
- **auto_suggest**: (boolean) if `True`, provide fish shell style auto-suggestions. These
@@ -166,6 +168,8 @@ prompt is displayed.
166168
- Updated `set` command to consolidate its confirmation output into a single, colorized line.
167169
The confirmation now uses `pfeedback()`, allowing it to be silenced when the `quiet` settable
168170
is enabled.
171+
- `alias` and `macro` subcommands for `create` and `delete` now output their non-essential
172+
success case output using `pfeedback`
169173

170174
## 3.5.1 (April 24, 2026)
171175

cmd2/cmd2.py

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ def __init__(
474474
self.debug = False
475475
self.echo = False
476476
self.editor = self.DEFAULT_EDITOR
477-
self.feedback_to_output = False # Do not include nonessentials in >, | output by default (things like timing)
478477
self.quiet = False # Do not suppress nonessential output
479478
self.scripts_add_to_history = True # Scripts and pyscripts add commands to history
480479
self.timing = False # Prints elapsed time for each command
@@ -1370,7 +1369,6 @@ def allow_style_type(value: str) -> ru.AllowStyle:
13701369
self.add_settable(Settable("debug", bool, "Show full traceback on exception", self))
13711370
self.add_settable(Settable("echo", bool, "Echo command issued into output", self))
13721371
self.add_settable(Settable("editor", str, "Program used by 'edit'", self))
1373-
self.add_settable(Settable("feedback_to_output", bool, "Include nonessentials in '|' and '>' results", self))
13741372
self.add_settable(
13751373
Settable(
13761374
"max_completion_table_items",
@@ -1754,40 +1752,23 @@ def pfeedback(
17541752
rich_print_kwargs: Mapping[str, Any] | None = None,
17551753
**kwargs: Any, # noqa: ARG002
17561754
) -> None:
1757-
"""Print nonessential feedback.
1758-
1759-
The output can be silenced with the `quiet` setting and its inclusion in redirected output
1760-
is controlled by the `feedback_to_output` setting.
1755+
"""Print nonessential feedback where the output can be silenced with the `quiet` setting.
17611756
17621757
For details on the parameters, refer to the `print_to` method documentation.
17631758
"""
17641759
if not self.quiet:
1765-
if self.feedback_to_output:
1766-
self.poutput(
1767-
*objects,
1768-
sep=sep,
1769-
end=end,
1770-
style=style,
1771-
soft_wrap=soft_wrap,
1772-
justify=justify,
1773-
emoji=emoji,
1774-
markup=markup,
1775-
highlight=highlight,
1776-
rich_print_kwargs=rich_print_kwargs,
1777-
)
1778-
else:
1779-
self.perror(
1780-
*objects,
1781-
sep=sep,
1782-
end=end,
1783-
style=style,
1784-
soft_wrap=soft_wrap,
1785-
justify=justify,
1786-
emoji=emoji,
1787-
markup=markup,
1788-
highlight=highlight,
1789-
rich_print_kwargs=rich_print_kwargs,
1790-
)
1760+
self.poutput(
1761+
*objects,
1762+
sep=sep,
1763+
end=end,
1764+
style=style,
1765+
soft_wrap=soft_wrap,
1766+
justify=justify,
1767+
emoji=emoji,
1768+
markup=markup,
1769+
highlight=highlight,
1770+
rich_print_kwargs=rich_print_kwargs,
1771+
)
17911772

17921773
def ppaged(
17931774
self,
@@ -2992,7 +2973,7 @@ def onecmd_plus_hooks(
29922973
stop = self.postcmd(stop, statement)
29932974

29942975
if self.timing:
2995-
self.pfeedback(f"Elapsed: {datetime.datetime.now(tz=datetime.timezone.utc) - timestart}")
2976+
self.perror(f"Elapsed: {datetime.datetime.now(tz=datetime.timezone.utc) - timestart}", style=None)
29962977
finally:
29972978
# Get sigint protection while we restore stuff
29982979
with self.sigint_protection:

docs/features/builtin_commands.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ application:
8383
debug False Show full traceback on exception
8484
echo False Echo command issued into output
8585
editor vim Program used by 'edit'
86-
feedback_to_output False Include nonessentials in '|' and '>' results
8786
max_column_completion_results 7 Maximum number of completion results to display in a single column
8887
max_completion_table_items 50 Maximum number of completion results allowed for a completion table to appear
8988
quiet False Don't print nonessential feedback

docs/features/generating_output.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ output.
8484

8585
You may have the need to display information to the user which is not intended to be part of the
8686
generated output. This could be debugging information or status information about the progress of
87-
long running commands. It's not output, it's not error messages, it's feedback. If you use the
87+
long running commands. It's not output, it's not error messages, it's status. If you use the
8888
[Timing](./settings.md#timing) setting, the output of how long it took the command to run will be
89-
output as feedback. You can use the [pfeedback][cmd2.Cmd.pfeedback] method to produce this type of
90-
output, and several [Settings](./settings.md) control how it is handled.
89+
output as to `stderr` without any styling. You can use the [perror][cmd2.Cmd.perror] method to
90+
produce this type of output by passing it `style=None`.
9191

9292
If the [quiet](./settings.md#quiet) setting is `True`, then calling `cmd2.Cmd.pfeedback` produces no
93-
output. If [quiet](./settings.md#quiet) is `False`, the
94-
[feedback_to_output](./settings.md#feedback_to_output) setting is consulted to determine whether to
95-
send the output to `stdout` or `stderr`.
93+
output. If [quiet](./settings.md#quiet) is `False`,the `pfeedback` method sends output to `stdout`.
94+
Hence, `pfeedback` is useful for non-essential output that you want the ability to silence when
95+
`quiet` is `True`.
9696

9797
## Exceptions
9898

docs/features/initialization.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ Here are instance attributes of `cmd2.Cmd` which developers might wish to overri
4343
- **editor**: text editor program to use with _edit_ command (e.g. `vim`)
4444
- **exclude_from_history**: commands to exclude from the _history_ command
4545
- **exit_code**: this determines the value returned by `cmdloop()` when exiting the application
46-
- **feedback_to_output**: if `True`, send nonessential output to stdout, if `False` send them to stderr (Default: `False`)
4746
- **help_error**: the error that prints when no help information can be found
4847
- **hidden_commands**: commands to exclude from the help menu and tab completion
4948
- **last_result**: stores results from the last command run to enable usage of results in a Python script or interactive console. Built-in commands don't make use of this. It is purely there for user-defined commands and convenience.

docs/features/settings.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@ the prompt.
5454
Similar to the `EDITOR` shell variable, this setting contains the name of the program which should
5555
be run by the [edit](./builtin_commands.md#edit) command.
5656

57-
### feedback_to_output
58-
59-
Controls whether feedback generated with the `cmd2.Cmd.pfeedback` method is sent to `self.stdout` or
60-
`sys.stderr`. If `False` the output will be sent to `sys.stderr`
61-
62-
If `True` the output is sent to `stdout` (which is often the screen but may be
63-
[redirected](./redirection.md#output-redirection-and-pipes)). The feedback output will be mixed in
64-
with and indistinguishable from output generated with `cmd2.Cmd.poutput`.
65-
6657
### max_completion_table_items
6758

6859
The maximum number of items to display in a completion table. A completion table is a special kind
@@ -74,8 +65,8 @@ appear.
7465

7566
### quiet
7667

77-
If `True`, output generated by calling `cmd2.Cmd.pfeedback` is suppressed. If `False`, the
78-
[feedback_to_output](#feedback_to_output) setting controls where the output is sent.
68+
If `True`, output generated by calling `cmd2.Cmd.pfeedback` is suppressed. If `False`, the output is
69+
sent to `stdout`.
7970

8071
### scripts_add_to_history
8172

tests/test_cmd2.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,7 @@ def test_output_redirection_to_too_long_filename(redirection_app) -> None:
726726
assert "Failed to redirect" in err[0]
727727

728728

729-
def test_feedback_to_output_true(redirection_app) -> None:
730-
redirection_app.feedback_to_output = True
729+
def test_feedback(redirection_app) -> None:
731730
f, filename = tempfile.mkstemp(prefix="cmd2_test", suffix=".txt")
732731
os.close(f)
733732

@@ -740,22 +739,6 @@ def test_feedback_to_output_true(redirection_app) -> None:
740739
os.remove(filename)
741740

742741

743-
def test_feedback_to_output_false(redirection_app) -> None:
744-
redirection_app.feedback_to_output = False
745-
f, filename = tempfile.mkstemp(prefix="feedback_to_output", suffix=".txt")
746-
os.close(f)
747-
748-
try:
749-
_out, err = run_cmd(redirection_app, f"print_feedback > {filename}")
750-
751-
with open(filename) as f:
752-
content = f.read().splitlines()
753-
assert not content
754-
assert "feedback" in err
755-
finally:
756-
os.remove(filename)
757-
758-
759742
def test_disallow_redirection(redirection_app: RedirectionApp, capsys: pytest.CaptureFixture[str]) -> None:
760743
# Set allow_redirection to False
761744
redirection_app.allow_redirection = False
@@ -872,7 +855,6 @@ def test_allow_clipboard(base_app) -> None:
872855

873856

874857
def test_base_timing(base_app) -> None:
875-
base_app.feedback_to_output = False
876858
out, err = run_cmd(base_app, "set timing True")
877859
assert not out
878860
assert err[0].startswith("timing: False")

0 commit comments

Comments
 (0)