mercurial/ui.py
changeset 50487 7f0f3b274d1e
parent 50253 444fa55f5dd2
child 50804 7f8f6fe13fa9
--- a/mercurial/ui.py	Fri Mar 10 11:20:18 2023 +0000
+++ b/mercurial/ui.py	Tue Mar 21 14:29:35 2023 +0000
@@ -1107,10 +1107,16 @@
     def fout(self):
         return self._fout
 
+    @util.propertycache
+    def _fout_is_a_tty(self):
+        self._isatty(self._fout)
+
     @fout.setter
     def fout(self, f):
         self._fout = f
         self._fmsgout, self._fmsgerr = _selectmsgdests(self)
+        if '_fout_is_a_tty' in vars(self):
+            del self._fout_is_a_tty
 
     @property
     def ferr(self):
@@ -1234,7 +1240,7 @@
             return
 
         # inlined _writenobuf() for speed
-        if not opts.get('keepprogressbar', False):
+        if not opts.get('keepprogressbar', self._fout_is_a_tty):
             self._progclear()
         msg = b''.join(args)
 
@@ -1273,7 +1279,7 @@
 
     def _writenobuf(self, dest, *args: bytes, **opts: _MsgOpts) -> None:
         # update write() as well if you touch this code
-        if not opts.get('keepprogressbar', False):
+        if not opts.get('keepprogressbar', self._fout_is_a_tty):
             self._progclear()
         msg = b''.join(args)