ui: keep the progress bar around when writing if stdout is not a tty
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 21 Mar 2023 14:29:35 +0000
changeset 50443 7f0f3b274d1e
parent 50433 e07dc1e7a454
child 50444 0729d011c542
ui: keep the progress bar around when writing if stdout is not a tty
mercurial/ui.py
--- 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)