Mercurial > hg > numerics
changeset 93:b755a8d946de
stub: txt display
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Mon, 02 Mar 2015 18:35:16 -0800 |
parents | 5b25e0be78aa |
children | b5aea10e611d |
files | numerics/text_display.py |
diffstat | 1 files changed, 57 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/numerics/text_display.py Mon Mar 02 18:35:16 2015 -0800 @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +text display +""" + +# imports +import argparse + +# module globals +__all__ = ['main', 'frac', 'FracParser'] + +block = '' + + +def frac(*fractions, width=20, bar='│'): + """display fractions""" + raise NotImplementedError('TODO') # -> record TODO items + + +class FracParser(argparse.ArgumentParser): + """CLI option parser""" + def __init__(self, **kwargs): + kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter) + kwargs.setdefault('description', __doc__) + argparse.ArgumentParser.__init__(self, **kwargs) + self.add_argument('fraction', type=float, nargs='+' + help="fractions to display") + self.add_argument('-w', '--width', dest='width', + type=int, default=20, + help="width to display [DEFAULT: %(default)s]") + self.options = None + + def parse_args(self, *args, **kw): + options = argparse.ArgumentParser.parse_args(self, *args, **kw) + self.validate(options) + self.options = options + return options + + def validate(self, options): + """validate options""" + if options.width < 1: + self.error("Width must be greater than zero (You gave: {})".format(options.width)) + +def main(args=sys.argv[1:]): + """CLI""" + + # parse command line options + parser = FracParser() + options = parser.parse_args(args) + + +if __name__ == '__main__': + main() + +