Source

Pygments Queue / auto-term256.diff

# HG changeset patch
# Parent 61d106092548d54b36fa4d86e7cb63b3dc8eefce
# User Dan Villiom Podlaski Christiansen  <danchr@gmail.com>
Use the terminal256 formatter by default under a *-color256 terminal.

diff --git a/pygments/cmdline.py b/pygments/cmdline.py
--- a/pygments/cmdline.py
+++ b/pygments/cmdline.py
@@ -8,6 +8,7 @@
     :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
     :license: BSD, see LICENSE for details.
 """
+import os
 import sys
 import getopt
 from textwrap import dedent
@@ -18,7 +19,7 @@ from pygments.lexers import get_all_lexe
      find_lexer_class, guess_lexer, TextLexer
 from pygments.formatters import get_all_formatters, get_formatter_by_name, \
      get_formatter_for_filename, find_formatter_class, \
-     TerminalFormatter  # pylint:disable-msg=E0611
+     TerminalFormatter, Terminal256Formatter  # pylint:disable-msg=E0611
 from pygments.filters import get_all_filters, find_filter_class
 from pygments.styles import get_all_styles, get_style_by_name
 
@@ -340,7 +341,10 @@ def main(args=sys.argv):
             return 1
     else:
         if not fmter:
-            fmter = TerminalFormatter(**parsed_opts)
+            if os.getenv('TERM', '').endswith('-256color'):
+                fmter = Terminal256Formatter(**parsed_opts)
+            else:
+                fmter = TerminalFormatter(**parsed_opts)
         outfile = sys.stdout
 
     # select lexer