annotate MoinMoin/support/pygments/formatters/terminal.py @ 6133:a6283e189869 tip

fixup: remove nonexisting passlib.utils._blowfish this was removed by the passlib 1.7.1 upgrade.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 01 Jun 2017 18:10:19 +0200
parents 815981fad7fd
children
rev   line source
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
2 """
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
3 pygments.formatters.terminal
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
5
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
6 Formatter for terminal output with ANSI sequences.
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
7
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
9 :license: BSD, see LICENSE for details.
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
10 """
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
11
6009
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
12 import sys
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
13
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
14 from pygments.formatter import Formatter
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
15 from pygments.token import Keyword, Name, Comment, String, Error, \
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
16 Number, Operator, Generic, Token, Whitespace
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
17 from pygments.console import ansiformat
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
18 from pygments.util import get_choice_opt
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
19
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
20
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
21 __all__ = ['TerminalFormatter']
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
22
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
23
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
24 #: Map token types to a tuple of color values for light and dark
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
25 #: backgrounds.
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
26 TERMINAL_COLORS = {
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
27 Token: ('', ''),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
28
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
29 Whitespace: ('lightgray', 'darkgray'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
30 Comment: ('lightgray', 'darkgray'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
31 Comment.Preproc: ('teal', 'turquoise'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
32 Keyword: ('darkblue', 'blue'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
33 Keyword.Type: ('teal', 'turquoise'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
34 Operator.Word: ('purple', 'fuchsia'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
35 Name.Builtin: ('teal', 'turquoise'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
36 Name.Function: ('darkgreen', 'green'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
37 Name.Namespace: ('_teal_', '_turquoise_'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
38 Name.Class: ('_darkgreen_', '_green_'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
39 Name.Exception: ('teal', 'turquoise'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
40 Name.Decorator: ('darkgray', 'lightgray'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
41 Name.Variable: ('darkred', 'red'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
42 Name.Constant: ('darkred', 'red'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
43 Name.Attribute: ('teal', 'turquoise'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
44 Name.Tag: ('blue', 'blue'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
45 String: ('brown', 'brown'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
46 Number: ('darkblue', 'blue'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
47
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
48 Generic.Deleted: ('red', 'red'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
49 Generic.Inserted: ('darkgreen', 'green'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
50 Generic.Heading: ('**', '**'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
51 Generic.Subheading: ('*purple*', '*fuchsia*'),
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
52 Generic.Prompt: ('**', '**'),
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
53 Generic.Error: ('red', 'red'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
54
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
55 Error: ('_red_', '_red_'),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
56 }
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
57
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
58
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
59 class TerminalFormatter(Formatter):
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
60 r"""
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
61 Format tokens with ANSI color sequences, for output in a text console.
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
62 Color sequences are terminated at newlines, so that paging the output
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
63 works correctly.
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
64
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
65 The `get_style_defs()` method doesn't do anything special since there is
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
66 no support for common styles.
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
67
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
68 Options accepted:
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
69
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
70 `bg`
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
71 Set to ``"light"`` or ``"dark"`` depending on the terminal's background
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
72 (default: ``"light"``).
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
73
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
74 `colorscheme`
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
75 A dictionary mapping token types to (lightbg, darkbg) color names or
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
76 ``None`` (default: ``None`` = use builtin colorscheme).
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
77
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
78 `linenos`
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
79 Set to ``True`` to have line numbers on the terminal output as well
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
80 (default: ``False`` = no line numbers).
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
81 """
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
82 name = 'Terminal'
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
83 aliases = ['terminal', 'console']
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
84 filenames = []
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
85
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
86 def __init__(self, **options):
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
87 Formatter.__init__(self, **options)
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
88 self.darkbg = get_choice_opt(options, 'bg',
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
89 ['light', 'dark'], 'light') == 'dark'
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
90 self.colorscheme = options.get('colorscheme', None) or TERMINAL_COLORS
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
91 self.linenos = options.get('linenos', False)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
92 self._lineno = 0
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
93
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
94 def format(self, tokensource, outfile):
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
95 # hack: if the output is a terminal and has an encoding set,
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
96 # use that to avoid unicode encode problems
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
97 if not self.encoding and hasattr(outfile, "encoding") and \
6009
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
98 hasattr(outfile, "isatty") and outfile.isatty() and \
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
99 sys.version_info < (3,):
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
100 self.encoding = outfile.encoding
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
101 return Formatter.format(self, tokensource, outfile)
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
102
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
103 def _write_lineno(self, outfile):
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
104 self._lineno += 1
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
105 outfile.write("%s%04d: " % (self._lineno != 1 and '\n' or '', self._lineno))
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
106
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
107 def _get_color(self, ttype):
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
108 # self.colorscheme is a dict containing usually generic types, so we
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
109 # have to walk the tree of dots. The base Token type must be a key,
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
110 # even if it's empty string, as in the default above.
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
111 colors = self.colorscheme.get(ttype)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
112 while colors is None:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
113 ttype = ttype.parent
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
114 colors = self.colorscheme.get(ttype)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
115 return colors[self.darkbg]
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
116
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
117 def format_unencoded(self, tokensource, outfile):
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
118 if self.linenos:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
119 self._write_lineno(outfile)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
120
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
121 for ttype, value in tokensource:
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
122 color = self._get_color(ttype)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
123
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
124 for line in value.splitlines(True):
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
125 if color:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
126 outfile.write(ansiformat(color, line.rstrip('\n')))
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
127 else:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
128 outfile.write(line.rstrip('\n'))
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
129 if line.endswith('\n'):
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
130 if self.linenos:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
131 self._write_lineno(outfile)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
132 else:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
133 outfile.write('\n')
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
134
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
135 if self.linenos:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
136 outfile.write("\n")