summaryrefslogtreecommitdiff
path: root/pygments/formatters/terminal.py
diff options
context:
space:
mode:
authorgbrandl <devnull@localhost>2007-01-25 20:00:35 +0100
committergbrandl <devnull@localhost>2007-01-25 20:00:35 +0100
commit1699701fd132c19974be66c5664a88a90a32a3d2 (patch)
tree7163ddc984cb36c862979a5f5f86bc4a4e85eaff /pygments/formatters/terminal.py
parent8661de37c9a04da977fd8da8542e36115ee83fb2 (diff)
downloadpygments-1699701fd132c19974be66c5664a88a90a32a3d2.tar.gz
[svn] - add missing example files
- add "outencoding" option to formatters - improve cmdline error reporting
Diffstat (limited to 'pygments/formatters/terminal.py')
-rw-r--r--pygments/formatters/terminal.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/pygments/formatters/terminal.py b/pygments/formatters/terminal.py
index 661031e7..6ac6cd1b 100644
--- a/pygments/formatters/terminal.py
+++ b/pygments/formatters/terminal.py
@@ -9,6 +9,8 @@
:license: BSD, see LICENSE for more details.
"""
+import os
+
from pygments.formatter import Formatter
from pygments.token import Keyword, Name, Comment, String, Error, \
Number, Operator, Generic, Token
@@ -77,6 +79,11 @@ class TerminalFormatter(Formatter):
def format(self, tokensource, outfile):
enc = self.encoding
+ # hack: if the output is a terminal and has an encoding set,
+ # use that to avoid unicode encode problems
+ if not enc and hasattr(outfile, "encoding") and \
+ hasattr(outfile, "isatty") and outfile.isatty():
+ enc = outfile.encoding
for ttype, value in tokensource:
if enc:
value = value.encode(enc)