Commit Graph

178 Commits

Author SHA1 Message Date
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
Pulkit Goyal
8b4f697218 py3: remove use of *L syntax
The int in Python 3 behaves as long so no need of L's in py3.
Moreover we dont need long here.
2016-09-01 02:29:46 +05:30
Augie Fackler
4e1c384d0a extensions: change magic "shipped with hg" string
I've caught multiple extensions in the wild lying about being
'internal', so it's time to move the goalposts on people. Goalpost
moving will continue until third party extensions stop trying to
defeat the system.
2016-08-23 11:26:08 -04:00
Yuya Nishihara
a5c934df3c py3: move up symbol imports to enforce import-checker rules
Since (b) is banned, we should do the same for (a) for consistency.

 a) from mercurial import hg
    from mercurial.i18n import _

 b) from . import hg
    from .i18n import _
2016-05-14 14:03:12 +09:00
Pulkit Goyal
570e0beb47 py3: make color use absolute_import 2016-04-17 00:53:56 +05:30
timeless
45450b6576 ui: add prompt argument to write (issue5154) (API)
When code like filemerge._iprompt calls ui.prompt, it expects
the user to see the output in addition to getting the prompt.

Other code such as histedit may call ui.pushbuffer, but its
goal is not to interfere with prompts, so this commit adds
an optional prompt flag to ui.write and has _readline
include that argument.

ui.promptchoice calls ui.prompt which calls ui._readline.

This commit also updates hgext.color.write.
2016-03-25 21:51:00 +00:00
Yuya Nishihara
b20edef8a1 templater: move label() function from color extension
ui.label() is no-op by default, so we can just call ui.label() by label()
template function no matter if the color is enabled or not.
2015-06-11 23:04:14 +09:00
Yuya Nishihara
e7ec9f2344 templater: make label() take unknown symbol as color literal
Instead of the mapping hack introduced by d4686e0c15c9, this patch changes the
way how a label symbol is evaluated. This is still hackish, but should be more
predictable in that it doesn't depend on the known color effects.

This change is intended to eliminate the reference to color._effects so that
color.templatelabel() can be merged with templater.label().
2015-06-11 22:58:27 +09:00
Yuya Nishihara
a0a8a0401c templater: factor out thin helper that evaluates argument as string
This function is trivial, but it can make it clear that args[i] is a
(func, data) pair.
2016-02-14 13:30:32 +09:00
Yuya Nishihara
ddf9358dea color: make label() template function stringify "expr" argument first
Since label() should return a string (or a thunk to be evaluated to a string),
this change is okay. This helps porting to evalstring() helper. See the next
patch for details.
2016-03-05 00:01:36 +09:00
Yuya Nishihara
2298c7a029 color: drop useless override of ui.popbuffer()
Because labels are applied at write() time since ce03e7329682,
colorui.popbuffer() is useless and it doesn't update _bufferapplylabels
correctly. Removing it should fix the problem.
2015-12-05 23:41:11 +09:00
Gregory Szorc
d84af347c4 ui: avoid needless casting to a str
In many cases, we don't need to cast to a str because the object will
be cast when it is eventually written.

As part of testing this, I added some code to raise exceptions when a
non-str was passed in and wasn't able to trigger it. i.e. we're already
passing str into this function everywhere, so the casting isn't
necessary.
2015-11-22 14:44:55 -08:00
Gregory Szorc
b184853d7f ui: remove labeled argument from popbuffer
It was moved to pushbuffer and currently does nothing.
2015-11-24 11:23:10 -08:00
Gregory Szorc
d3425fdff9 color: evaluate labels at write time
Previously, we stored 2-tuples of text and label in a list and then
evaluated the labels when the buffer was popped. After this patch,
we evaluate the labels at write time and do a simple join when the
buffer is popped.

This patch appears to have no impact on performance, despite creating
fewer 2-tuples and having fewer strings hanging around in memory.
2015-11-22 14:18:42 -08:00
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07:00
Yuya Nishihara
7be294a6b8 templater: do not reevaluate rawstring as template (BC)
The previous patch made 'string' is always interpreted as a template. So
this patch removes the special handling of r'rawstring' instead. Now r''
disables template processing at all.
2015-06-10 21:44:43 +09:00
Yuya Nishihara
60332ef594 color: copy docstring of label() template function to wrapper
Otherwise label() wouldn't be listed in "hg help template" if color extension
is enabled.
2015-06-10 22:08:15 +09:00
Ryan McElroy
6acaea3ec5 bookmarks: name label for active bookmark correctly
Retain old label as well for backwards compatibility.

