Commit Graph

214 Commits

Author SHA1 Message Date
Matt Harbison
ca74aac810 color: fix grammar in help text 2017-03-25 13:29:23 -04:00
Pierre-Yves David
a29094b506 color: update main documentation
Now that the feature no longer lives in the extension, we document it in the
help of the core config. This include the new 'ui.color' option introduced in
the previous changesets.

As a result the color extensions can now be deprecated.

This is a documentation patch only; color is still disabled by default.
2017-02-21 20:04:55 +01:00
Pierre-Yves David
394a984c5e color: move 'debugcolor' into the 'debugcommands' modules
This is the last bits we needed to move out of the extensions. 'hgext/color.py'
now only contains logic to changes the default color behavior to 'auto'.

However, more cleanups are on the way and we need to document the new config
directly in core.
2017-02-21 18:41:37 +01:00
Pierre-Yves David
23a62914d0 color: move 'styles' definition on the 'ui' object
Same logic as for '_terminfoparams'. The content depends on the config so it
should be specific to each 'ui instance.
2016-11-06 20:16:01 +01:00
Pierre-Yves David
ae9d790b11 color: move the dict with terminfo parameters on the ui object
This dictionnary is affected by the content of the config, so we should have
one for each ui config.

We rename the global dict to '_baseterminfoparams' to make the situation
clearer.
2017-02-25 15:00:51 +01:00
Pierre-Yves David
b29eb57306 color: add a 'ui.color' option to control color behavior
This new option control whether or not color will be used. It mirror the behavior
of '--color'. I usually avoid adding new option to '[ui]' as the section is
already filled with many option. However, I feel like 'color' is central enough
to deserves a spot in this '[ui]' section.

For now the option is not documented so it is still marked as experimental. Once
it get documented and official, we should be able to deprecate the color
extensions.

There is more cleanup to do before that documentation is written, but we need
this option early to made them. Having that option will allow for more cleanup
of the initialisation process and proper separation between color
configuration.
2017-02-25 19:44:23 +01:00
Pierre-Yves David
89576090e1 color: move triggering of the initialisation logic in core
We now run the color initialisation as part of the standard dispatch. This is
opening the way for multiple cleanups since we now have access to the multiple 'ui'
object and we'll be able to see difference between global and local config. This
cleanup will arrive in later changesets.

As a side effect, the '--color' flag is now working without the extension.

Since we now properly initialize color for each ui idependently, we get a
warning message twice.
2017-02-21 18:20:12 +01:00
Pierre-Yves David
e5d5db7cf5 color: add the definition of '--color' in core
If we want to be able to move the initialisation in core, we need core to be
aware of that '--color' flag at all time. So we now have the definition in core. That flag
is currently unprocessed without the extensions (will be fixed soon). In
addition the default value for this flag in core is 'never'. Enabling the
extensions change that default value to 'auto'.
2017-02-21 18:09:21 +01:00
Pierre-Yves David
678b643454 color: handle 'ui.plain()' directly in mode setup
If 'ui.plain()' is set we should not colorize. We move that logic into the
function that determine and setup the color mode. As all other code respect
the resulting mode this will be equivalent.
2017-02-21 17:51:43 +01:00
Pierre-Yves David
be432559a1 color: move git-subrepo support into the subrepo module
Now that all ui instance carry a '_colormode' attribute, we can access and
comply to it directly in the subrepo code. The actual implementation could
probably be a bit smarter, but we stick close to the current one for the sake
of simplicity.
2017-02-21 17:50:04 +01:00
Pierre-Yves David
d02ff2c6a2 color: move 'modesetup' into the core module
Yet another piece of code moving from the extensions to the module in core!
2016-12-22 14:30:46 +01:00
Pierre-Yves David
edcce6b7a3 color: move 'terminfosetup' into the core module
Another step closer to have all the logic living in core
2016-12-22 14:17:52 +01:00
Pierre-Yves David
9ec0d7ca98 color: drop the 'colorui' class
Now that all logics formally bared by 'colorui' have been moved to the main ui
class, that class is empty and can be dropped. As a nice side effect we can get
rid of the baroque Initialization associated to it.

