changeset 36794:fa53a1d1f16e

ui: do not try readline support if fin/fout aren't standard streams It's unlikely for a non-stdio stream to be a tty. Minimizing readline support makes it much simpler to work around the unicode input() function of Python 3. This also works on chg which duplicates client's tty to stdio fds.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 06 Mar 2018 02:32:26 -0600
parents eca1051e6c22
children 9b513888ea23
files mercurial/ui.py
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/ui.py	Tue Mar 06 02:28:59 2018 -0600
+++ b/mercurial/ui.py	Tue Mar 06 02:32:26 2018 -0600
@@ -1264,7 +1264,9 @@
         return i
 
     def _readline(self):
-        if self._isatty(self.fin):
+        usereadline = (self._isatty(self.fin) and self._isatty(self.fout)
+                       and util.isstdin(self.fin) and util.isstdout(self.fout))
+        if usereadline:
             try:
                 # magically add command line editing support, where
                 # available
@@ -1273,7 +1275,7 @@
                 readline.read_history_file
                 # windows sometimes raises something other than ImportError
             except Exception:
-                pass
+                usereadline = False
 
         # prompt ' ' must exist; otherwise readline may delete entire line
         # - http://bugs.python.org/issue12833