Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/ui.py @ 31108:ad074f900907
color: move 'write' logic to the core ui class
One more step, the support for writing color is not directly in core. No
behavior change for the default case ('_colormode' = None).
Here are the details of what we have to change to the core method:
* apply to 'self.label' to input in the buffered case
* dispatch to 'win32print' when applicable
* apply to 'self.label' to input when applicable
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Mon, 20 Feb 2017 12:31:39 +0100 |
parents | e9f96ccf36a6 |
children | cb759f7f940d |
comparison
equal
deleted
inserted
replaced
31107:e9f96ccf36a6 | 31108:ad074f900907 |
---|---|
777 return "".join(self._buffers.pop()) | 777 return "".join(self._buffers.pop()) |
778 | 778 |
779 def write(self, *args, **opts): | 779 def write(self, *args, **opts): |
780 '''write args to output | 780 '''write args to output |
781 | 781 |
782 By default, this method simply writes to the buffer or stdout, | 782 By default, this method simply writes to the buffer or stdout. |
783 but extensions or GUI tools may override this method, | 783 Color mode can be set on the UI class to have the output decorated |
784 write_err(), popbuffer(), and label() to style output from | 784 with color modifier before being written to stdout. |
785 various parts of hg. | 785 |
786 | 786 The color used is controlled by an optional keyword argument, "label". |
787 An optional keyword argument, "label", can be passed in. | 787 This should be a string containing label names separated by space. |
788 This should be a string containing label names separated by | 788 Label names take the form of "topic.type". For example, ui.debug() |
789 space. Label names take the form of "topic.type". For example, | 789 issues a label of "ui.debug". |
790 ui.debug() issues a label of "ui.debug". | |
791 | 790 |
792 When labeling output for a specific command, a label of | 791 When labeling output for a specific command, a label of |
793 "cmdname.type" is recommended. For example, status issues | 792 "cmdname.type" is recommended. For example, status issues |
794 a label of "status.modified" for modified files. | 793 a label of "status.modified" for modified files. |
795 ''' | 794 ''' |
796 if self._buffers and not opts.get('prompt', False): | 795 if self._buffers and not opts.get('prompt', False): |
797 self._buffers[-1].extend(a for a in args) | 796 if self._bufferapplylabels: |
797 label = opts.get('label', '') | |
798 self._buffers[-1].extend(self.label(a, label) for a in args) | |
799 else: | |
800 self._buffers[-1].extend(args) | |
801 elif self._colormode == 'win32': | |
802 # windows color printing is its own can of crab, defer to | |
803 # the color module and that is it. | |
804 color.win32print(self._write, *args, **opts) | |
798 else: | 805 else: |
799 self._write(*args, **opts) | 806 msgs = args |
807 if self._colormode is not None: | |
808 label = opts.get('label', '') | |
809 msgs = [self.label(a, label) for a in args] | |
810 self._write(*msgs, **opts) | |
800 | 811 |
801 def _write(self, *msgs, **opts): | 812 def _write(self, *msgs, **opts): |
802 self._progclear() | 813 self._progclear() |
803 # opencode timeblockedsection because this is a critical path | 814 # opencode timeblockedsection because this is a critical path |
804 starttime = util.timer() | 815 starttime = util.timer() |