[issue792] interactive output (especially prompts) should always go to stderr

Daniel Holth mercurial-bugs at selenic.com
Wed Oct 24 13:13:24 CDT 2007


New submission from Daniel Holth <dholth at fastmail.fm>:

It would make scripting Mercurial much easier. Here is a sample patch, but it
would probably be better to reimplement the prompt function so readline can
print the prompt to stderr.

diff --git a/mercurial/httprepo.py b/mercurial/httprepo.py
--- a/mercurial/httprepo.py
+++ b/mercurial/httprepo.py
@@ -27,7 +27,7 @@ class passwordmgr(urllib2.HTTPPasswordMg
         if not self.ui.interactive:
             raise util.Abort(_('http authorization required'))

-        self.ui.write(_("http authorization required\n"))
+        self.ui.write_err(_("http authorization required\n"))
         self.ui.status(_("realm: %s\n") % realm)
         if user:
             self.ui.status(_("user: %s\n") % user)
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -403,7 +403,8 @@ class ui(object):
                 readline.read_history_file
             except ImportError:
                 pass
-        return raw_input(prompt)
+        self.write_err(prompt)
+        return raw_input()

     def prompt(self, msg, pat=None, default="y", matchflags=0):
         if not self.interactive: return default
@@ -418,7 +419,9 @@ class ui(object):

     def getpass(self, prompt=None, default=None):
         if not self.interactive: return default
-        return getpass.getpass(prompt or _('password: '))
+
+        self.write_err(prompt or _('password: '))
+        return getpass.getpass('')
     def status(self, *msg):
         if not self.quiet: self.write(*msg)
     def warn(self, *msg):

----------
messages: 4176
nosy: dholth
priority: feature
status: unread
title: interactive output (especially prompts) should always go to stderr

____________________________________________________
Mercurial issue tracker <mercurial-bugs at selenic.com>
<http://www.selenic.com/mercurial/bts/issue792>
____________________________________________________



More information about the Mercurial-devel mailing list