comparison textshaper/main.py @ 19:70dde00a4df0

selectable, albeit single, input
author Jeff Hammel <k0scist@gmail.com>
date Sun, 23 Feb 2014 00:26:19 -0800
parents df52326aa08d
children 586631375670
comparison
equal deleted inserted replaced
18:df52326aa08d 19:70dde00a4df0
9 import os 9 import os
10 import subprocess 10 import subprocess
11 import sys 11 import sys
12 import time 12 import time
13 from which import which 13 from which import which
14
14 15
15 def info(content): 16 def info(content):
16 """gathers info about the content and returns a dict""" 17 """gathers info about the content and returns a dict"""
17 18
18 lines = content.splitlines() 19 lines = content.splitlines()
29 print (hr) 30 print (hr)
30 print ('; '.join(['{}: {}'.format(key, _info[key]) 31 print ('; '.join(['{}: {}'.format(key, _info[key])
31 for key in keys])) 32 for key in keys]))
32 33
33 def add_options(parser): 34 def add_options(parser):
34 """add options to the OptionParser instance""" 35 """add options to the parser instance"""
36
37 parser.add_option('-f', '--file', dest='input',
38 type=argparse.FileType('r'), default=sys.stdin,
39 help="file to read from [DEFAULT: stdin]")
35 40
36 if which('xclip'): # TODO: support e.g. xsel or python native 41 if which('xclip'): # TODO: support e.g. xsel or python native
37 parser.add_option('-c', '--clip', '--copy', dest='copy_to_clipboard', 42 parser.add_option('-c', '--clip', '--copy', dest='copy_to_clipboard',
38 action='store_true', default=False, 43 action='store_true', default=False,
39 help="copy to clipboard") 44 help="copy to clipboard")
45 # parse command line options 50 # parse command line options
46 parser = argparse.ArgumentParser(description=__doc__, formatter=PlainDescriptionFormatter()) 51 parser = argparse.ArgumentParser(description=__doc__, formatter=PlainDescriptionFormatter())
47 options = parser.parse_args(args) 52 options = parser.parse_args(args)
48 53
49 # read from stdin 54 # read from stdin
50 content = sys.stdin.read() 55 content = options.read()
51 56
52 # print formatted content 57 # print formatted content
53 display(content) 58 display(content)
54 59
55 # main display loop 60 # main display loop