Show More
@@ -28,7 +28,7 b'' | |||
|
28 | 28 | scan Python source code and re-emit it with no changes to its original |
|
29 | 29 | formatting (which is the hard part). |
|
30 | 30 | |
|
31 |
$Id: PyColorize.py 2 |
|
|
31 | $Id: PyColorize.py 2341 2007-05-15 14:44:30Z vivainio $""" | |
|
32 | 32 | |
|
33 | 33 | __all__ = ['ANSICodeColors','Parser'] |
|
34 | 34 | |
@@ -38,6 +38,7 b" _scheme_default = 'Linux'" | |||
|
38 | 38 | import cStringIO |
|
39 | 39 | import keyword |
|
40 | 40 | import os |
|
41 | import optparse | |
|
41 | 42 | import string |
|
42 | 43 | import sys |
|
43 | 44 | import token |
@@ -242,42 +243,38 b' class Parser:' | |||
|
242 | 243 | # send text |
|
243 | 244 | owrite('%s%s%s' % (color,toktext,colors.normal)) |
|
244 | 245 | |
|
245 | def main(): | |
|
246 | """Colorize a python file using ANSI color escapes and print to stdout. | |
|
246 | def main(argv=None): | |
|
247 | """Run as a command-line script: colorize a python file using ANSI color | |
|
248 | escapes and print to stdout. | |
|
247 | 249 | |
|
248 | Usage: | |
|
249 | %s [-s scheme] filename | |
|
250 | Inputs: | |
|
250 | 251 | |
|
251 | Options: | |
|
252 | - argv(None): a list of strings like sys.argv[1:] giving the command-line | |
|
253 | arguments. If None, use sys.argv[1:]. | |
|
254 | """ | |
|
252 | 255 | |
|
253 | -s scheme: give the color scheme to use. Currently only 'Linux' | |
|
254 | (default) and 'LightBG' and 'NoColor' are implemented (give without | |
|
255 | quotes). """ | |
|
256 | usage_msg = """%prog [options] filename | |
|
256 | 257 | |
|
257 | def usage(): | |
|
258 | print >> sys.stderr, main.__doc__ % sys.argv[0] | |
|
259 | sys.exit(1) | |
|
260 | ||
|
261 | # FIXME: rewrite this to at least use getopt | |
|
262 | try: | |
|
263 | if sys.argv[1] == '-s': | |
|
264 | scheme_name = sys.argv[2] | |
|
265 | del sys.argv[1:3] | |
|
266 | else: | |
|
267 | scheme_name = _scheme_default | |
|
268 | ||
|
269 | except: | |
|
270 | usage() | |
|
258 | Colorize a python file using ANSI color escapes and print to stdout.""" | |
|
259 | ||
|
260 | parser = optparse.OptionParser(usage=usage_msg) | |
|
261 | newopt = parser.add_option | |
|
262 | newopt('-s','--scheme',metavar='NAME',dest='scheme_name',action='store', | |
|
263 | choices=['Linux','LightBG','NoColor'],default=_scheme_default, | |
|
264 | help="give the color scheme to use. Currently only 'Linux'\ | |
|
265 | (default) and 'LightBG' and 'NoColor' are implemented (give without\ | |
|
266 | quotes)") | |
|
267 | ||
|
268 | opts,args = parser.parse_args(argv) | |
|
269 | ||
|
270 | if len(args) != 1: | |
|
271 | parser.error("you must give one filename.") | |
|
271 | 272 | |
|
272 | try: | |
|
273 | fname = sys.argv[1] | |
|
274 | except: | |
|
275 | usage() | |
|
276 | ||
|
277 | 273 | # write colorized version to stdout |
|
274 | fname = args[0] | |
|
278 | 275 | parser = Parser() |
|
279 | 276 | try: |
|
280 |
parser.format(file(fname).read(),scheme |
|
|
277 | parser.format(file(fname).read(),scheme=opts.scheme_name) | |
|
281 | 278 | except IOError,msg: |
|
282 | 279 | # if user reads through a pager and quits, don't print traceback |
|
283 | 280 | if msg.args != (32,'Broken pipe'): |
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.' | |||
|
6 | 6 | |
|
7 | 7 | This file contains all the classes and helper functions specific to IPython. |
|
8 | 8 | |
|
9 |
$Id: iplib.py 2 |
|
|
9 | $Id: iplib.py 2341 2007-05-15 14:44:30Z vivainio $ | |
|
10 | 10 | """ |
|
11 | 11 | |
|
12 | 12 | #***************************************************************************** |
@@ -1288,6 +1288,9 b' want to merge them back into the new files.""" % locals()' | |||
|
1288 | 1288 | Currently it handles auto-indent only.""" |
|
1289 | 1289 | |
|
1290 | 1290 | #debugx('self.indent_current_nsp','pre_readline:') |
|
1291 | print "prer",self.indent_current_nsp # dbg | |
|
1292 | ||
|
1293 | ||
|
1291 | 1294 | self.readline.insert_text(self.indent_current_str()) |
|
1292 | 1295 | |
|
1293 | 1296 | def init_readline(self): |
@@ -1806,6 +1809,7 b' want to merge them back into the new files.""" % locals()' | |||
|
1806 | 1809 | #debugx('line') |
|
1807 | 1810 | #debugx('self.indent_current_nsp') |
|
1808 | 1811 | if self.autoindent: |
|
1812 | print "ind level", self.indent_current_nsp #dbg | |
|
1809 | 1813 | if line: |
|
1810 | 1814 | inisp = num_ini_spaces(line) |
|
1811 | 1815 | if inisp < self.indent_current_nsp: |
@@ -2,7 +2,7 b'' | |||
|
2 | 2 | .\" First parameter, NAME, should be all caps |
|
3 | 3 | .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection |
|
4 | 4 | .\" other parameters are allowed: see man(7), man(1) |
|
5 |
.TH PYCOLOR 1 "Ma |
|
|
5 | .TH PYCOLOR 1 "May 12, 2007" | |
|
6 | 6 | .\" Please adjust this date whenever revising the manpage. |
|
7 | 7 | .\" |
|
8 | 8 | .\" Some roff macros, for reference: |
@@ -24,7 +24,10 b' pycolor \\- Colorize a python file using ANSI and print to stdout.' | |||
|
24 | 24 | Prints a colorized version of the input file to standard out. |
|
25 | 25 | .SH OPTIONS |
|
26 | 26 | .TP |
|
27 | .B \-s <scheme> | |
|
27 | .B \-h, \-\-help | |
|
28 | Output a brief help message. | |
|
29 | .TP | |
|
30 | .B \-s, \-\-scheme <scheme> | |
|
28 | 31 | Give the color scheme to use. Currently only Linux (default), |
|
29 | 32 | LightBG, and NOColor are implemented. |
|
30 | 33 | .SH AUTHOR |
General Comments 0
You need to be logged in to leave comments.
Login now