view textshaper/main.py @ 9:71fb16088d54

add file for indentation; wth did my work go??? :(
author Jeff Hammel <k0scist@gmail.com>
date Fri, 17 Jan 2014 18:17:59 -0800
parents 0a800613af9a
children 5b70bbff04b1
line wrap: on
line source

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
package to shape text blocks
"""

import optparse
import os
import subprocess
import sys
import time

def display(content):
    print content
    print '--'
    nlines = len(content.splitlines())
    print '%d lines' % nlines

def add_options(parser):
    """add options to the OptionParser instance"""

    # TODO
    #    parser.add_option('-c', '--clip', '--copy', dest='copy_to_clipboard',
    #                  help="copy to given program on exit")

def main(args=sys.argv[1:]):

    # parse command line options
    usage = '%prog [options] ...'
    class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
        """description formatter for console script entry point"""
        def format_description(self, description):
            if description:
                return description.strip() + '\n'
            else:
                return ''
    parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
    options, args = parser.parse_args(args)

    # read from stdin
    content = sys.stdin.read()

    # print formatted content
    display(content)

    while True:
        time.sleep(1) # XXX

if __name__ == '__main__':
  main()