[PATCH 2 of 4] Implement local prompt in terms of ui.prompt

John Goerzen jgoerzen at complete.org
Wed Mar 21 22:59:07 CDT 2007


# HG changeset patch
# User John Goerzen <jgoerzen at complete.org>
# Date 1174535734 18000
# Node ID d44a7fcfe7078cc60b23a03ce69b0d9b57314a6e
# Parent  60ec27d55e7ca3a4b1037fc69b8e0a616848e09d
Implement local prompt in terms of ui.prompt

diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -69,13 +69,6 @@ from mercurial.i18n import _
 from mercurial.i18n import _
 from mercurial.node import *
 
-try:
-    # readline gives raw_input editing capabilities, but is not
-    # present on windows
-    import readline
-except ImportError:
-    pass
-
 def patchbomb(ui, repo, *revs, **opts):
     '''send changesets as a series of patch emails
 
@@ -88,22 +81,22 @@ def patchbomb(ui, repo, *revs, **opts):
     the changeset description.  Next, (optionally) if the diffstat
     program is installed, the result of running diffstat on the patch.
     Finally, the patch itself, as generated by "hg export".'''
-    def prompt(prompt, default = None, rest = ': ', empty_ok = False):
-        if default:
+    def prompt(prompt, default = None, rest = ':', empty_ok = False):
+        if default is not None:
             prompt += ' [%s]' % default
         prompt += rest
-        while True:
-            r = raw_input(prompt)
-            if r:
-                return r
-            if default is not None:
-                return default
-            if empty_ok:
-                return r
-            ui.warn(_('Please enter a valid value.\n'))
+        if empty_ok or default is not None:
+            pat = None
+        else:
+            pat = "."
+
+        r = ui.prompt(prompt, pat, default)
+        if not r:
+            return default
+        return r
 
     def confirm(s):
-        if not prompt(s, default = 'y', rest = '? ').lower().startswith('y'):
+        if not prompt(s, default = 'y', rest = '?').lower().startswith('y'):
             raise ValueError
 
     def cdiffstat(summary, patchlines):
@@ -233,7 +226,7 @@ def patchbomb(ui, repo, *revs, **opts):
             tlen, 0,
             len(patches),
             opts['subject'] or
-            prompt('Subject:', rest = ' [PATCH %0*d of %d] ' % (tlen, 0,
+            prompt('Subject:', rest = ' [PATCH %0*d of %d]' % (tlen, 0,
                 len(patches))))
 
         body = ''


More information about the Mercurial-devel mailing list