Mercurial > hg
comparison mercurial/ui.py @ 40538:c5e964f75bf7
ui: pass in file object to _writenobuf()
See the subsequent patches for why. The "if" block in _writenobuf() will
be removed soon.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 03 Nov 2018 17:56:17 +0900 |
parents | 25732c5678bc |
children | 04a9dd8da959 |
comparison
equal
deleted
inserted
replaced
40537:cbd251d479bb | 40538:c5e964f75bf7 |
---|---|
945 label = opts.get(r'label', '') | 945 label = opts.get(r'label', '') |
946 self._buffers[-1].extend(self.label(a, label) for a in args) | 946 self._buffers[-1].extend(self.label(a, label) for a in args) |
947 else: | 947 else: |
948 self._buffers[-1].extend(args) | 948 self._buffers[-1].extend(args) |
949 else: | 949 else: |
950 self._writenobuf(self._write, *args, **opts) | 950 self._writenobuf(self.fout, *args, **opts) |
951 | 951 |
952 def _writenobuf(self, write, *args, **opts): | 952 def _writenobuf(self, dest, *args, **opts): |
953 self._progclear() | 953 self._progclear() |
954 if dest is self.fout: | |
955 write = self._write | |
956 elif dest is self.ferr: | |
957 write = self._write_err | |
958 else: | |
959 raise error.ProgrammingError('unsupported file to write') | |
954 msg = b''.join(args) | 960 msg = b''.join(args) |
955 | 961 |
956 # opencode timeblockedsection because this is a critical path | 962 # opencode timeblockedsection because this is a critical path |
957 starttime = util.timer() | 963 starttime = util.timer() |
958 try: | 964 try: |
977 | 983 |
978 def write_err(self, *args, **opts): | 984 def write_err(self, *args, **opts): |
979 if self._bufferstates and self._bufferstates[-1][0]: | 985 if self._bufferstates and self._bufferstates[-1][0]: |
980 self.write(*args, **opts) | 986 self.write(*args, **opts) |
981 else: | 987 else: |
982 self._writenobuf(self._write_err, *args, **opts) | 988 self._writenobuf(self.ferr, *args, **opts) |
983 | 989 |
984 def _write_err(self, data): | 990 def _write_err(self, data): |
985 try: | 991 try: |
986 if True: | 992 if True: |
987 if not getattr(self.fout, 'closed', False): | 993 if not getattr(self.fout, 'closed', False): |
1341 If ui is not interactive, the default is returned. | 1347 If ui is not interactive, the default is returned. |
1342 """ | 1348 """ |
1343 if not self.interactive(): | 1349 if not self.interactive(): |
1344 self.write(msg, ' ', default or '', "\n") | 1350 self.write(msg, ' ', default or '', "\n") |
1345 return default | 1351 return default |
1346 self._writenobuf(self._write, msg, label='ui.prompt') | 1352 self._writenobuf(self.fout, msg, label='ui.prompt') |
1347 self.flush() | 1353 self.flush() |
1348 try: | 1354 try: |
1349 r = self._readline() | 1355 r = self._readline() |
1350 if not r: | 1356 if not r: |
1351 r = default | 1357 r = default |