Commit Graph

43 Commits

Author SHA1 Message Date
Yuya Nishihara
a71f259bd2 doctest: bulk-replace string literals with b'' for Python 3
Our code transformer can't rewrite string literals in docstrings, and I
don't want to make the transformer more complex.
2017-09-03 14:32:11 +09:00
Kyle Lippincott
b8407e4530 color: remove warnings if term is not formatted (==dumb or !ui.formatted())
If the user sets color.mode=terminfo, and then runs in the shell inside of emacs
(so TERM=dumb), the previous behavior was that it would warn about no terminfo
entry for setab/setaf, and then warn about 'failed to set color mode to
terminfo'.  The first warning is silenced by carrying 'formatted' through to
_terminfosetup, the second is silenced by using 'formatted' instead of
ui.formatted().

If --color=on (or ui.color=always) is specified, this will still warn, since the
formatted boolean is set to true in these cases.

Differential Revision: https://phab.mercurial-scm.org/D223
2017-08-03 12:40:48 -07:00
Boris Feld
80b62eed4f configitems: register the 'ui.color' config 2017-07-15 14:14:53 +02:00
Boris Feld
23c3d582a2 color: drop the _enabledbydefault module variable
Since color is on by default, cleanup the now useless variable in both core
and color extension.
2017-07-15 14:14:46 +02:00
Pierre-Yves David
cfc0e24ec0 configitems: register the 'color.mode' config 2017-06-30 03:32:09 +02:00
Matt Harbison
2671b24110 color: enable ANSI support on Windows 10
This will display color if "color.mode=ansi", and default to 'ansi' if the mode
is set to 'auto'.  The 'debugcolor' command also reflects this policy.
Previously, "color.mode=ansi" on Windows printed jibberish around the normal
text.  Using ANSI color is better, as it avoids the normal loss of color when
the default pager is enabled on Windows.  See also issue5570.

When the underlying function fails (e.g. when run on older Windows), 'auto'
still falls back to 'win32'.  Apparently, Microsoft originally had this feature
turned on by default, and then made it opt-in[1].  Therefore, not enabling it
unconditionally seems safer.  Instead, only do it after processing the existing
check for support in a Unix-like environment.

[1] https://github.com/symfony/symfony/issues/17499#issuecomment-243481052
2017-05-22 22:20:38 -04:00
Martin von Zweigbergk
c3406ac3db cleanup: use set literals
We no longer support Python 2.6, so we can now use set literals.
2017-02-10 16:56:29 -08:00
Pierre-Yves David
f6556e7dce color: special case 'always' in 'ui.color'
This lift the confusing case, where 'ui.color=always' would actually not always
use color.
2017-05-02 20:19:09 +02:00
Pierre-Yves David
9b05154b04 color: turn 'ui.color' into a boolean (auto or off)
Previously, 'ui.color=yes' meant "always show color", While
"ui.color=auto" meant "use color automatically when it appears
sensible".

This feels problematic to some people because if an administrator has
disabled color with "ui.color=off", and a user turn it back  on using
"color=on", it will get surprised (because it breaks their output when
redirected to a file.) This patch changes ui.color=true to only move the
default value of --color from "never" to "auto".

I'm not really in favor of this changes as I suspect the above case will
be pretty rare and I would rather keep the logic simpler. However, I'm
providing this patch to help the 4.2 release in the case were others
decide to make this changes.

Users that want to force colors without specifying --color on the
command line can use the 'ui.formatted' config knob, which had to be
enabled in a handful of tests for this patch.

Nice summary table (credit: Augie Fackler)

That is, before this patch:

+--------------------+--------------------+--------------------+
|                    | not a tty          | a tty              |
|                    | --color not set    | --color not set    |
|                    |                    |                    |
+--------------------+--------------------+--------------------+
| [ui]               |                    |                    |
| color (not set)    | no color           | no color           |
|                    |                    |                    |
+--------------------+--------------------+--------------------+
| [ui]               |                    |                    |
| color = auto       | no color           | color              |
|                    |                    |                    |
+--------------------+--------------------+--------------------+
| [ui]               |                    |                    |
| color = yes        | *color*            | color              |
|                    |                    |                    |
+--------------------+--------------------+--------------------+
| [ui]               |                    |                    |
| color = no         | no color           | no color           |
|                    |                    |                    |
+--------------------+--------------------+--------------------+
(if --color is specified, it always clobbers the setting in [ui])

and after this patch:

+--------------------+--------------------+--------------------+
|                    | not a tty          | a tty              |
|                    | --color not set    | --color not set    |
|                    |                    |                    |
+--------------------+--------------------+--------------------+
| [ui]               |                    |                    |
| color (not set)    | no color           | no color           |
|                    |                    |                    |
+--------------------+--------------------+--------------------+
| [ui]               |                    |                    |
| color = auto       | no color           | color              |
|                    |                    |                    |
+--------------------+--------------------+--------------------+
| [ui]               |                    |                    |
| color = yes        | *no color*         | color              |
|                    |                    |                    |
+--------------------+--------------------+--------------------+
| [ui]               |                    |                    |
| color = no         | no color           | no color           |
|                    |                    |                    |
+--------------------+--------------------+--------------------+
(if --color is specified, it always clobbers the setting in [ui])
2017-05-02 20:01:54 +02:00
Pierre-Yves David
97de39f32f color: also enable by default on windows
I've not found anything related to color + windows on the bug tracker. So I'm
suggesting we get bolder and turn it on for windows too in the release
candidate. We can always backout this changeset if we find serious issue on
windows.
2017-04-16 02:34:08 +02:00
Pierre-Yves David
1a7077c9d6 color: turn on by default (but for windows)
Color support is all in core for a couple of months. I've browsed the bug tracker
without finding any blocker bug. So I'm moving forward and enable color on by
default before '4.2-rc'. In the worse case, having it on in the release
candidate will help us to find blocker bug and we can turn it off for the final
release.