There was much rejoicing.
2017-02-20 12:42:35 +01:00
Pierre-Yves David
7636ff5278 color: move 'write-err' logic to the core ui class
This is similar to what we needed for 'write', we move the logic from the
extension to the core class. Beside the dispatch to 'win32print', we just apply
label to the argument.
2017-02-20 12:42:23 +01:00
Pierre-Yves David
26de620d6b 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
2017-02-20 12:31:39 +01:00
Pierre-Yves David
e346e78cd5 color: add multiple messages input support to 'win32print'
All other function doing writes support any number of input message. For
simplicity, we make 'win32print' able to do the same.
2017-02-24 21:34:07 +01:00
Pierre-Yves David
30677aa45c color: move the 'colorlabel' call 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 to call the new 'colorlabel'
function. Behavior is unchanged when colormode = None.
2017-02-23 19:45:32 +01:00
Pierre-Yves David
88e8699e8f color: move the 'colorlabel' function in the core module
The extract code is relocated in core.
2017-02-23 19:10:24 +01:00
Pierre-Yves David
f7032f18df color: extract the label code into its own function
We extract the logic into a function. This will allow us to move the logic into
the core 'color' module and later call it directly from core.
2017-02-23 19:00:26 +01:00
Pierre-Yves David
c28f2900b0 color: inline the 'showlabel' method
This function is quite simple and only have one call site… located a handful of line
under the definition. We inline the function for the sake of simplicity. One of
the motivation to do that now is that it reduce the amount of new method we
will have to add to the core 'ui' class for color support.
2017-02-20 12:13:23 +01:00
Pierre-Yves David
3a2218f308 color: move '_colormode' to the core 'ui' class
Having all 'ui' objects aware of 'color' allows us to update the core code to
handle color. The mode will stay 'None' in the default case so that will not
introduce any changes.
2017-02-20 12:12:08 +01:00
Pierre-Yves David
2b091caddc color: set initial default value for 'colormode' to None
This should not introduce any behavior changes when using the color extension.
In practive, the colormode will be setup at early at run time to the proper
value (from config and environment).

We do this change as this gets us closer of a state were we can have all the
mechanisms associated to color in core with the feature disabled by default.
2016-12-22 06:18:45 +01:00
Pierre-Yves David
6a72272bdb color: merge two identical 'for' loops
The previous changeset made it clear that we are iterating twice on the same
items. We gather the two loops into a single one.
2017-02-16 10:52:27 +01:00
Pierre-Yves David
ea8940a79d color: minor simplification of some terminfo setup code
No logic change is introduced. The previous code were using a 'dict.update' with
a complex generator. That was a bit confusing to read and not so compact.
Instead we now use an explicit loop and conditional for the sake of clarity.

This also allow for more simplification coming in the next changeset.
2016-12-22 13:06:53 +01:00
Pierre-Yves David
f6a9369fbf color: make a test for curse availability explicite
We won't use terminfo when curse failed to load. Before this change, we were
doing an indirect test, relying on the fact some variable ('_terminfo_params')
would be empty if curses failed to load. We update the code to be more explicit
and directly checks if we managed to load the curse module.
2016-12-22 06:17:40 +01:00
Pierre-Yves David
27dabab2f3 color: move 'win32' declaration to the core module
This is another part of moving color implementation into core. before we can
move the advance logic, we need to move the basic definition and building
bricks. This is one more step on that road.
2016-12-22 03:11:19 +01:00
Pierre-Yves David
d3cdbad5e6 color: move the '_render_effects' function to the core module 2016-12-22 02:38:53 +01:00
Pierre-Yves David
59ecec91a4 color: move '_effect_str' function into the core module 2016-12-22 02:37:18 +01:00
Pierre-Yves David
0f0fe390dc color: move configstyles into the core module
The extension is getting thinner as we speak!
2016-12-22 02:34:22 +01:00
Pierre-Yves David
fcd5d56250 color: move 'valideffect' function into the core module 2016-12-22 02:26:50 +01:00
Pierre-Yves David
98d6e487dc color: move '_terminfo_params' into the core 'color' module
On step closer to have color in core.
2016-12-22 02:23:23 +01:00
Pierre-Yves David
2c4222ad04 color: move '_effect' mapping into core
This is the second things we can move into core safely.
2016-11-18 18:48:38 +01:00
Pierre-Yves David
19558426fc color: spread '_effect' values for readability
We move to our "usual" one value per line style.
2016-11-18 18:43:39 +01:00
Pierre-Yves David
9ff835aa99 color: load 'colortable' from extension using an 'extraloader'
Now that we have the '_style' dictionary in core, we can use the clean and
standard 'extraloader' mechanism to load extension's 'colortable'.
color.loadcolortable
2016-11-18 18:18:15 +01:00
Pierre-Yves David
59221a2230 color: move hgext.color._styles to mercurial.color.style
This is small first step to start moving the color infrastructure into core. The
current code of the color extensions is full of strange and debatable things,
we'll clean it up in the process as having things into core help the cleaning.

