Show More
@@ -29,7 +29,7 b' 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 | 31 | |
|
32 | __all__ = ['ANSICodeColors','Parser'] | |
|
32 | __all__ = ['ANSICodeColors', 'Parser'] | |
|
33 | 33 | |
|
34 | 34 | _scheme_default = 'Linux' |
|
35 | 35 | |
@@ -43,7 +43,7 b' import tokenize' | |||
|
43 | 43 | |
|
44 | 44 | generate_tokens = tokenize.generate_tokens |
|
45 | 45 | |
|
46 |
from IPython.utils.coloransi import TermColors, InputTermColors |
|
|
46 | from IPython.utils.coloransi import TermColors, InputTermColors,ColorScheme, ColorSchemeTable | |
|
47 | 47 | from .colorable import Colorable |
|
48 | 48 | from io import StringIO |
|
49 | 49 | |
@@ -185,8 +185,11 b' class Parser(Colorable):' | |||
|
185 | 185 | |
|
186 | 186 | super(Parser, self).__init__(parent=parent) |
|
187 | 187 | |
|
188 |
self.color_table = color_table |
|
|
188 | self.color_table = color_table if color_table else ANSICodeColors | |
|
189 | 189 | self.out = out |
|
190 | self.pos = None | |
|
191 | self.lines = None | |
|
192 | self.raw = None | |
|
190 | 193 | if not style: |
|
191 | 194 | self.style = self.default_style |
|
192 | 195 | else: |
@@ -231,9 +234,8 b' class Parser(Colorable):' | |||
|
231 | 234 | error = False |
|
232 | 235 | self.out.write(raw) |
|
233 | 236 | if string_output: |
|
234 | return raw,error | |
|
235 | else: | |
|
236 | return None,error | |
|
237 | return raw, error | |
|
238 | return None, error | |
|
237 | 239 | |
|
238 | 240 | # local shorthands |
|
239 | 241 | colors = self.color_table[self.style].colors |
@@ -247,9 +249,10 b' class Parser(Colorable):' | |||
|
247 | 249 | pos = 0 |
|
248 | 250 | raw_find = self.raw.find |
|
249 | 251 | lines_append = self.lines.append |
|
250 |
while |
|
|
252 | while True: | |
|
251 | 253 | pos = raw_find('\n', pos) + 1 |
|
252 |
if not pos: |
|
|
254 | if not pos: | |
|
255 | break | |
|
253 | 256 | lines_append(pos) |
|
254 | 257 | lines_append(len(self.raw)) |
|
255 | 258 | |
@@ -277,11 +280,11 b' class Parser(Colorable):' | |||
|
277 | 280 | return (output, error) |
|
278 | 281 | return (None, error) |
|
279 | 282 | |
|
280 | def _inner_call_(self, toktype, toktext, start_pos, end_pos, line): | |
|
283 | ||
|
284 | def _inner_call_(self, toktype, toktext, start_pos): | |
|
281 | 285 | """like call but write to a temporary buffer""" |
|
282 | 286 | buff = StringIO() |
|
283 |
|
|
|
284 | (erow,ecol) = end_pos | |
|
287 | srow, scol = start_pos | |
|
285 | 288 | colors = self.colors |
|
286 | 289 | owrite = buff.write |
|
287 | 290 | |
@@ -310,8 +313,6 b' class Parser(Colorable):' | |||
|
310 | 313 | toktype = _KEYWORD |
|
311 | 314 | color = colors.get(toktype, colors[_TEXT]) |
|
312 | 315 | |
|
313 | #print '<%s>' % toktext, # dbg | |
|
314 | ||
|
315 | 316 | # Triple quoted strings must be handled carefully so that backtracking |
|
316 | 317 | # in pagers works correctly. We need color terminators on _each_ line. |
|
317 | 318 | if linesep in toktext: |
@@ -327,5 +328,4 b' class Parser(Colorable):' | |||
|
327 | 328 | def __call__(self, toktype, toktext, start_pos, end_pos, line): |
|
328 | 329 | """ Token handler, with syntax highlighting.""" |
|
329 | 330 | self.out.write( |
|
330 |
self._inner_call_(toktype, toktext, start_pos |
|
|
331 | ||
|
331 | self._inner_call_(toktype, toktext, start_pos)) |
General Comments 0
You need to be logged in to leave comments.
Login now