I remember people talking about issue with Windows during the freeze so I'm
keeping it off by default on that OS.

We could do various cleaning of the color used and the label issued.  However
the label are probably already in our backward compatibility envelope since the
color extensions has been around since for ever and I do not think the color
choice themself should be considered BC. So I think we should rather gives color
to all user sooner than later.

A couple of test needs to be updated to avoid having color related control code
spoil the tested output.
2017-04-16 02:32:51 +02:00
Pulkit Goyal
46eedbfb56 color: replace str() with pycompat.bytestr() 2017-03-29 14:47:52 +05:30
Matt Harbison
75ecbbd369 color: stop mutating the default effects map
A future change will make color.setup() callable a second time when the pager is
spawned, in order to honor the 'color.pagermode' setting.  The problem was that
when 'color.mode=auto' was resolved to 'win32' in the first pass, the default
ANSI effects were overwritten, making it impossible to honor 'pagermode=ansi'.
Also, the two separate maps didn't have the same keys.  The symmetric difference
is 'dim' and 'italic' (from ANSI), and 'bold_background' (from win32).  Thus,
the update left entries that didn't belong for the current mode.  This bled
through `hg debugcolor`, where the unsupported ANSI keys were listed in 'win32'
mode.

As an added bonus, this now correctly enables color with MSYS `less` for a
command like this, where pager is forced on:

    $ hg log --config color.pagermode=ansi --pager=yes --color=auto

Previously, the output was corrupted.  The raw output, as seen through the ANSI
blind `more.com` was:

    <-[-1;6mchangeset:   34840:3580d1197af9<-[-1m
    ...

which MSYS `less -FRX` rendered as:

    1;6mchangeset:   34840:3580d1197af91m
    ...

(The two '<-' instances were actually an arrow character that TortoiseHg warned
couldn't be encoded, and notepad++ translated to a single '?'.)

Returning an empty map for 'ui._colormode == None' seems better that defaulting
to '_effects' (since some keys are mode dependent), and is better than None,
which blows up `hg debugcolor --color=never`.
2017-03-25 13:50:17 -04:00
Yuya Nishihara
32e72957d2 templater: make pad() strip color codes before computing width (issue5416)
Tested in ANSI mode. We might have to extend _ansieffectre to support
terminfo mode.
2017-03-18 21:02:20 +09:00
Yuya Nishihara
5af4f5ecfd color: insert color code after every "\e[0m" (issue5413)
This assumes the last color wins, tested in ANSI mode. I guess terminfo mode
would work in the same way.
2017-03-18 20:11:15 +09:00
Matt Harbison
e8a2cad68d color: sync text attributes and buffered text output on Windows (issue5508)
I originally noticed that log output wasn't being colored after 348863ccec7e,
but there were other complications too.  With a bunch of untracked files, only
the first 1K of characters were colored pink, and the rest were normal white.  A
single modified file at the top would also be colored pink.

Line buffering and full buffering are treated as the same thing in Windows [1],
meaning the stream is either buffered or not.  I can't find any explicit
documentation to say stdout is unbuffered by default when attached to a console
(but some internet postings indicated that is the case[2]).  Therefore, it seems
that explicit flushes are better than just not reopening stdout.

NB: pager is now on by default, and needs to be disabled to see any color on
Windows.

[1] https://msdn.microsoft.com/en-us/library/86cebhfs(v=vs.140).aspx
[2] https://sourceforge.net/p/mingw/mailman/message/27121137/
2017-03-19 12:44:45 -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
df8accc45d color: rename '_styles' to '_defaultstyles' for clarity
This should make it clear the dict is only used for new config. Extensions
should not modify it directly anyway since we have 'extraloader' logic for
loading '_styles' too.
2016-11-06 20:16:54 +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
da62a3693e color: pass 'ui' to 'win32print'
Same logic as before,'win32print' relies on some data we will move on the 'ui'
object soon, we update the API beforehand for clarity.
2016-11-06 20:10:53 +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
899a2d4ada color: add ui to effect rendering
We'll carry more and more color specific data on the ui object. This will help
isolating different color configuration from each other. For example repository
config might configure special style that should not affect other ui object.

The first step is to make sure the ui object is available were we will needs it.
2017-02-25 15:00:44 +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
48a235c8c6 color: reinvent dictionary
move the module lever dictionary declaration to a more standard (and practical
indentation)
2017-02-28 11:42:07 +01:00
Pierre-Yves David
00b25b244a color: have the 'ui' object carry the '_colormode' directly
Before this changeset, the value was carried by the class to work around
limitation of the extensions initialisation. Now that the initialisation is
cleanly handled in 'dispatch', we can drop this work around.
2017-02-21 18:22:07 +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
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
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
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
b094768dd3 color: clarify name of an argument of 'win32print'
In the current code, the function called to write happens to the 'orig' version
of the method calling 'win32print' (obtained with a 'super' call). However, the
variable could have a better name. That will be useful when we'll stop having
inheritance in play.
2017-02-24 21:31:47 +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
3440ddf077 color: minor reversal of two conditional clause for clarity
Another minor cleanup while reading the code. The two branches of the conditional
have similar complexity so we go for the order that give us the simplest
condition (we drop the negation).
2016-12-22 13:19:12 +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
e15ab34611 color: rework conditional 'valideffect'
Not very important, but the full conditional is not that hard to follow and
having it unified make the function role a bit clearer in my opinion.
2016-12-22 02:30:03 +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
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