Mercurial > hg > TextShaper
comparison textshaper/main.py @ 32:929a5e97af3e
prestrip text unless specified
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 23 Feb 2014 14:56:17 -0800 |
parents | 586631375670 |
children | 88a69d587326 |
comparison
equal
deleted
inserted
replaced
31:23616399f36c | 32:929a5e97af3e |
---|---|
35 """add options to the parser instance""" | 35 """add options to the parser instance""" |
36 | 36 |
37 parser.add_argument('-f', '--file', dest='input', | 37 parser.add_argument('-f', '--file', dest='input', |
38 type=argparse.FileType('r'), default=sys.stdin, | 38 type=argparse.FileType('r'), default=sys.stdin, |
39 help="file to read from [DEFAULT: stdin]") | 39 help="file to read from [DEFAULT: stdin]") |
40 parser.add_argument('-n', '--no-strip', dest='strip', | |
41 action='store_false', default=True, | |
42 help="do not strip whitespace before processing") | |
40 | 43 |
41 if which('xclip'): # TODO: support e.g. xsel or python native | 44 if which('xclip'): # TODO: support e.g. xsel or python native |
42 parser.add_argument('-c', '--clip', '--copy', dest='copy_to_clipboard', | 45 parser.add_argument('-c', '--clip', '--copy', dest='copy_to_clipboard', |
43 action='store_true', default=False, | 46 action='store_true', default=False, |
44 help="copy to clipboard") | 47 help="copy to clipboard") |
45 | 48 |
46 | 49 |
47 | 50 |
48 def main(args=sys.argv[1:]): | 51 def main(args=sys.argv[1:]): |
49 | 52 |
53 # TODO: read ~/.textshaper | |
54 | |
50 # parse command line options | 55 # parse command line options |
51 parser = argparse.ArgumentParser(description=__doc__) | 56 parser = argparse.ArgumentParser(description=__doc__) |
52 add_options(parser) | 57 add_options(parser) |
53 options = parser.parse_args(args) | 58 options = parser.parse_args(args) |
54 | 59 |
55 # read input | 60 # read input |
56 content = options.input.read() | 61 content = options.input.read() |
62 | |
63 # pre-process output | |
64 if options.strip: | |
65 content = content.strip() | |
57 | 66 |
58 # print formatted content | 67 # print formatted content |
59 display(content) | 68 display(content) |
60 | 69 |
61 # main display loop | 70 # main display loop |