Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5b381a3

Browse files
committed
Make ANSI the default output style
1 parent 0712f40 commit 5b381a3

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

Tools/scripts/highlight.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Example command-line calls:
55
66
# Show syntax highlighted code in the terminal window
7-
$ ./highlight.py -a myfile.py
7+
$ ./highlight.py myfile.py
88
99
# Colorize myfile.py and display in a browser
1010
$ ./highlight.py -b myfile.py
@@ -13,7 +13,7 @@
1313
./highlight.py -s myfile.py
1414
1515
# Create a complete HTML file
16-
$ ./highlight.py myfile.py > myfile.html
16+
$ ./highlight.py -c myfile.py > myfile.html
1717
1818
'''
1919

@@ -149,31 +149,28 @@ def build_page(source, title='python', css=default_css, html=default_html):
149149
description = 'Add syntax highlighting to Python source')
150150
parser.add_argument('sourcefile', metavar = 'SOURCEFILE',
151151
help = 'File containing Python sourcecode')
152-
parser.add_argument('-a', '--ansi', action = 'store_true',
153-
help = 'emit ANSI escape highlighted source')
154152
parser.add_argument('-b', '--browser', action = 'store_true',
155153
help = 'launch a browser to show results')
154+
parser.add_argument('-c', '--complete', action = 'store_true',
155+
help = 'build a complete html webpage')
156156
parser.add_argument('-s', '--section', action = 'store_true',
157157
help = 'show an HTML section rather than a complete webpage')
158158
args = parser.parse_args()
159159

160-
if args.browser and args.section:
160+
if args.section and (args.browser or args.complete):
161161
parser.error('The -s/--section option is incompatible with '
162-
'the -b/--browser option')
163-
if args.ansi and (args.browser or args.section):
164-
parser.error('The -a/--ansi option is incompatible with '
165-
'the -b/--browser and -s/--section options')
162+
'the -b/--browser or -c/--complete options')
166163

167164
sourcefile = args.sourcefile
168165
with open(sourcefile) as f:
169166
source = f.read()
170167

171-
if args.ansi:
172-
encoded = colorize_ansi(source)
168+
if args.complete or args.browser:
169+
encoded = build_page(source, title=sourcefile)
173170
elif args.section:
174171
encoded = colorize_html(source)
175172
else:
176-
encoded = build_page(source, title=sourcefile)
173+
encoded = colorize_ansi(source)
177174

178175
if args.browser:
179176
htmlfile = os.path.splitext(os.path.basename(sourcefile))[0] + '.html'

0 commit comments

Comments
 (0)