Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/ui.py @ 40591:c2aea007130b
ui: add inner function to select write destination
I'm going to add a config knob to redirect any status messages to stderr.
This function helps to switch underlying file objects.
# no-check-commit because of existing write_err() function
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 03 Nov 2018 18:17:30 +0900 |
parents | 06e841e72523 |
children | d8997c5ce2ff |
comparison
equal
deleted
inserted
replaced
40590:06e841e72523 | 40591:c2aea007130b |
---|---|
911 else: | 911 else: |
912 self._bufferapplylabels = None | 912 self._bufferapplylabels = None |
913 | 913 |
914 return "".join(self._buffers.pop()) | 914 return "".join(self._buffers.pop()) |
915 | 915 |
916 def _isbuffered(self, dest): | |
917 if dest is self.fout: | |
918 return bool(self._buffers) | |
919 if dest is self.ferr: | |
920 return bool(self._bufferstates and self._bufferstates[-1][0]) | |
921 return False | |
922 | |
916 def canwritewithoutlabels(self): | 923 def canwritewithoutlabels(self): |
917 '''check if write skips the label''' | 924 '''check if write skips the label''' |
918 if self._buffers and not self._bufferapplylabels: | 925 if self._buffers and not self._bufferapplylabels: |
919 return True | 926 return True |
920 return self._colormode is None | 927 return self._colormode is None |
938 | 945 |
939 When labeling output for a specific command, a label of | 946 When labeling output for a specific command, a label of |
940 "cmdname.type" is recommended. For example, status issues | 947 "cmdname.type" is recommended. For example, status issues |
941 a label of "status.modified" for modified files. | 948 a label of "status.modified" for modified files. |
942 ''' | 949 ''' |
943 if self._buffers: | 950 self._write(self.fout, *args, **opts) |
951 | |
952 def write_err(self, *args, **opts): | |
953 self._write(self.ferr, *args, **opts) | |
954 | |
955 def _write(self, dest, *args, **opts): | |
956 if self._isbuffered(dest): | |
944 if self._bufferapplylabels: | 957 if self._bufferapplylabels: |
945 label = opts.get(r'label', '') | 958 label = opts.get(r'label', '') |
946 self._buffers[-1].extend(self.label(a, label) for a in args) | 959 self._buffers[-1].extend(self.label(a, label) for a in args) |
947 else: | 960 else: |
948 self._buffers[-1].extend(args) | 961 self._buffers[-1].extend(args) |
949 else: | 962 else: |
950 self._writenobuf(self.fout, *args, **opts) | 963 self._writenobuf(dest, *args, **opts) |
951 | 964 |
952 def _writenobuf(self, dest, *args, **opts): | 965 def _writenobuf(self, dest, *args, **opts): |
953 self._progclear() | 966 self._progclear() |
954 msg = b''.join(args) | 967 msg = b''.join(args) |
955 | 968 |
979 raise error.StdioError(err) | 992 raise error.StdioError(err) |
980 finally: | 993 finally: |
981 self._blockedtimes['stdio_blocked'] += \ | 994 self._blockedtimes['stdio_blocked'] += \ |
982 (util.timer() - starttime) * 1000 | 995 (util.timer() - starttime) * 1000 |
983 | 996 |
984 def write_err(self, *args, **opts): | |
985 if self._bufferstates and self._bufferstates[-1][0]: | |
986 self.write(*args, **opts) | |
987 else: | |
988 self._writenobuf(self.ferr, *args, **opts) | |
989 | |
990 def flush(self): | 997 def flush(self): |
991 # opencode timeblockedsection because this is a critical path | 998 # opencode timeblockedsection because this is a critical path |
992 starttime = util.timer() | 999 starttime = util.timer() |
993 try: | 1000 try: |
994 try: | 1001 try: |