changeset 36796: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 d4c760c997cd
files mercurial/ui.py
diffstat 1 files changed, 4 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/ui.py	Tue Mar 06 02:38:53 2018 -0600
+++ b/mercurial/ui.py	Tue Mar 06 02:42:37 2018 -0600
@@ -1286,6 +1286,10 @@
         with self.timeblockedsection('stdio'):
             if usereadline:
                 line = encoding.strtolocal(pycompat.rawinput(r' '))
+                # When stdin is in binary mode on Windows, it can cause
+                # raw_input() to emit an extra trailing carriage return
+                if pycompat.oslinesep == b'\r\n' and line.endswith(b'\r'):
+                    line = line[:-1]
             else:
                 self.fout.write(b' ')
                 self.fout.flush()
@@ -1295,10 +1299,6 @@
                 if line.endswith(pycompat.oslinesep):
                     line = line[:-len(pycompat.oslinesep)]
 
-        # When stdin is in binary mode on Windows, it can cause
-        # raw_input() to emit an extra trailing carriage return
-        if pycompat.oslinesep == '\r\n' and line and line[-1] == '\r':
-            line = line[:-1]
         return line
 
     def prompt(self, msg, default="y"):