mercurial/utils/procutil.py
changeset 45039 2bfbd7d2c204
parent 45000 3fadbdc47aed
child 45040 fd205a9c358a
equal deleted inserted replaced
45038:c7d109c400a4 45039:2bfbd7d2c204
    47         return fp.isatty()
    47         return fp.isatty()
    48     except AttributeError:
    48     except AttributeError:
    49         return False
    49         return False
    50 
    50 
    51 
    51 
    52 if pycompat.ispy3:
    52 class LineBufferedWrapper(object):
    53 
    53     def __init__(self, orig):
    54     class LineBufferedWrapper(object):
    54         self.orig = orig
    55         def __init__(self, orig):
    55 
    56             self.orig = orig
    56     def __getattr__(self, attr):
    57 
    57         return getattr(self.orig, attr)
    58         def __getattr__(self, attr):
    58 
    59             return getattr(self.orig, attr)
    59     def write(self, s):
    60 
    60         orig = self.orig
    61         def write(self, s):
    61         res = orig.write(s)
    62             orig = self.orig
    62         if s.endswith(b'\n'):
    63             res = orig.write(s)
    63             orig.flush()
    64             if s.endswith(b'\n'):
    64         return res
    65                 orig.flush()
    65 
    66             return res
    66 
    67 
    67 io.BufferedIOBase.register(LineBufferedWrapper)
    68     io.BufferedIOBase.register(LineBufferedWrapper)
       
    69 
    68 
    70 
    69 
    71 # glibc determines buffering on first write to stdout - if we replace a TTY
    70 # glibc determines buffering on first write to stdout - if we replace a TTY
    72 # destined stdout with a pipe destined stdout (e.g. pager), we want line
    71 # destined stdout with a pipe destined stdout (e.g. pager), we want line
    73 # buffering (or unbuffered, on Windows)
    72 # buffering (or unbuffered, on Windows)