Moving _style was the simplest sensible move that is possible. It will also help
cleaning up the extension setup process in a later changesets.
2016-11-18 18:09:36 +01:00
Pierre-Yves David
124732c109 color: drop use of the 'global' keyword for '_style'
Using 'global' is usually a bad sign. Here it is used so that one can empty the
content of a dict at the global scope. We '_style.clear()' and drop the global.
2016-11-18 18:29:19 +01:00
Pierre-Yves David
bf00b0d218 color: drop use of the 'global' keyword for _terminfo_params
Using 'global' is usually a bad sign. Here it is used so that one can empty the
content of a dict at the global scope. We '_terminfo_params.clear()' and
drop the global.
2016-11-18 18:27:13 +01:00
Pulkit Goyal
1f6538b90b py3: replace os.name with pycompat.osname (part 2 of 2) 2016-12-19 00:28:12 +05:30
Pulkit Goyal
9251b69fc4 py3: replace os.environ with encoding.environ (part 5 of 5) 2016-12-18 02:08:59 +05:30
Augie Fackler
a6fae4a4f2 color: avoid shadowing a variable inside a list comprehension 2016-11-10 16:32:51 -05:00
Xidorn Quan
e164cf9b26 color: show mode warning based on ui.formatted
ui.interactive is only for input and ui.formatted is for output.
2016-11-11 13:06:05 +11:00
Pierre-Yves David
1a69a24d99 color: add the ability to display configured style to 'debugcolor'
The 'hg debugcolor' command gains a '--style' flag to display all the configured
labels and their styles. This have many benefits:

 * discovering documented label,
 * checking consistency between label's style,
 * showing the actual style of a label.
2016-11-03 15:17:02 +01:00
Pierre-Yves David
a87b2dcecc color: sort output of 'debugcolor'
The previous ordering were provided by the set. The new output is more stable
and rational. In addition we have some logic to keep the '_background' version
together to help readability.
2016-11-03 15:15:47 +01:00
Pierre-Yves David
d254535be6 color: extract color and effect display from 'debugcolor'
We are about to introduce a second mode for 'hg debugcolor' that would list the
known label and their configuration, so we split the code related to color and
effect out of the main function.
2016-11-03 14:48:47 +01:00
Pierre-Yves David
9bb3c03012 color: restore _style global after debugcolor ran
Before this change, running 'debugcolor' would destroy all color style for the
rest of the process life. We now properly backup and restore the variable
content. Using a global variable is sketchy in general and could probably be
removed. However, this is a quest for another adventure.
2016-11-03 14:29:19 +01:00
Pierre-Yves David
0551e941c2 color: add basic documentation to 'debugcolor'
This does not hurt.
2016-11-03 14:12:32 +01:00
Danek Duvall
5572888746 color: add some documentation for custom terminfo codes 2016-10-15 15:01:14 -07:00
Danek Duvall
3d2001514d color: debugcolor should emit the user-defined colors
This also fixes a long-standing bug that reversed the sense of the color
name and the label used to print it, which was never relevant before.
2016-10-13 13:10:01 -07:00
Danek Duvall
36e57eb638 color: ignore effects missing from terminfo
If terminfo mode is in effect, and an effect is used which is missing from
the terminfo database, simply silently ignore the request, leaving the
output unaffected rather than causing a crash.
2016-10-13 12:01:41 -07:00
Danek Duvall
fb575a9782 color: allow for user-configurable terminfo codes for effects
If the entry in the terminfo database for your terminal is missing some
attributes, it should be possible to create them on the fly without
resorting to just making them a color.  This change allows you to have

    [color]
    terminfo.<effect> = <code>

where <effect> might be something like "dim" or "bold", and <code> is the
escape sequence that would otherwise have come from a call to tigetstr().
If an escape character is needed, use "\E".  Any such settings will
override attributes that are present in the terminfo database.
2016-10-13 11:48:17 -07:00