Skip to content

Commit

Permalink
chore: remove termcolor (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
torsdag committed Oct 11, 2023
1 parent 9e2226c commit 8f7c460
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -78,7 +78,6 @@ def run_tests(self):
install_requires=[
'requests >= 2, <3',
'arrow >= 0.4.4, < 1',
'termcolor >= 1.1.0, < 2',
'pyparsing >= 2.0, < 3',
'clique == 1.6.1',
'websocket-client >= 0.40.0, < 1',
Expand All @@ -88,6 +87,7 @@ def run_tests(self):
],
tests_require=[
'pytest >= 4.6',
'termcolor >= 1.1.0, < 2',
'pytest-mock',
'mock',
'flaky'
Expand Down
28 changes: 21 additions & 7 deletions source/ftrack_api/formatter.py
@@ -1,8 +1,9 @@
# :coding: utf-8
# :copyright: Copyright (c) 2014 ftrack
import os
import sys

from builtins import str
import termcolor

import ftrack_api.entity.base
import ftrack_api.collection
Expand All @@ -18,6 +19,21 @@
}


def _can_do_colors():
'''check if we are ( likely ) to be able to handle colors.'''
if "ANSI_COLORS_DISABLED" in os.environ:
return False
if "NO_COLOR" in os.environ:
return False
if "FORCE_COLOR" in os.environ:
return True
return (
hasattr(sys.stdout, "isatty")
and sys.stdout.isatty()
and os.environ.get("TERM") != "dumb"
)


def format(
entity, formatters=None, attribute_filter=None, recursive=False,
indent=0, indent_first_line=True, _seen=None
Expand Down Expand Up @@ -56,14 +72,12 @@ def format(
formatters = dict()

formatters.setdefault(
'header', lambda text: termcolor.colored(
text, 'white', 'on_blue', attrs=['bold']
)
'header',
lambda text: '\x1b[1m\x1b[44m\x1b[97m{}\x1b[0m\033[0m'.format(text) if _can_do_colors() else text
)
formatters.setdefault(
'label', lambda text: termcolor.colored(
text, 'blue', attrs=['bold']
)
'label',
lambda text: '\x1b[1m\x1b[34m{}\x1b[0m\033[0m'.format(text) if _can_do_colors() else text
)

# Determine indents.
Expand Down

0 comments on commit 8f7c460

Please sign in to comment.