diff options
author | Georg Brandl <georg@python.org> | 2014-10-07 15:04:45 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-10-07 15:04:45 +0200 |
commit | f32c46a5b907553962d68cd7ce637729cd7dd45b (patch) | |
tree | 44a03d08970c60d4160d3b02c108a895a3674036 /pygments/cmdline.py | |
parent | b977e2e3e21e64a758bf35acfe38fc47158e38b5 (diff) | |
download | pygments-f32c46a5b907553962d68cd7ce637729cd7dd45b.tar.gz |
Closes #963: always guess lexer when reading from stdin.
Diffstat (limited to 'pygments/cmdline.py')
-rw-r--r-- | pygments/cmdline.py | 16 |
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 |