From 0c61e02a705ccf124b04d2b5367a0ee7f5c48b3d Mon Sep 17 00:00:00 2001 From: Caio Prado Date: Tue, 27 Aug 2019 17:34:07 +0800 Subject: [PATCH] Fix '--color always' option when not stdout output Bug: If not stdout, program will auto-detect terminfo capabilities despite the choice regarding the `--color` command line argument. Because of this, terminfo terminal is never initialized and the program breaks when trying to output any color code. This change forces terminfo proper initialization if `--color always` is requested, even if `os.isatty()` is `False`. --- latexrun | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/latexrun b/latexrun index b669d9f..013d22f 100755 --- a/latexrun +++ b/latexrun @@ -384,11 +384,16 @@ hash_cache = HashCache() class _Terminfo: def __init__(self): - self.__tty = os.isatty(sys.stdout.fileno()) - if self.__tty: - curses.setupterm() + self.__tty = False + if os.isatty(sys.stdout.fileno()): + self.setupterm() self.__ti = {} + def setupterm(self): + if not self.__tty: + self.__tty = True + curses.setupterm() + def __ensure(self, cap): if cap not in self.__ti: if not self.__tty: @@ -484,6 +489,7 @@ class Message(collections.namedtuple( cls._color = False elif state == 'always': cls._color = True + terminfo.setupterm() elif state == 'auto': cls._color = terminfo.has('setaf', 'bold', 'sgr0') else: