Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/ui.py @ 36804:aa0fc12743c7
ui: adjust Windows workaround to new _readline() code
It's only needed when rawinput() is called. Also made it Py3 compatible.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 06 Mar 2018 02:42:37 -0600 |
parents | 9b513888ea23 |
children | 1527f40de3b3 |
comparison
equal
deleted
inserted
replaced
36803:9b513888ea23 | 36804:aa0fc12743c7 |
---|---|
1284 # prompt ' ' must exist; otherwise readline may delete entire line | 1284 # prompt ' ' must exist; otherwise readline may delete entire line |
1285 # - http://bugs.python.org/issue12833 | 1285 # - http://bugs.python.org/issue12833 |
1286 with self.timeblockedsection('stdio'): | 1286 with self.timeblockedsection('stdio'): |
1287 if usereadline: | 1287 if usereadline: |
1288 line = encoding.strtolocal(pycompat.rawinput(r' ')) | 1288 line = encoding.strtolocal(pycompat.rawinput(r' ')) |
1289 # When stdin is in binary mode on Windows, it can cause | |
1290 # raw_input() to emit an extra trailing carriage return | |
1291 if pycompat.oslinesep == b'\r\n' and line.endswith(b'\r'): | |
1292 line = line[:-1] | |
1289 else: | 1293 else: |
1290 self.fout.write(b' ') | 1294 self.fout.write(b' ') |
1291 self.fout.flush() | 1295 self.fout.flush() |
1292 line = self.fin.readline() | 1296 line = self.fin.readline() |
1293 if not line: | 1297 if not line: |
1294 raise EOFError | 1298 raise EOFError |
1295 if line.endswith(pycompat.oslinesep): | 1299 if line.endswith(pycompat.oslinesep): |
1296 line = line[:-len(pycompat.oslinesep)] | 1300 line = line[:-len(pycompat.oslinesep)] |
1297 | 1301 |
1298 # When stdin is in binary mode on Windows, it can cause | |
1299 # raw_input() to emit an extra trailing carriage return | |
1300 if pycompat.oslinesep == '\r\n' and line and line[-1] == '\r': | |
1301 line = line[:-1] | |
1302 return line | 1302 return line |
1303 | 1303 |
1304 def prompt(self, msg, default="y"): | 1304 def prompt(self, msg, default="y"): |
1305 """Prompt user with msg, read response. | 1305 """Prompt user with msg, read response. |
1306 If ui is not interactive, the default is returned. | 1306 If ui is not interactive, the default is returned. |