Patchwork ui: add brief comment why raw_input() needs dummy ' ' prompt string

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 24, 2014, 4:57 a.m.
Message ID <6eec2f3116ab5ab02fe3.1408856261@mimosa>
Download mbox | patch
Permalink /patch/5566/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 24, 2014, 4:57 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1408851353 -32400
#      Sun Aug 24 12:35:53 2014 +0900
# Node ID 6eec2f3116ab5ab02fe3b6ed026e34df265ffdb8
# Parent  90cf454edd709c616d1e5ea4f30fb4d02f0c01a4
ui: add brief comment why raw_input() needs dummy ' ' prompt string

Retrieved from 17ffb30d9174.

I was about to move ' ' to label(msg + ' ', 'ui.prompt') so that subclass can
distinguish prompt output from data.  But it was not that simple.
Augie Fackler - Aug. 26, 2014, 7:17 p.m.
On Sun, Aug 24, 2014 at 01:57:41PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1408851353 -32400
> #      Sun Aug 24 12:35:53 2014 +0900
> # Node ID 6eec2f3116ab5ab02fe3b6ed026e34df265ffdb8
> # Parent  90cf454edd709c616d1e5ea4f30fb4d02f0c01a4
> ui: add brief comment why raw_input() needs dummy ' ' prompt string

Queued, thanks

>
> Retrieved from 17ffb30d9174.
>
> I was about to move ' ' to label(msg + ' ', 'ui.prompt') so that subclass can
> distinguish prompt output from data.  But it was not that simple.
>
> diff --git a/mercurial/ui.py b/mercurial/ui.py
> --- a/mercurial/ui.py
> +++ b/mercurial/ui.py
> @@ -626,6 +626,8 @@ class ui(object):
>          oldout = sys.stdout
>          sys.stdin = self.fin
>          sys.stdout = self.fout
> +        # prompt ' ' must exist; otherwise readline may delete entire line
> +        # - http://bugs.python.org/issue12833
>          line = raw_input(' ')
>          sys.stdin = oldin
>          sys.stdout = oldout
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -626,6 +626,8 @@  class ui(object):
         oldout = sys.stdout
         sys.stdin = self.fin
         sys.stdout = self.fout
+        # prompt ' ' must exist; otherwise readline may delete entire line
+        # - http://bugs.python.org/issue12833
         line = raw_input(' ')
         sys.stdin = oldin
         sys.stdout = oldout