Today, the terms 'active' and 'current' are interchangeably used throughout the
codebase in reference to the active bookmark (the bookmark that will be updated
with the next commit). This leads to confusion among developers and users.
This patch is part of a series to standardize the usage to 'active' throughout
the mercurial codebase and user interface.
2015-04-16 15:18:59 -07:00
Augie Fackler
f95a6caba1 extensions: document that testedwith = 'internal' is special
Extension authors (notably at companies using hg) have been
cargo-culting the `testedwith = 'internal'` bit from hg's own
extensions, which then defeats our "file bugs over here" logic in
dispatch. Let's be more aggressive about trying to give extension
authors a hint about what testedwith should say.
2015-04-28 16:44:37 -04:00
Pierre-Yves David
3ecff4d3f6 ui: allow capture of subprocess output
We want to capture hooks output during bundle2 processing. For this purpose we
introduce a new 'subproc' argument to 'ui.pushbuffer'. When set, the output of
sub process created through 'ui.system' will be captured in the buffer too.

This will be used in the next changeset.
2015-04-23 14:57:39 +01:00
Matt Harbison
37984876f0 color: fix crash in cmd.exe
When 'term' is None because it isn't in the environment, don't iterate over it.
Unfortunately, unsetting $TERM or exporting it as '' doesn't work in the tests,
so there's no way to simulate cmd.exe in the test suite.
2015-03-31 14:27:45 -04:00
Jordi Gutiérrez Hermoso
715eecf927 color: consolidate cut-and-paste code
This fixes a mild case of cut-and-paste code regarding failing to set
terminal modes. This is evident in the win32 comment that is misplaced
for the terminfo mode since cset 1456f081d00e.

Instead, we refactor this C&P into a small local function.
2015-03-11 09:34:22 -04:00
Jordi Gutiérrez Hermoso
a24b7fe425 color: omit terminfo/win32 warning if non-interactive (issue4543)
It's pretty annoying to be getting this warning when already the
colour extension has no hope of working. If there isn't a human on the
other end to to see the colours, there probably isn't a human either
who cares about this warning. More likely, some script somewhere is
gonna get confused with the warning output.

Of course, if we still want to see the warning for some reason, we can
always set --config ui.interactive=True.
2015-03-10 13:40:14 -04:00
Gregory Szorc
7215819964 color: support a different color mode when the pager is active
MSYS on Windows has a terminal that supports the "win32" color mode
(which "auto" properly detects for us). However, a popularily configured
pager in that environment (GNU less) only supports the "ansi" color
mode.

This patch teaches color about a new config option: pagermode. It
behaves like "mode" but is only consulted when the pager is active for
the current command. MSYS users can now set "pagermode = ansi" and get a
colorful experience that just works. Previously, MSYS users would have
to live without color when using GNU less as the pager, would have to
manually configure the pager to attend every command, or would have
gibberish if "ansi" was used without the pager.
2015-02-04 14:11:45 -08:00
Gregory Szorc
0acb6cde54 color: be more conservative about setting ANSI mode on Windows (BC)
The current color mode detection on Windows assumes the presence of the
TERM environment variable assumes ANSI is supported. However, this isn't
always true. In MSYS (commonly found as part of MinGW), TERM is set to
"cygwin" and the auto resolved color mode of "ansi" results in escape
sequences getting printed literally to the terminal. The output is
very difficult to read and results in a bad user experience. A
workaround is to activate the pager and have it attend all commands (GNU
less in MSYS can render ANSI terminal sequences properly).

In Cygwin, TERM is set to "xterm." Furthermore, Cygwin supports
displaying these terminal sequences properly (unlike MSYS).

This patch changes the mode auto-detection logic on Windows to be more
conservative about selecting the "ansi" mode. We now only select the
"ansi" mode if TERM is set and it contains the string "xterm" or if
we were unable to talk to win32 APIs to determine the settings. There is
a chance this may take away "ansi" from a terminal that actually
supports it. The recourse for this would be to patch the detection to
act appropriately and to override color.mode until that patch has
landed. However, the author believes this regression is tolerable, since
it means MSYS users won't have gibberish printed by default.

