Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ license = "MIT"
[tool.poetry.dependencies]
python = "^3.6"
has-flag = "^0.1.1"
dict = "^2020.12.3"

[tool.poetry.dev-dependencies]
pytest = "^5.2"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{'': ['*']}

install_requires = \
['dict>=2020.12.3,<2021.0.0', 'has-flag>=0.1.1,<0.2.0']
['has-flag>=0.1.1,<0.2.0']

setup_kwargs = {
'name': 'supports-color',
Expand Down
57 changes: 41 additions & 16 deletions supports_color/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

from has_flag import has_flag
from os import environ as env
from dict import dict as edict
import re
import sys
import platform

class edict(dict):
def __getattr__(self, k):
return self.get(k)


if has_flag('no-color') or \
has_flag('no-colors') or \
has_flag('color=false') or \
Expand Down Expand Up @@ -36,12 +40,12 @@ def translateLevel(level):
if level == 0:
return False

return edict(
level=level,
hasBasic=True,
has256=level >= 2,
has16m=level >= 3
)
return edict({
'level': level,
'hasBasic': True,
'has256': level >= 2,
'has16m': level >= 3,
})


# function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
Expand Down Expand Up @@ -83,6 +87,15 @@ def _supportsColor(haveStream, *, streamIsTTY, sniffFlags=True):

if has_flag('color=256'):
return 2

# // Check for Azure DevOps pipelines.
# // Has to be above the `!streamIsTTY` check.
# if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
# return 1;
# }
if 'TF_BUILD' in env and 'AGENT_NAME' in env:
return 1

#
# if (haveStream && !streamIsTTY && forceColor === undefined) {
# return 0;
Expand All @@ -98,7 +111,6 @@ def _supportsColor(haveStream, *, streamIsTTY, sniffFlags=True):
if env.get('TERM') == 'dumb':
return min
#
# TODO
# if (process.platform === 'win32') {
# // Windows 10 build 10586 is the first Windows release that supports 256 colors.
# // Windows 10 build 14931 is the first release that supports 16m/TrueColor.
Expand All @@ -121,29 +133,42 @@ def _supportsColor(haveStream, *, streamIsTTY, sniffFlags=True):
return 3 if int(osRelease[2]) >= 14931 else 2
return 1
# if ('CI' in env) {
# if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
# if ('GITHUB_ACTIONS' in env || 'GITEA_ACTIONS' in env) {
# return 3;
# }
# if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
# return 1;
# }
#
# return min;
# }
if 'CI' in env:
if any([sign in env for sign in
['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE', 'DRONE']]) or env.get(
if 'GITHUB_ACTIONS' in env or 'GITEA_ACTIONS' in env:
return 3

if any(sign in env for sign in
['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE']) or env.get(
'CI_NAME') == 'codeship':
return 1
#
# TODO
# if ('TEAMCITY_VERSION' in env) {
# return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
# }
if 'TEAMCITY_VERSION' in env:
return 1 if re.search(r'^(9\.(0*[1-9]\d*)\.|\d{2,}\.)', env.get('TEAMCITY_VERSION')) else 0
#
# if (env.COLORTERM === 'truecolor') {
# return 3;
# }
if env.get('COLORTERM') == 'truecolor':
return 3

# if (env.TERM === 'xterm-kitty') {
# return 3;
# }
if env.get('TERM') == 'xterm-kitty':
return 3

# Fix for iTerm2 via SSH
if env.get('LC_TERMINAL') == 'iTerm2':
return 3
Expand Down Expand Up @@ -207,7 +232,7 @@ def createSupportsColor(stream, **options):
# stderr: createSupportsColor({isTTY: tty.isatty(2)})
# }

supportsColor = edict(
stdout=createSupportsColor(sys.stdout),
stderr=createSupportsColor(sys.stderr),
)
supportsColor = edict({
'stdout': createSupportsColor(sys.stdout),
'stderr': createSupportsColor(sys.stderr),
})