diff --git a/IPython/PyColorize.py b/IPython/PyColorize.py index 55e3ed9..2268ee1 100755 --- a/IPython/PyColorize.py +++ b/IPython/PyColorize.py @@ -28,7 +28,7 @@ scan Python source code and re-emit it with no changes to its original formatting (which is the hard part). - $Id: PyColorize.py 2274 2007-04-26 14:41:43Z jdh2358 $""" + $Id: PyColorize.py 2341 2007-05-15 14:44:30Z vivainio $""" __all__ = ['ANSICodeColors','Parser'] @@ -38,6 +38,7 @@ _scheme_default = 'Linux' import cStringIO import keyword import os +import optparse import string import sys import token @@ -242,42 +243,38 @@ class Parser: # send text owrite('%s%s%s' % (color,toktext,colors.normal)) -def main(): - """Colorize a python file using ANSI color escapes and print to stdout. +def main(argv=None): + """Run as a command-line script: colorize a python file using ANSI color + escapes and print to stdout. - Usage: - %s [-s scheme] filename + Inputs: - Options: + - argv(None): a list of strings like sys.argv[1:] giving the command-line + arguments. If None, use sys.argv[1:]. + """ - -s scheme: give the color scheme to use. Currently only 'Linux' - (default) and 'LightBG' and 'NoColor' are implemented (give without - quotes). """ + usage_msg = """%prog [options] filename - def usage(): - print >> sys.stderr, main.__doc__ % sys.argv[0] - sys.exit(1) - - # FIXME: rewrite this to at least use getopt - try: - if sys.argv[1] == '-s': - scheme_name = sys.argv[2] - del sys.argv[1:3] - else: - scheme_name = _scheme_default - - except: - usage() +Colorize a python file using ANSI color escapes and print to stdout.""" + + parser = optparse.OptionParser(usage=usage_msg) + newopt = parser.add_option + newopt('-s','--scheme',metavar='NAME',dest='scheme_name',action='store', + choices=['Linux','LightBG','NoColor'],default=_scheme_default, + help="give the color scheme to use. Currently only 'Linux'\ + (default) and 'LightBG' and 'NoColor' are implemented (give without\ + quotes)") + + opts,args = parser.parse_args(argv) + + if len(args) != 1: + parser.error("you must give one filename.") - try: - fname = sys.argv[1] - except: - usage() - # write colorized version to stdout + fname = args[0] parser = Parser() try: - parser.format(file(fname).read(),scheme = scheme_name) + parser.format(file(fname).read(),scheme=opts.scheme_name) except IOError,msg: # if user reads through a pager and quits, don't print traceback if msg.args != (32,'Broken pipe'): diff --git a/IPython/iplib.py b/IPython/iplib.py index e95c8d4..319890f 100644 --- a/IPython/iplib.py +++ b/IPython/iplib.py @@ -6,7 +6,7 @@ Requires Python 2.3 or newer. This file contains all the classes and helper functions specific to IPython. -$Id: iplib.py 2297 2007-04-30 11:08:46Z vivainio $ +$Id: iplib.py 2341 2007-05-15 14:44:30Z vivainio $ """ #***************************************************************************** @@ -1288,6 +1288,9 @@ want to merge them back into the new files.""" % locals() Currently it handles auto-indent only.""" #debugx('self.indent_current_nsp','pre_readline:') + print "prer",self.indent_current_nsp # dbg + print + self.readline.insert_text(self.indent_current_str()) def init_readline(self): @@ -1806,6 +1809,7 @@ want to merge them back into the new files.""" % locals() #debugx('line') #debugx('self.indent_current_nsp') if self.autoindent: + print "ind level", self.indent_current_nsp #dbg if line: inisp = num_ini_spaces(line) if inisp < self.indent_current_nsp: diff --git a/doc/pycolor.1 b/doc/pycolor.1 index 34cf5d5..3594630 100644 --- a/doc/pycolor.1 +++ b/doc/pycolor.1 @@ -2,7 +2,7 @@ .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) -.TH PYCOLOR 1 "March 21, 2003" +.TH PYCOLOR 1 "May 12, 2007" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: @@ -24,7 +24,10 @@ pycolor \- Colorize a python file using ANSI and print to stdout. Prints a colorized version of the input file to standard out. .SH OPTIONS .TP -.B \-s +.B \-h, \-\-help +Output a brief help message. +.TP +.B \-s, \-\-scheme Give the color scheme to use. Currently only Linux (default), LightBG, and NOColor are implemented. .SH AUTHOR