pgcli
pgcli copied to clipboard
convert to dual outputs: pager and stdout
regular output (mainly query results) goes to the pager. status output goes directly to stdout. both implement a consistent interface for easy mocking in tests.
Description
Picking up where #1383 left off.
We agreed on the need to separate normal query result output from status output. The previous PR used stdout and stderr, but we decided instead to use the pager's stdin and pgcli's stdout as the two streams.
Further, because there's a need to maintain order in the output lines even across the two streams, this PR inverts control and takes a DI approach, pushing "output emitters" down into the PGCli object. The previously pure "format_output" function is now "emit_output" which takes the injected emitters. For tests, we mock out the emitters with an implementation that collects the output lines in order for later assertions.
Checklist
- [X] I've added this contribution to the
changelog.rst
. - [X] I've added my name to the
AUTHORS
file (or it's already there).
- [X] I installed pre-commit hooks (
pip install pre-commit && pre-commit install
), and ranblack
on my code. - [x] Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)
@teepark Would you be able to resolve the conflicts?