Skip to content

Commit d731cff

Browse files
committed
Refactored the Windows vs macOS/Linux conditional in ppaged()
Aslo: - Added some documentation for ppaged() - Updated CHANGELOG - Added line about ppaged() in README
1 parent 5cc434b commit d731cff

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* ``exclude_from_help`` and ``excludeFromHistory`` are now instance instead of class attributes
1717
* Added flag and index based tab completion helper functions
1818
* See [tab_completion.py](https://github.com/python-cmd2/cmd2/blob/master/examples/tab_completion.py)
19+
* Added support for displaying output which won't fit on the screen via a pager using ``ppaged()``
20+
* See [paged_output.py](https://github.com/python-cmd2/cmd2/blob/master/examples/paged_output.py)
1921
* Attributes Removed (**can cause breaking changes**)
2022
* ``abbrev`` - Removed support for abbreviated commands
2123
* Good tab completion makes this unnecessary and its presence could cause harmful unintended actions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Main Features
2626
- Redirect command output to file with `>`, `>>`; input from file with `<`
2727
- Bare `>`, `>>` with no filename send output to paste buffer (clipboard)
2828
- `py` enters interactive Python console (opt-in `ipy` for IPython console)
29+
- Option to display long output using a pager with ``cmd2.Cmd.ppaged()``
2930
- Multi-line commands
3031
- Special-character command shortcuts (beyond cmd's `@` and `!`)
3132
- Settable environment parameters

cmd2.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,14 +1229,15 @@ def ppaged(self, msg, end=os.linesep):
12291229

12301230
# Don't attempt to use a pager that can block if redirecting or running a script (either text or Python)
12311231
if not self.redirecting and not self._in_py and not self._script_dir:
1232-
# Here is the meaning of the various flags we are using with the less command:
1233-
# -S causes lines longer than the screen width to be chopped (truncated) rather than wrapped
1234-
# -R causes ANSI "color" escape sequences to be output in raw form (i.e. colors are displayed)
1235-
# -X disables sending the termcap initialization and deinitialization strings to the terminal
1236-
# -F causes less to automatically exit if the entire file can be displayed on the first screen
1237-
pager_cmd = 'less -SRXF'
12381232
if sys.platform.startswith('win'):
12391233
pager_cmd = 'more'
1234+
else:
1235+
# Here is the meaning of the various flags we are using with the less command:
1236+
# -S causes lines longer than the screen width to be chopped (truncated) rather than wrapped
1237+
# -R causes ANSI "color" escape sequences to be output in raw form (i.e. colors are displayed)
1238+
# -X disables sending the termcap initialization and deinitialization strings to the terminal
1239+
# -F causes less to automatically exit if the entire file can be displayed on the first screen
1240+
pager_cmd = 'less -SRXF'
12401241
self.pipe_proc = subprocess.Popen(pager_cmd, shell=True, stdin=subprocess.PIPE)
12411242
try:
12421243
self.pipe_proc.stdin.write(msg_str.encode('utf-8', 'replace'))

docs/unfreefeatures.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,23 @@ There are a couple functions which can globally effect how arguments are parsed
147147
.. _argparse: https://docs.python.org/3/library/argparse.html
148148

149149

150-
poutput, pfeedback, perror
151-
==========================
150+
poutput, pfeedback, perror, ppaged
151+
==================================
152152

153153
Standard ``cmd`` applications produce their output with ``self.stdout.write('output')`` (or with ``print``,
154154
but ``print`` decreases output flexibility). ``cmd2`` applications can use
155-
``self.poutput('output')``, ``self.pfeedback('message')``, and ``self.perror('errmsg')``
155+
``self.poutput('output')``, ``self.pfeedback('message')``, ``self.perror('errmsg')``, and ``self.ppaged('text')``
156156
instead. These methods have these advantages:
157157

158158
- Handle output redirection to file and/or pipe appropriately
159159
- More concise
160160
- ``.pfeedback()`` destination is controlled by :ref:`quiet` parameter.
161+
- Option to display long output using a pager via ``ppaged()``
161162

162163
.. automethod:: cmd2.Cmd.poutput
163164
.. automethod:: cmd2.Cmd.perror
164165
.. automethod:: cmd2.Cmd.pfeedback
166+
.. automethod:: cmd2.Cmd.ppaged
165167

166168

167169
color

0 commit comments

Comments
 (0)