D6168: readline: provide styled prompt to readline (issue6070)
durin42 (Augie Fackler)
phabricator at mercurial-scm.org
Fri Mar 22 15:06:14 UTC 2019
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D6168
AFFECTED FILES
mercurial/ui.py
CHANGE DETAILS
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=' '):
# 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
@@ -1450,13 +1450,13 @@
# - 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 +1478,14 @@
self._writemsg(self._fmsgout, default or '', "\n",
type='promptecho')
return default
- self._writemsgnobuf(self._fmsgout, msg, type='prompt', **opts)
- self.flush()
+ if self._colormode == 'win32':
+ readline_prompt = ' '
+ self._writemsgnobuf(self._fmsgout, msg, type='prompt', **opts)
+ self.flush()
+ else:
+ readline_prompt = self.label(msg, 'ui.prompt') + ' '
try:
- r = self._readline()
+ r = self._readline(prompt=readline_prompt)
if not r:
r = default
if self.configbool('ui', 'promptecho'):
To: durin42, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list