Mercurial > public > mercurial-scm > hg
comparison mercurial/ui.py @ 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 | 30742c216abb |
children | 9b513888ea23 |
comparison
equal
deleted
inserted
replaced
36793:eca1051e6c22 | 36794:fa53a1d1f16e |
---|---|
1262 return self._isatty(self.fout) | 1262 return self._isatty(self.fout) |
1263 | 1263 |
1264 return i | 1264 return i |
1265 | 1265 |
1266 def _readline(self): | 1266 def _readline(self): |
1267 if self._isatty(self.fin): | 1267 usereadline = (self._isatty(self.fin) and self._isatty(self.fout) |
1268 and util.isstdin(self.fin) and util.isstdout(self.fout)) | |
1269 if usereadline: | |
1268 try: | 1270 try: |
1269 # magically add command line editing support, where | 1271 # magically add command line editing support, where |
1270 # available | 1272 # available |
1271 import readline | 1273 import readline |
1272 # force demandimport to really load the module | 1274 # force demandimport to really load the module |
1273 readline.read_history_file | 1275 readline.read_history_file |
1274 # windows sometimes raises something other than ImportError | 1276 # windows sometimes raises something other than ImportError |
1275 except Exception: | 1277 except Exception: |
1276 pass | 1278 usereadline = False |
1277 | 1279 |
1278 # prompt ' ' must exist; otherwise readline may delete entire line | 1280 # prompt ' ' must exist; otherwise readline may delete entire line |
1279 # - http://bugs.python.org/issue12833 | 1281 # - http://bugs.python.org/issue12833 |
1280 with self.timeblockedsection('stdio'): | 1282 with self.timeblockedsection('stdio'): |
1281 sin, sout = sys.stdin, sys.stdout | 1283 sin, sout = sys.stdin, sys.stdout |