2022-01-06 01:42:23 +03:00
|
|
|
# Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
2019-11-01 22:33:28 +03:00
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2.
|
|
|
|
|
2016-11-18 20:09:36 +03:00
|
|
|
# utility for color output for Mercurial commands
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 Kevin Christen <kevin.christen@gmail.com> and other
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2017-03-18 15:02:20 +03:00
|
|
|
import re
|
2022-07-20 02:56:02 +03:00
|
|
|
from typing import Dict, List, Optional, Pattern, Union
|
2017-03-18 15:02:20 +03:00
|
|
|
|
2022-09-16 00:00:06 +03:00
|
|
|
import bindings
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
from . import encoding, pycompat, util
|
2016-12-22 04:34:22 +03:00
|
|
|
from .i18n import _
|
2022-09-16 00:00:06 +03:00
|
|
|
from .pycompat import decodeutf8, encodeutf8
|
2016-12-22 04:34:22 +03:00
|
|
|
|
2016-12-22 05:11:19 +03:00
|
|
|
|
2016-12-22 04:23:23 +03:00
|
|
|
try:
|
|
|
|
import curses
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2020-04-03 23:45:47 +03:00
|
|
|
curses.COLOR_BLACK
|
2021-02-11 20:44:03 +03:00
|
|
|
except (ImportError, AttributeError):
|
2016-12-22 04:23:23 +03:00
|
|
|
curses = None
|
|
|
|
|
2016-11-18 20:48:38 +03:00
|
|
|
# start and stop parameters for effects
|
2020-04-03 23:45:47 +03:00
|
|
|
_defaulteffects = {
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"none": 0,
|
|
|
|
"black": 30,
|
|
|
|
"red": 31,
|
|
|
|
"green": 32,
|
|
|
|
"yellow": 33,
|
|
|
|
"blue": 34,
|
|
|
|
"magenta": 35,
|
|
|
|
"cyan": 36,
|
|
|
|
"white": 37,
|
|
|
|
"bold": 1,
|
|
|
|
"italic": 3,
|
|
|
|
"underline": 4,
|
|
|
|
"inverse": 7,
|
|
|
|
"dim": 2,
|
|
|
|
"black_background": 40,
|
|
|
|
"red_background": 41,
|
|
|
|
"green_background": 42,
|
|
|
|
"yellow_background": 43,
|
|
|
|
"blue_background": 44,
|
|
|
|
"purple_background": 45,
|
|
|
|
"cyan_background": 46,
|
|
|
|
"white_background": 47,
|
|
|
|
}
|
2022-07-20 02:56:02 +03:00
|
|
|
_effects: Dict[str, int] = {}
|
2016-11-18 20:48:38 +03:00
|
|
|
|
2016-11-06 22:16:54 +03:00
|
|
|
_defaultstyles = {
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"grep.match": "red bold",
|
|
|
|
"grep.linenumber": "green",
|
|
|
|
"grep.rev": "green",
|
|
|
|
"grep.change": "green",
|
|
|
|
"grep.sep": "cyan",
|
|
|
|
"grep.filename": "magenta",
|
|
|
|
"grep.user": "magenta",
|
|
|
|
"grep.date": "magenta",
|
2019-06-26 20:59:13 +03:00
|
|
|
"blackbox.timestamp": "green",
|
|
|
|
"blackbox.session.0": "yellow",
|
|
|
|
"blackbox.session.1": "cyan",
|
|
|
|
"blackbox.session.2": "magenta",
|
2020-04-14 00:59:41 +03:00
|
|
|
"blackbox.session.3": "brightblue:blue",
|
2018-10-27 20:30:25 +03:00
|
|
|
"blame.age.1hour": "#ffe:color231:bold",
|
|
|
|
"blame.age.1day": "#eea:color230:bold",
|
2020-04-14 00:59:41 +03:00
|
|
|
"blame.age.7day": "#dd5:color229:brightyellow:yellow",
|
|
|
|
"blame.age.30day": "#cc3:color228:brightyellow:yellow",
|
2018-10-27 20:30:25 +03:00
|
|
|
"blame.age.60day": "#aa2:color185:yellow",
|
|
|
|
"blame.age.180day": "#881:color142:yellow",
|
|
|
|
"blame.age.360day": "#661:color100:yellow",
|
|
|
|
"blame.age.old": "#440:color58:brightblack:yellow",
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"bookmarks.active": "green",
|
|
|
|
"branches.active": "none",
|
|
|
|
"branches.closed": "black bold",
|
|
|
|
"branches.current": "green",
|
|
|
|
"branches.inactive": "none",
|
|
|
|
"diff.changed": "white",
|
|
|
|
"diff.deleted": "color160:brightred:red",
|
|
|
|
"diff.deleted.changed": "color196:brightred:red",
|
|
|
|
"diff.deleted.unchanged": "color124:red",
|
|
|
|
"diff.diffline": "bold",
|
|
|
|
"diff.extended": "cyan bold",
|
|
|
|
"diff.file_a": "red bold",
|
|
|
|
"diff.file_b": "green bold",
|
|
|
|
"diff.hunk": "magenta",
|
|
|
|
"diff.inserted": "color40:brightgreen:green",
|
|
|
|
"diff.inserted.changed": "color40:brightgreen:green",
|
|
|
|
"diff.inserted.unchanged": "color28:green",
|
|
|
|
"diff.tab": "",
|
|
|
|
"diff.trailingwhitespace": "bold red_background",
|
2020-01-14 01:27:26 +03:00
|
|
|
"changeset.public": "yellow",
|
|
|
|
"changeset.draft": "brightyellow:yellow bold",
|
|
|
|
"changeset.secret": "brightyellow:yellow",
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"diffstat.deleted": "red",
|
|
|
|
"diffstat.inserted": "green",
|
|
|
|
"formatvariant.name.mismatchconfig": "red",
|
|
|
|
"formatvariant.name.mismatchdefault": "yellow",
|
|
|
|
"formatvariant.name.uptodate": "green",
|
|
|
|
"formatvariant.repo.mismatchconfig": "red",
|
|
|
|
"formatvariant.repo.mismatchdefault": "yellow",
|
|
|
|
"formatvariant.repo.uptodate": "green",
|
|
|
|
"formatvariant.config.special": "yellow",
|
|
|
|
"formatvariant.config.default": "green",
|
|
|
|
"formatvariant.default": "",
|
|
|
|
"histedit.remaining": "red bold",
|
2020-01-14 01:27:26 +03:00
|
|
|
"log.changeset": "",
|
2018-08-23 07:26:48 +03:00
|
|
|
"processtree.descendants": "green",
|
|
|
|
"processtree.selected": "green bold",
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"progress.fancy.bar.background": "",
|
|
|
|
"progress.fancy.bar.indeterminate": "yellow_background",
|
2018-08-23 07:26:48 +03:00
|
|
|
"progress.fancy.bar.normal": "green_background",
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"progress.fancy.bar.spinner": "cyan_background",
|
2018-08-23 07:26:48 +03:00
|
|
|
"progress.fancy.count": "bold",
|
|
|
|
"progress.fancy.item": "",
|
|
|
|
"progress.fancy.topic": "bold",
|
|
|
|
"ui.prompt": "yellow",
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"rebase.rebased": "blue",
|
|
|
|
"rebase.remaining": "red bold",
|
|
|
|
"resolve.resolved": "green bold",
|
|
|
|
"resolve.unresolved": "red bold",
|
|
|
|
"shelve.age": "cyan",
|
|
|
|
"shelve.newest": "green bold",
|
|
|
|
"shelve.name": "blue bold",
|
|
|
|
"status.added": "green bold",
|
2019-03-21 08:46:07 +03:00
|
|
|
"ui.metrics": "#777:color242:dim",
|
2019-05-09 16:50:03 +03:00
|
|
|
"ui.prefix.component": "cyan",
|
|
|
|
"ui.prefix.error": "brightred:red",
|
|
|
|
"ui.prefix.notice": "yellow",
|
2022-04-20 22:57:30 +03:00
|
|
|
"testing.divider": "brightblack:none",
|
|
|
|
"testing.lineloc": "brightblue:blue",
|
|
|
|
"testing.source": "none",
|
|
|
|
"testing.exceeded": "cyan",
|
2017-02-28 13:42:07 +03:00
|
|
|
}
|
2016-11-18 20:18:15 +03:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2022-07-20 02:56:02 +03:00
|
|
|
def loadcolortable(ui, extname, colortable) -> None:
|
2016-11-06 22:16:54 +03:00
|
|
|
_defaultstyles.update(colortable)
|
2016-12-22 04:26:50 +03:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2022-07-20 02:56:02 +03:00
|
|
|
def setup(ui) -> None:
|
2017-02-21 20:20:12 +03:00
|
|
|
"""configure color on a ui
|
|
|
|
|
2017-02-25 21:44:23 +03:00
|
|
|
That function both set the colormode for the ui object and read
|
2017-02-21 20:20:12 +03:00
|
|
|
the configuration looking for custom colors and effect definitions."""
|
2017-02-25 21:44:23 +03:00
|
|
|
mode = _modesetup(ui)
|
2017-02-21 20:22:07 +03:00
|
|
|
ui._colormode = mode
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
if mode and mode != "debug":
|
2017-02-21 20:20:12 +03:00
|
|
|
configstyles(ui)
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2022-07-20 02:56:02 +03:00
|
|
|
def _modesetup(ui) -> Optional[str]:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
if ui.plain("color"):
|
2017-02-21 19:51:43 +03:00
|
|
|
return None
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
config = ui.config("ui", "color")
|
|
|
|
if config == "debug":
|
|
|
|
return "debug"
|
2016-12-22 16:30:46 +03:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
auto = config == "auto"
|
2017-05-02 21:01:54 +03:00
|
|
|
always = False
|
|
|
|
if not auto and util.parsebool(config):
|
2017-05-02 21:19:09 +03:00
|
|
|
# We want the config to behave like a boolean, "on" is actually auto,
|
|
|
|
# but "always" value is treated as a special case to reduce confusion.
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
if ui.configsource("ui", "color") == "--color" or config == "always":
|
2017-05-02 21:01:54 +03:00
|
|
|
always = True
|
|
|
|
else:
|
|
|
|
auto = True
|
|
|
|
|
2016-12-22 16:30:46 +03:00
|
|
|
if not always and not auto:
|
|
|
|
return None
|
|
|
|
|
2020-05-19 16:11:56 +03:00
|
|
|
havecolors = always or (
|
|
|
|
encoding.environ.get("TERM") != "dumb" and ui.terminaloutput()
|
|
|
|
)
|
2016-12-22 16:30:46 +03:00
|
|
|
|
2017-10-13 09:30:46 +03:00
|
|
|
if pycompat.iswindows:
|
2017-05-23 05:20:38 +03:00
|
|
|
from . import win32
|
|
|
|
|
2020-04-06 23:04:50 +03:00
|
|
|
if not (util.istest() or win32.enablevtmode()):
|
2020-04-08 05:34:30 +03:00
|
|
|
if not ui.pageractive:
|
2020-07-02 17:11:55 +03:00
|
|
|
if havecolors and not always:
|
2022-05-21 03:41:34 +03:00
|
|
|
ui.debug("couldn't enable VT mode, disabling colors\n")
|
2020-04-08 05:34:30 +03:00
|
|
|
if not always:
|
|
|
|
return None
|
2016-12-22 16:30:46 +03:00
|
|
|
|
2020-05-19 16:11:56 +03:00
|
|
|
if always or (auto and havecolors):
|
2020-04-03 23:45:47 +03:00
|
|
|
return "ansi"
|
2016-12-22 16:30:46 +03:00
|
|
|
return None
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2018-03-24 12:16:04 +03:00
|
|
|
def normalizestyle(ui, style):
|
|
|
|
"""choose a fallback from a list of labels"""
|
|
|
|
# colorname1:colorname2:colorname3 means:
|
|
|
|
# use colorname1 if supported, fallback to colorname2, then
|
|
|
|
# fallback to colorname3.
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
for e in style.split(":"):
|
2018-03-24 12:16:04 +03:00
|
|
|
if valideffect(ui, e):
|
|
|
|
return e
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2018-10-27 20:30:25 +03:00
|
|
|
class truecoloreffects(dict):
|
|
|
|
def makecolor(self, c):
|
|
|
|
n = 38
|
|
|
|
if c.endswith("_background"):
|
|
|
|
c = c[:-11]
|
|
|
|
n = 48
|
|
|
|
if len(c) == 4:
|
|
|
|
r, g, b = c[1] + c[1], c[2] + c[2], c[3] + c[3]
|
|
|
|
else:
|
|
|
|
r, g, b = c[1:3], c[3:5], c[5:7]
|
|
|
|
return ";".join(map(str, [n, 2, int(r, 16), int(g, 16), int(b, 16)]))
|
|
|
|
|
|
|
|
def get(self, key, default=None):
|
|
|
|
if _truecolorre.match(key):
|
|
|
|
return self.makecolor(key)
|
|
|
|
else:
|
|
|
|
return super(truecoloreffects, self).get(key, default)
|
|
|
|
|
|
|
|
def __getitem__(self, key):
|
|
|
|
if _truecolorre.match(key):
|
|
|
|
return self.makecolor(key)
|
|
|
|
else:
|
|
|
|
return super(truecoloreffects, self).__getitem__(key)
|
|
|
|
|
|
|
|
|
2022-07-20 02:56:02 +03:00
|
|
|
def _extendcolors(colors) -> None:
|
2018-03-29 20:16:37 +03:00
|
|
|
# see https://en.wikipedia.org/wiki/ANSI_escape_code
|
2018-10-27 20:30:25 +03:00
|
|
|
global _effects
|
2020-04-03 23:45:47 +03:00
|
|
|
_effects = _defaulteffects.copy()
|
2018-03-29 20:16:37 +03:00
|
|
|
if colors >= 16:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
_effects.update(
|
|
|
|
{
|
|
|
|
"brightblack": 90,
|
|
|
|
"brightred": 91,
|
|
|
|
"brightgreen": 92,
|
|
|
|
"brightyellow": 93,
|
|
|
|
"brightblue": 94,
|
|
|
|
"brightmagenta": 95,
|
|
|
|
"brightcyan": 96,
|
|
|
|
"brightwhite": 97,
|
|
|
|
}
|
|
|
|
)
|
2018-03-29 20:16:37 +03:00
|
|
|
if colors >= 256:
|
|
|
|
for i in range(256):
|
2022-07-20 02:56:02 +03:00
|
|
|
# pyre-fixme[6]: For 2nd param expected `int` but got `str`.
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
_effects["color%s" % i] = "38;5;%s" % i
|
2022-07-20 02:56:02 +03:00
|
|
|
# pyre-fixme[6]: For 2nd param expected `int` but got `str`.
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
_effects["color%s_background" % i] = "48;5;%s" % i
|
2018-10-27 20:30:25 +03:00
|
|
|
if colors >= 16777216:
|
|
|
|
_effects = truecoloreffects(_effects)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2018-03-29 20:16:37 +03:00
|
|
|
|
2022-07-20 02:56:02 +03:00
|
|
|
def configstyles(ui) -> None:
|
2020-04-03 23:45:47 +03:00
|
|
|
if ui._colormode == "ansi":
|
|
|
|
_extendcolors(supportedcolors(ui))
|
2016-11-06 22:16:54 +03:00
|
|
|
ui._styles.update(_defaultstyles)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
for status, cfgeffects in ui.configitems("color"):
|
2020-04-03 23:45:47 +03:00
|
|
|
if "." not in status or status.startswith("color."):
|
2016-12-22 04:34:22 +03:00
|
|
|
continue
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
cfgeffects = ui.configlist("color", status)
|
2016-12-22 04:34:22 +03:00
|
|
|
if cfgeffects:
|
|
|
|
good = []
|
|
|
|
for e in cfgeffects:
|
2018-03-24 12:16:04 +03:00
|
|
|
n = normalizestyle(ui, e)
|
|
|
|
if n:
|
|
|
|
good.append(n)
|
2016-12-22 04:34:22 +03:00
|
|
|
else:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
ui.warn(
|
|
|
|
_(
|
|
|
|
"ignoring unknown color/effect %r "
|
|
|
|
"(configured in color.%s)\n"
|
|
|
|
)
|
|
|
|
% (e, status)
|
|
|
|
)
|
|
|
|
ui._styles[status] = " ".join(good)
|
|
|
|
|
2016-12-22 04:34:22 +03:00
|
|
|
|
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 20:50:17 +03:00
|
|
|
def _activeeffects(ui):
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"""Return the effects map for the color mode set on the ui."""
|
2020-04-03 23:45:47 +03:00
|
|
|
if ui._colormode is not None:
|
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 20:50:17 +03:00
|
|
|
return _effects
|
|
|
|
return {}
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2022-07-20 02:56:02 +03:00
|
|
|
def valideffect(ui, effect) -> bool:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"Determine if the effect is valid or not."
|
2021-02-23 15:45:08 +03:00
|
|
|
return all(
|
|
|
|
(isinstance(_activeeffects(ui), truecoloreffects) and _truecolorre.match(e))
|
|
|
|
or (e in _activeeffects(ui))
|
|
|
|
for e in effect.split("+")
|
|
|
|
)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2016-12-22 04:38:53 +03:00
|
|
|
|
2022-02-10 01:26:09 +03:00
|
|
|
def _mergeeffects(
|
|
|
|
text: "Union[str, bytes]", start: str, stop: str, usebytes: bool = False
|
|
|
|
) -> "Union[str, bytes]":
|
2017-03-18 14:11:15 +03:00
|
|
|
"""Insert start sequence at every occurrence of stop sequence
|
|
|
|
|
2022-01-19 04:19:06 +03:00
|
|
|
>>> s = _mergeeffects('cyan', '[C]', '|')
|
|
|
|
>>> s = _mergeeffects(s + 'yellow', '[Y]', '|')
|
|
|
|
>>> s = _mergeeffects('ma' + s + 'genta', '[M]', '|')
|
|
|
|
>>> s = _mergeeffects('red' + s, '[R]', '|')
|
2017-03-18 14:11:15 +03:00
|
|
|
>>> s
|
|
|
|
'[R]red[M]ma[Y][C]cyan|[R][M][Y]yellow|[R][M]genta|'
|
|
|
|
"""
|
|
|
|
parts = []
|
2020-01-31 23:58:35 +03:00
|
|
|
if usebytes:
|
|
|
|
assert isinstance(text, bytes)
|
|
|
|
for t in text.split(encodeutf8(stop)):
|
|
|
|
if not t:
|
|
|
|
continue
|
|
|
|
parts.extend([encodeutf8(start), t, encodeutf8(stop)])
|
|
|
|
return b"".join(parts)
|
|
|
|
else:
|
|
|
|
assert isinstance(text, str)
|
|
|
|
for t in text.split(stop):
|
|
|
|
if not t:
|
|
|
|
continue
|
|
|
|
parts.extend([start, t, stop])
|
|
|
|
return "".join(parts)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2017-03-18 14:11:15 +03:00
|
|
|
|
2022-07-20 02:56:02 +03:00
|
|
|
def _render_effects(ui, text, effects: List[str], usebytes: bool = False):
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"Wrap text in commands to turn on each effect."
|
2016-12-22 04:38:53 +03:00
|
|
|
if not text:
|
|
|
|
return text
|
2020-04-03 23:45:47 +03:00
|
|
|
activeeffects = _activeeffects(ui)
|
2022-07-20 02:56:02 +03:00
|
|
|
# pyre-fixme[16]: `List` has no attribute `split`.
|
2021-02-23 15:45:08 +03:00
|
|
|
effects = ["none"] + [e for effect in effects.split() for e in effect.split("+")]
|
|
|
|
start = [pycompat.bytestr(activeeffects[e]) for e in effects]
|
2020-04-03 23:45:47 +03:00
|
|
|
start = "\033[" + ";".join(start) + "m"
|
|
|
|
stop = "\033[" + pycompat.bytestr(activeeffects["none"]) + "m"
|
2020-01-31 23:58:35 +03:00
|
|
|
return _mergeeffects(text, start, stop, usebytes=usebytes)
|
2016-12-22 05:11:19 +03:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2022-07-20 02:56:02 +03:00
|
|
|
_ansieffectre: Pattern[str] = re.compile(r"\x1b\[[0-9;]*m")
|
|
|
|
_truecolorre: Pattern[str] = re.compile(r"#([0-9A-Fa-f]{3}){1,2}(_background)?")
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2017-03-18 15:02:20 +03:00
|
|
|
|
|
|
|
def stripeffects(text):
|
|
|
|
"""Strip ANSI control codes which could be inserted by colorlabel()"""
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
return _ansieffectre.sub("", text)
|
|
|
|
|
2017-03-18 15:02:20 +03:00
|
|
|
|
2022-07-20 02:56:02 +03:00
|
|
|
def colorlabel(ui, msg, label, usebytes: bool = False) -> Union[bytes, str]:
|
2017-02-23 21:10:24 +03:00
|
|
|
"""add color control code according to the mode"""
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
if ui._colormode == "debug":
|
2017-02-23 21:10:24 +03:00
|
|
|
if label and msg:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
if msg[-1] == "\n":
|
2020-01-31 23:58:35 +03:00
|
|
|
if usebytes:
|
2020-02-01 02:39:18 +03:00
|
|
|
msg = b"[%s|%s]\n" % (encodeutf8(label), msg[:-1])
|
2020-01-31 23:58:35 +03:00
|
|
|
else:
|
|
|
|
msg = "[%s|%s]\n" % (label, msg[:-1])
|
2017-02-23 21:10:24 +03:00
|
|
|
else:
|
2020-01-31 23:58:35 +03:00
|
|
|
if usebytes:
|
2020-02-01 02:39:18 +03:00
|
|
|
msg = b"[%s|%s]" % (encodeutf8(label), msg)
|
2020-01-31 23:58:35 +03:00
|
|
|
else:
|
|
|
|
msg = "[%s|%s]" % (label, msg)
|
2017-02-23 21:10:24 +03:00
|
|
|
elif ui._colormode is not None:
|
2022-09-16 00:00:06 +03:00
|
|
|
if ui.configbool("color", "use-rust", default=True):
|
|
|
|
if not ui._styler:
|
|
|
|
ui._styler = bindings.io.styler(supportedcolors(ui))
|
|
|
|
|
|
|
|
style = " ".join(ui._styles.get(l, l) for l in label.split())
|
|
|
|
if usebytes:
|
|
|
|
msg = decodeutf8(msg)
|
|
|
|
styled = ui._styler.renderbytes(style, msg)
|
|
|
|
if not usebytes:
|
|
|
|
styled = styled.decode()
|
|
|
|
return styled
|
|
|
|
|
2017-02-23 21:10:24 +03:00
|
|
|
effects = []
|
|
|
|
for l in label.split():
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
s = ui._styles.get(l, "")
|
|
|
|
if ":" in s:
|
2018-03-24 12:16:04 +03:00
|
|
|
s = normalizestyle(ui, s)
|
2017-02-23 21:10:24 +03:00
|
|
|
if s:
|
|
|
|
effects.append(s)
|
2017-02-25 17:00:44 +03:00
|
|
|
elif valideffect(ui, l):
|
2017-02-23 21:10:24 +03:00
|
|
|
effects.append(l)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
effects = " ".join(effects)
|
2017-02-23 21:10:24 +03:00
|
|
|
if effects:
|
2020-01-31 23:58:35 +03:00
|
|
|
if usebytes:
|
|
|
|
msg = b"\n".join(
|
|
|
|
[
|
2022-07-20 02:56:02 +03:00
|
|
|
# pyre-fixme[6]: For 3rd param expected `List[str]` but got
|
|
|
|
# `str`.
|
2020-01-31 23:58:35 +03:00
|
|
|
_render_effects(ui, line, effects, usebytes=True)
|
|
|
|
for line in msg.split(b"\n")
|
|
|
|
]
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
msg = "\n".join(
|
2022-07-20 02:56:02 +03:00
|
|
|
# pyre-fixme[6]: For 3rd param expected `List[str]` but got `str`.
|
2020-01-31 23:58:35 +03:00
|
|
|
[_render_effects(ui, line, effects) for line in msg.split("\n")]
|
|
|
|
)
|
2017-02-23 21:10:24 +03:00
|
|
|
return msg
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2020-04-03 23:45:47 +03:00
|
|
|
def supportedcolors(ui):
|
2018-03-29 20:16:37 +03:00
|
|
|
"""Return the number of colors likely supported by the terminal
|
2018-03-24 12:15:57 +03:00
|
|
|
|
2018-03-29 20:16:37 +03:00
|
|
|
Usually it's one of 8, 16, 256.
|
|
|
|
"""
|
|
|
|
# HGCOLORS can override the decision
|
|
|
|
env = encoding.environ
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
if "HGCOLORS" in env:
|
2018-03-29 20:16:37 +03:00
|
|
|
colors = 8
|
|
|
|
try:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
colors = int(env["HGCOLORS"])
|
2018-03-29 20:16:37 +03:00
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
return colors
|
|
|
|
|
|
|
|
# Colors reported by terminfo. Might be smaller than the real value.
|
|
|
|
ticolors = 8
|
|
|
|
if curses:
|
|
|
|
try:
|
|
|
|
curses.setupterm()
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
ticolors = curses.tigetnum("colors")
|
2018-03-29 20:16:37 +03:00
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Guess the real number of colors supported.
|
2020-05-02 00:49:52 +03:00
|
|
|
# ConEmu normalizes 256 colors incorrectly. Limit it to 16 colors.
|
|
|
|
if "ConEmuPID" in env:
|
|
|
|
realcolors = 16
|
2018-03-29 20:16:37 +03:00
|
|
|
# Emacs has issues with 16 or 256 colors.
|
2020-04-03 23:45:47 +03:00
|
|
|
if env.get("INSIDE_EMACS"):
|
2018-03-29 20:16:37 +03:00
|
|
|
realcolors = 8
|
2018-03-24 12:15:57 +03:00
|
|
|
# Detecting Terminal features is hard. "infocmp" seems to be a "standard"
|
|
|
|
# way to do it. But it can often miss real terminal capabilities.
|
|
|
|
#
|
|
|
|
# Tested on real tmux (2.2), mosh (1.3.0), screen (4.04) from Linux (xfce)
|
|
|
|
# and OS X Terminal.app and iTerm 2. Every terminal support 256 colors
|
2018-03-29 20:16:37 +03:00
|
|
|
# except for "screen". "screen" also uses underline for "dim".
|
2018-03-24 12:15:57 +03:00
|
|
|
#
|
|
|
|
# screen can actually support 256 colors if it's started with TERM set to
|
|
|
|
# "xterm-256color". In that case, screen will set TERM to
|
|
|
|
# "screen.xterm-256color". Tmux sets TERM to "screen" by default. But it
|
|
|
|
# also sets TMUX.
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
elif env.get("TERM") == "screen" and "TMUX" not in env:
|
2018-03-29 20:16:37 +03:00
|
|
|
realcolors = 16
|
2018-10-27 20:30:25 +03:00
|
|
|
# If COLORTERM is set to indicate a truecolor terminal, believe it.
|
|
|
|
elif env.get("COLORTERM") in ("truecolor", "24bit"):
|
|
|
|
realcolors = 16777216
|
2020-04-03 23:45:47 +03:00
|
|
|
# XXX: The gitbash pager doesn't support more than 8 colors, remove once
|
|
|
|
# we switched over to our embedded less pager.
|
|
|
|
elif pycompat.iswindows and ui.pageractive:
|
|
|
|
realcolors = 8
|
2018-03-29 20:16:37 +03:00
|
|
|
# Otherwise, pretend to support 256 colors.
|
|
|
|
else:
|
|
|
|
realcolors = 256
|
2018-03-24 12:15:59 +03:00
|
|
|
|
2018-03-29 20:16:37 +03:00
|
|
|
# terminfo can override "realcolors" upwards.
|
|
|
|
return max([realcolors, ticolors])
|