Mercurial > hg > TextShaper
annotate textshaper/main.py @ 10:466386702968
more stuff
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Sat, 18 Jan 2014 09:28:55 -0800 |
| parents | 71fb16088d54 |
| children | 5b70bbff04b1 |
| rev | line source |
|---|---|
| 0 | 1 #!/usr/bin/env python |
| 2 # -*- coding: utf-8 -*- | |
| 3 | |
| 4 """ | |
| 4 | 5 package to shape text blocks |
| 0 | 6 """ |
| 7 | |
| 8 import optparse | |
| 9 import os | |
| 10 import subprocess | |
| 11 import sys | |
| 3 | 12 import time |
| 0 | 13 |
| 5 | 14 def display(content): |
| 4 | 15 print content |
| 16 print '--' | |
| 17 nlines = len(content.splitlines()) | |
| 18 print '%d lines' % nlines | |
| 19 | |
| 0 | 20 def add_options(parser): |
| 21 """add options to the OptionParser instance""" | |
| 22 | |
|
9
71fb16088d54
add file for indentation; wth did my work go??? :(
Jeff Hammel <k0scist@gmail.com>
parents:
5
diff
changeset
|
23 # TODO |
|
71fb16088d54
add file for indentation; wth did my work go??? :(
Jeff Hammel <k0scist@gmail.com>
parents:
5
diff
changeset
|
24 # parser.add_option('-c', '--clip', '--copy', dest='copy_to_clipboard', |
|
71fb16088d54
add file for indentation; wth did my work go??? :(
Jeff Hammel <k0scist@gmail.com>
parents:
5
diff
changeset
|
25 # help="copy to given program on exit") |
|
71fb16088d54
add file for indentation; wth did my work go??? :(
Jeff Hammel <k0scist@gmail.com>
parents:
5
diff
changeset
|
26 |
| 0 | 27 def main(args=sys.argv[1:]): |
| 28 | |
| 29 # parse command line options | |
| 30 usage = '%prog [options] ...' | |
| 31 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): | |
| 32 """description formatter for console script entry point""" | |
| 33 def format_description(self, description): | |
| 34 if description: | |
| 35 return description.strip() + '\n' | |
| 36 else: | |
| 37 return '' | |
| 38 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) | |
| 39 options, args = parser.parse_args(args) | |
| 40 | |
| 3 | 41 # read from stdin |
| 42 content = sys.stdin.read() | |
| 43 | |
| 44 # print formatted content | |
| 4 | 45 display(content) |
| 3 | 46 |
| 47 while True: | |
| 48 time.sleep(1) # XXX | |
| 49 | |
| 0 | 50 if __name__ == '__main__': |
| 51 main() | |
| 52 |
