[PATCH 3 of 6] move: move the 'label' method to the core class

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Feb 24 11:34:15 EST 2017



On 02/23/2017 03:09 PM, Yuya Nishihara wrote:
> On Wed, 22 Feb 2017 17:54:34 +0100, Pierre-Yves David wrote:
>> # HG changeset patch
>> # User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
>> # Date 1487590284 -3600
>> #      Mon Feb 20 12:31:24 2017 +0100
>> # Node ID 9a9e8b28b717e30ed43030cc64f115a4356193de
>> # Parent  f53e95ec986616a48a3a8e67e5a9674b8a684d6e
>> # EXP-Topic color
>> move: move the 'label' method to the core class
>>
>> We move 'label' method from the custom 'colorui' class to the core 'ui' class.
>> This bring us closer to supporting color in core natively. Core already have a
>> 'label' method that was a no-op. We update its content with the logic from the
>> extension. Behavior is unchanged when colormode = None.
>
> It's nice to move color functions into core and get rid of the colorui class,
> but I also think we should avoid making ui.py bloated. So, instead of moving
> everything into ui.py, can we put them in color.py as module-level functions?

That make sense, I've moved the label computation in the 'color' module 
since it make heavy refence of color specific parts. On the other hand, 
the new "write" part are not too color specific. They only add reference 
and call to "label", something already part of the top level color API 
so I think i make sense to keep it here.

Finally, poking at turning the unix part into the same thing as win32 
made me realize that may translation was wrote, win32 really need to 
access ui.write* , not just ui.f*.write. V2 will extract the lower level 
function writing to the stream so that we can reuse it properly.

Cheers,

>
> For instance,
>
>   def label(self, msg, label):
>       if self._colormode:
>           msg = color.labeledstr(self._colormode, msg, label)
>       return msg
>
>   def write(self, *args, **opts):
>       ...
>       if self._colormode:
>           color.writelabeled(self._colormode, self.fout, *args, **opts)
>

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list