comparison mercurial/ui.py @ 40521:49746e53ac92

ui: simplify interface of low-level write() functions _write() and _write_err() will be replaced with fout.write() and ferr.write() respectively. This is the first step.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 03 Nov 2018 17:36:10 +0900
parents fd60c2afb484
children 51091816a355
comparison
equal deleted inserted replaced
40520:fd60c2afb484 40521:49746e53ac92
958 else: 958 else:
959 msgs = args 959 msgs = args
960 if self._colormode is not None: 960 if self._colormode is not None:
961 label = opts.get(r'label', '') 961 label = opts.get(r'label', '')
962 msgs = [self.label(a, label) for a in args] 962 msgs = [self.label(a, label) for a in args]
963 write(*msgs, **opts) 963 write(b''.join(msgs))
964 964
965 def _write(self, *msgs, **opts): 965 def _write(self, data):
966 # opencode timeblockedsection because this is a critical path 966 # opencode timeblockedsection because this is a critical path
967 starttime = util.timer() 967 starttime = util.timer()
968 try: 968 try:
969 self.fout.write(''.join(msgs)) 969 self.fout.write(data)
970 except IOError as err: 970 except IOError as err:
971 raise error.StdioError(err) 971 raise error.StdioError(err)
972 finally: 972 finally:
973 self._blockedtimes['stdio_blocked'] += \ 973 self._blockedtimes['stdio_blocked'] += \
974 (util.timer() - starttime) * 1000 974 (util.timer() - starttime) * 1000
977 if self._bufferstates and self._bufferstates[-1][0]: 977 if self._bufferstates and self._bufferstates[-1][0]:
978 self.write(*args, **opts) 978 self.write(*args, **opts)
979 else: 979 else:
980 self._writenobuf(self._write_err, *args, **opts) 980 self._writenobuf(self._write_err, *args, **opts)
981 981
982 def _write_err(self, *msgs, **opts): 982 def _write_err(self, data):
983 try: 983 try:
984 with self.timeblockedsection('stdio'): 984 with self.timeblockedsection('stdio'):
985 if not getattr(self.fout, 'closed', False): 985 if not getattr(self.fout, 'closed', False):
986 self.fout.flush() 986 self.fout.flush()
987 for a in msgs: 987 self.ferr.write(data)
988 self.ferr.write(a)
989 # stderr may be buffered under win32 when redirected to files, 988 # stderr may be buffered under win32 when redirected to files,
990 # including stdout. 989 # including stdout.
991 if not getattr(self.ferr, 'closed', False): 990 if not getattr(self.ferr, 'closed', False):
992 self.ferr.flush() 991 self.ferr.flush()
993 except IOError as inst: 992 except IOError as inst: