##// END OF EJS Templates
readline: provide styled prompt to readline (issue6070)...
Kyle Lippincott -
r42288:2d428b85 default
parent child Browse files
Show More
@@ -1430,7 +1430,7 b' class ui(object):'
1430
1430
1431 return i
1431 return i
1432
1432
1433 def _readline(self):
1433 def _readline(self, prompt=' ', promptopts=None):
1434 # Replacing stdin/stdout temporarily is a hard problem on Python 3
1434 # Replacing stdin/stdout temporarily is a hard problem on Python 3
1435 # because they have to be text streams with *no buffering*. Instead,
1435 # because they have to be text streams with *no buffering*. Instead,
1436 # we use rawinput() only if call_readline() will be invoked by
1436 # we use rawinput() only if call_readline() will be invoked by
@@ -1449,17 +1449,27 b' class ui(object):'
1449 except Exception:
1449 except Exception:
1450 usereadline = False
1450 usereadline = False
1451
1451
1452 if self._colormode == 'win32' or not usereadline:
1453 if not promptopts:
1454 promptopts = {}
1455 self._writemsgnobuf(self._fmsgout, prompt, type='prompt',
1456 **promptopts)
1457 self.flush()
1458 prompt = ' '
1459 else:
1460 prompt = self.label(prompt, 'ui.prompt') + ' '
1461
1452 # prompt ' ' must exist; otherwise readline may delete entire line
1462 # prompt ' ' must exist; otherwise readline may delete entire line
1453 # - http://bugs.python.org/issue12833
1463 # - http://bugs.python.org/issue12833
1454 with self.timeblockedsection('stdio'):
1464 with self.timeblockedsection('stdio'):
1455 if usereadline:
1465 if usereadline:
1456 line = encoding.strtolocal(pycompat.rawinput(r' '))
1466 line = encoding.strtolocal(pycompat.rawinput(prompt))
1457 # When stdin is in binary mode on Windows, it can cause
1467 # When stdin is in binary mode on Windows, it can cause
1458 # raw_input() to emit an extra trailing carriage return
1468 # raw_input() to emit an extra trailing carriage return
1459 if pycompat.oslinesep == b'\r\n' and line.endswith(b'\r'):
1469 if pycompat.oslinesep == b'\r\n' and line.endswith(b'\r'):
1460 line = line[:-1]
1470 line = line[:-1]
1461 else:
1471 else:
1462 self._fout.write(b' ')
1472 self._fout.write(pycompat.bytestr(prompt))
1463 self._fout.flush()
1473 self._fout.flush()
1464 line = self._fin.readline()
1474 line = self._fin.readline()
1465 if not line:
1475 if not line:
@@ -1481,10 +1491,8 b' class ui(object):'
1481 self._writemsg(self._fmsgout, default or '', "\n",
1491 self._writemsg(self._fmsgout, default or '', "\n",
1482 type='promptecho')
1492 type='promptecho')
1483 return default
1493 return default
1484 self._writemsgnobuf(self._fmsgout, msg, type='prompt', **opts)
1485 self.flush()
1486 try:
1494 try:
1487 r = self._readline()
1495 r = self._readline(prompt=msg, promptopts=opts)
1488 if not r:
1496 if not r:
1489 r = default
1497 r = default
1490 if self.configbool('ui', 'promptecho'):
1498 if self.configbool('ui', 'promptecho'):
General Comments 0
You need to be logged in to leave comments. Login now