Since MSYS's common pager (less) supports display of ANSI sequences,
there is room to patch the color extensions so it can select the ANSI
color mode if a pager is activated.

Mozilla (being an active user of MSYS) would really appreciate this
being part of the stable branch. However, since I believe it is BC, I
haven't explicitly requested application to stable since I figure that
request will be denied.
2015-02-03 16:24:32 -08:00
Sean Farley
ac6542ef7d color: add missing 'dim' in _effects
It seems that this has been missing for people running in 'ansi' mode.
2015-01-18 22:24:14 -08:00
Mathias De Maré
1521d2118c color: add support for colorizing git subrepo diffs 2015-01-08 21:30:22 +01:00
Pierre-Yves David
e8f7207454 patchbomb: add label and color to the confirm output
The current output is mostly a wall of text. This makes it hard to
actually check something for people with lazy eyes. We use labels and
colors to make it more joyful (and get the patch summaries to stand
out). The colors have been arbitrarily choosen. They can be changed
later if someone has a more scientific choice.
2014-11-04 13:38:33 +00:00
Jordi Gutiérrez Hermoso
88894fbfa7 color: reorganise and sectionify the help text
The color docstring was getting long. This splits it up into
bite-sized sections and rearranges the order of the paragraphs a
little to match these sections.
2014-10-06 08:18:03 -04:00
Jordi Gutiérrez Hermoso
6a56d95986 color: update description of the extension
The color extension long ago ceased to work only for the status and
qseries commands.
2014-10-06 08:16:40 -04:00
Jordi Gutiérrez Hermoso
5d799cff20 color: omit debug label output on empty strings
This is most noticeable when using custom templates. Before this
patch, a template like {label("foo.bar", baz)} would emit

   [foo.bar|]

whenever baz was empty. This cset simply omits all output when baz is
empty.
2014-10-03 19:47:57 -04:00
Jordi Gutiérrez Hermoso
45fc6b44bf color: update docstring for debug option
06eb97028e1b updated the format for the --color=debug option. This
updates the documentation to match this new format.
2014-08-24 17:40:27 -04:00
Jordi Gutiérrez Hermoso
b701187fa4 color: document the possibility to colourise tabs in diffs
This is a no-op change that simply suggests that tabs can be
colourised, but defaults to no colour effects for tabs. This
complements cset 56ff694317ca.

Like the similar effects for phases from 8f322ff11fbb, we set the
default effects to '' instead of None, so that this is a true noop
change. Otherwise, the diff.tab effect would override (i.e.
neutralise) the effect of the surrounding label.
2014-08-20 15:19:37 -04:00
Jordi Gutiérrez Hermoso
71fd49d081 color: document that changeset phases have labels
It's very useful to be able to colourise csets according to their
phases. There was no indication anywhere in the docs that this is
possible.

We use e.g. `changeset.secret = ` instead of `changeset.secret
='none'`, because otherwise this is a BC: it would nullify the effects
given to log.changeset label that usually surrounds the
changeset.{phase} labels. Specifying the label without any effect
instead of 'none' is a true no-op change and purely documentation.
2014-08-24 17:27:28 -04:00
Matt Mackall
ef96dff15e color: change the debug output format
Before, the format was

 label(labeled text)  # single label
 [label1 label2](labeled text) # multiple

Now, it's

 [labels|labeled text]

..which should make things a bit more clear.
2014-09-19 12:51:15 -05:00
Jordi Gutiérrez Hermoso
3818f62593 color: enable debug option to show labels
This is a debug option for showing labels. This can be helpful for
knowing which labels are available for colouring or to see the output
when defining your own templates. A couple of tests are included.
2014-08-24 17:40:27 -04:00
Jordi Gutiérrez Hermoso
d23bdb740a color: document that labels are used for colorizing text
It is a deeply hidden secret that it's possible to colorise so many
things with so many different labels. This is an attempt to document
this. The text is a bit long, but it seems as short as can be while
documenting everything. Perhaps it should be hidden under a --verbose
option.
2014-08-24 17:35:36 -04:00