summaryrefslogtreecommitdiff
path: root/cmd2
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-06-11 20:48:03 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-06-11 20:48:03 -0400
commit0d4e633e8e0698cecc851af2f8967b6ead0e748b (patch)
tree26f9634a091cd10709415dbb4f1d22d8335d770e /cmd2
parent3ae71e80e61a908ad0a0dec84ee6496592176022 (diff)
downloadcmd2-git-0d4e633e8e0698cecc851af2f8967b6ead0e748b.tar.gz
Added pager settable parameter to control the command used to display paged output
Also: - ppaged() now uses the pager settable parameter - By default the pager settable parameter uses the PAGER environment variable if present - If PAGER environment variable is not present, pager gets set to: - "less -SXRF" on POSIX OSes (macOS and Linux) - "more" on Windows
Diffstat (limited to 'cmd2')
-rw-r--r--cmd2/cmd2.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 3d2a8afe..22797430 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -385,6 +385,17 @@ class Cmd(cmd.Cmd):
break
feedback_to_output = False # Do not include nonessentials in >, | output by default (things like timing)
locals_in_py = False
+ pager = os.environ.get('PAGER')
+ if not pager:
+ if sys.platform.startswith('win'):
+ pager = 'more'
+ else:
+ # Here is the meaning of the various flags we are using with the less command:
+ # -S causes lines longer than the screen width to be chopped (truncated) rather than wrapped
+ # -R causes ANSI "color" escape sequences to be output in raw form (i.e. colors are displayed)
+ # -X disables sending the termcap initialization and deinitialization strings to the terminal
+ # -F causes less to automatically exit if the entire file can be displayed on the first screen
+ pager = 'less -SRXF'
quiet = False # Do not suppress nonessential output
timing = False # Prints elapsed time for each command
@@ -397,6 +408,7 @@ class Cmd(cmd.Cmd):
'editor': 'Program used by ``edit``',
'feedback_to_output': 'Include nonessentials in `|`, `>` results',
'locals_in_py': 'Allow access to your application in py via self',
+ 'pager': 'Command used for displaying paged output',
'prompt': 'The prompt issued to solicit input',
'quiet': "Don't print nonessential feedback",
'timing': 'Report execution times'}
@@ -635,17 +647,7 @@ class Cmd(cmd.Cmd):
# Don't attempt to use a pager that can block if redirecting or running a script (either text or Python)
# Also only attempt to use a pager if actually running in a real fully functional terminal
if functional_terminal and not self.redirecting and not self._in_py and not self._script_dir:
-
- if sys.platform.startswith('win'):
- pager_cmd = 'more'
- else:
- # Here is the meaning of the various flags we are using with the less command:
- # -S causes lines longer than the screen width to be chopped (truncated) rather than wrapped
- # -R causes ANSI "color" escape sequences to be output in raw form (i.e. colors are displayed)
- # -X disables sending the termcap initialization and deinitialization strings to the terminal
- # -F causes less to automatically exit if the entire file can be displayed on the first screen
- pager_cmd = 'less -SRXF'
- self.pipe_proc = subprocess.Popen(pager_cmd, shell=True, stdin=subprocess.PIPE)
+ self.pipe_proc = subprocess.Popen(self.pager, shell=True, stdin=subprocess.PIPE)
try:
self.pipe_proc.stdin.write(msg_str.encode('utf-8', 'replace'))
self.pipe_proc.stdin.close()