diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-03-07 19:36:42 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-03-07 19:36:42 -0500 |
commit | c18b2a830576db859a37732584a077699039bb33 (patch) | |
tree | 7cb8f894687d390c5328d7f5571c676ec97fb4fc /examples/paged_output.py | |
parent | a6f0e06a350f2ab65d3bf635fa7aae0b655ed44a (diff) | |
download | cmd2-git-c18b2a830576db859a37732584a077699039bb33.tar.gz |
Added ppaged() method for printing output via a pager
Also:
- Added paged_output.py example
- Modified cmd2 so it keeps track of when output is being redirected so it doesn't attempt to usage a pager in this case
Diffstat (limited to 'examples/paged_output.py')
-rwxr-xr-x | examples/paged_output.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/examples/paged_output.py b/examples/paged_output.py new file mode 100755 index 00000000..171c1b3e --- /dev/null +++ b/examples/paged_output.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# coding=utf-8 +"""A simple example demonstrating the using paged output via the ppaged() method. +""" +import functools + +import cmd2 +from cmd2 import with_argument_list + + +class PagedOutput(cmd2.Cmd): + """ Example cmd2 application where we create commands that just print the arguments they are called with.""" + + def __init__(self): + cmd2.Cmd.__init__(self) + + @with_argument_list + def do_page_file(self, args): + """Read in a text file and display its output in a pager.""" + with open(args[0], 'r') as f: + text = f.read() + self.ppaged(text) + + complete_page_file = functools.partial(cmd2.path_complete) + + +if __name__ == '__main__': + app = PagedOutput() + app.cmdloop() |