Patchwork [7,of,8] ui: adjust Windows workaround to new _readline() code

login
register
mail settings
Submitter Yuya Nishihara
Date March 9, 2018, 12:35 p.m.
Message ID <5ee522c20bc237012480.1520598940@mimosa>
Download mbox | patch
Permalink /patch/29167/
State Accepted
Headers show

Comments

Yuya Nishihara - March 9, 2018, 12:35 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1520325757 21600
#      Tue Mar 06 02:42:37 2018 -0600
# Node ID 5ee522c20bc23701248014fa18e90f691f00aec8
# Parent  ad7ff97565b261d82952acc9f941e5dd99f11374
ui: adjust Windows workaround to new _readline() code

It's only needed when rawinput() is called. Also made it Py3 compatible.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1286,6 +1286,10 @@  class ui(object):
         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 @@  class ui(object):
                 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"):