diff 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
line wrap: on
line diff
--- a/textshaper/main.py	Sun Feb 23 14:48:40 2014 -0800
+++ b/textshaper/main.py	Sun Feb 23 14:56:17 2014 -0800
@@ -37,6 +37,9 @@
     parser.add_argument('-f', '--file',  dest='input',
                         type=argparse.FileType('r'), default=sys.stdin,
                         help="file to read from [DEFAULT: stdin]")
+    parser.add_argument('-n', '--no-strip', dest='strip',
+                        action='store_false', default=True,
+                        help="do not strip whitespace before processing")
 
     if which('xclip'): # TODO: support e.g. xsel or python native
         parser.add_argument('-c', '--clip', '--copy', dest='copy_to_clipboard',
@@ -47,6 +50,8 @@
 
 def main(args=sys.argv[1:]):
 
+    # TODO: read ~/.textshaper
+
     # parse command line options
     parser = argparse.ArgumentParser(description=__doc__)
     add_options(parser)
@@ -55,6 +60,10 @@
     # read input
     content = options.input.read()
 
+    # pre-process output
+    if options.strip:
+        content = content.strip()
+
     # print formatted content
     display(content)