summaryrefslogtreecommitdiff
path: root/pygments/cmdline.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-10-07 15:04:45 +0200
committerGeorg Brandl <georg@python.org>2014-10-07 15:04:45 +0200
commitf32c46a5b907553962d68cd7ce637729cd7dd45b (patch)
tree44a03d08970c60d4160d3b02c108a895a3674036 /pygments/cmdline.py
parentb977e2e3e21e64a758bf35acfe38fc47158e38b5 (diff)
downloadpygments-f32c46a5b907553962d68cd7ce637729cd7dd45b.tar.gz
Closes #963: always guess lexer when reading from stdin.
Diffstat (limited to 'pygments/cmdline.py')
-rw-r--r--pygments/cmdline.py16
1 files changed, 5 insertions, 11 deletions
diff --git a/pygments/cmdline.py b/pygments/cmdline.py
index b6e83c24..c00e5974 100644
--- a/pygments/cmdline.py
+++ b/pygments/cmdline.py
@@ -409,21 +409,15 @@ def main(args=sys.argv):
return 1
else:
- if '-g' in opts:
- code = sys.stdin.read()
+ code = sys.stdin.read()
+ if not isinstance(code, text_type):
+ # Python 2; Python 3's terminal is already fine
+ code = code.decode(_get_termencoding()[0])
+ if not lexer:
try:
lexer = guess_lexer(code, **parsed_opts)
except ClassNotFound:
lexer = TextLexer(**parsed_opts)
- elif not lexer:
- print('Error: no lexer name given and reading '
- 'from stdin (try using -g or -l <lexer>)', file=sys.stderr)
- return 2
- else:
- code = sys.stdin.read()
- if not isinstance(code, text_type):
- # Python 2; Python 3's terminal is already fine
- code = code.decode(_get_termencoding()[0])
# When using the LaTeX formatter and the option `escapeinside` is
# specified, we need a special lexer which collects escaped text