Patchwork D6168: readline: provide styled prompt to readline (issue6070)

login
register
mail settings
Submitter phabricator
Date April 15, 2019, 9:31 p.m.
Message ID <ebfe8e5643ed2ec8b5aee1e7878a4c41@localhost.localdomain>
Download mbox | patch
Permalink /patch/39616/
State Not Applicable
Headers show

Comments

phabricator - April 15, 2019, 9:31 p.m.
spectral updated this revision to Diff 14746.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6168?vs=14582&id=14746

REVISION DETAIL
  https://phab.mercurial-scm.org/D6168

AFFECTED FILES
  mercurial/exthelper.py
  mercurial/ui.py

CHANGE DETAILS




To: durin42, #hg-reviewers, jeffpc, yuja
Cc: martinvonz, jeffpc, spectral, mercurial-devel

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1427,7 +1427,7 @@ 
 
         return i
 
-    def _readline(self):
+    def _readline(self, prompt=' ', promptopts=None):
         # Replacing stdin/stdout temporarily is a hard problem on Python 3
         # because they have to be text streams with *no buffering*. Instead,
         # we use rawinput() only if call_readline() will be invoked by
@@ -1446,17 +1446,27 @@ 
             except Exception:
                 usereadline = False
 
+        if self._colormode == 'win32' or not usereadline:
+            if not promptopts:
+                promptopts = {}
+            self._writemsgnobuf(self._fmsgout, prompt, type='prompt',
+                                **promptopts)
+            self.flush()
+            prompt = ' '
+        else:
+            prompt = self.label(prompt, 'ui.prompt') + ' '
+
         # prompt ' ' must exist; otherwise readline may delete entire line
         # - http://bugs.python.org/issue12833
         with self.timeblockedsection('stdio'):
             if usereadline:
-                line = encoding.strtolocal(pycompat.rawinput(r' '))
+                line = encoding.strtolocal(pycompat.rawinput(prompt))
                 # 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.write(pycompat.bytestr(prompt))
                 self._fout.flush()
                 line = self._fin.readline()
                 if not line:
@@ -1478,10 +1488,8 @@ 
             self._writemsg(self._fmsgout, default or '', "\n",
                            type='promptecho')
             return default
-        self._writemsgnobuf(self._fmsgout, msg, type='prompt', **opts)
-        self.flush()
         try:
-            r = self._readline()
+            r = self._readline(prompt=msg, opts=opts)
             if not r:
                 r = default
             if self.configbool('ui', 'promptecho'):
diff --git a/mercurial/exthelper.py b/mercurial/exthelper.py
--- a/mercurial/exthelper.py
+++ b/mercurial/exthelper.py
@@ -18,6 +18,8 @@ 
     registrar,
 )
 
+from hgdemandimport import tracing
+
 class exthelper(object):
     """Helper for modular extension setup
 
@@ -187,7 +189,8 @@ 
         - Changes to repo.__class__, repo.dirstate.__class__
         """
         for c in self._repocallables:
-            c(ui, repo)
+            with tracing.log('%s.%s', c.__module__, c.__name__):
+                c(ui, repo)
 
     def uisetup(self, call):
         """Decorated function will be executed during uisetup