mirror of
https://github.com/daylinmorgan/task.mk.git
synced 2024-12-22 01:50:44 -06:00
fix: if NO_COLOR set ignore ansi.custom setting
This commit is contained in:
parent
14b6dccbc9
commit
6dad870b23
1 changed files with 26 additions and 22 deletions
48
src/utils.py
48
src/utils.py
|
@ -65,29 +65,32 @@ class Ansi:
|
||||||
"""use custom color"""
|
"""use custom color"""
|
||||||
|
|
||||||
code, end = "\033[", "m"
|
code, end = "\033[", "m"
|
||||||
if fg:
|
if not sys.stdout.isatty() or os.getenv("NO_COLOR", False):
|
||||||
if isinstance(fg, int):
|
return ""
|
||||||
code += f"38;5;{fg}"
|
else:
|
||||||
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 1:
|
if fg:
|
||||||
code += f"38;5;{fg[0]}"
|
if isinstance(fg, int):
|
||||||
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 3:
|
code += f"38;5;{fg}"
|
||||||
code += f"38;2;{';'.join((str(i) for i in fg))}"
|
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 1:
|
||||||
else:
|
code += f"38;5;{fg[0]}"
|
||||||
print("Expected one or three values for fg as a list")
|
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 3:
|
||||||
sys.exit(1)
|
code += f"38;2;{';'.join((str(i) for i in fg))}"
|
||||||
|
else:
|
||||||
|
print("Expected one or three values for fg as a list")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if bg:
|
if bg:
|
||||||
if isinstance(bg, int):
|
if isinstance(bg, int):
|
||||||
code += f"{';' if fg else ''}48;5;{bg}"
|
code += f"{';' if fg else ''}48;5;{bg}"
|
||||||
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 1:
|
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 1:
|
||||||
code += f"{';' if fg else ''}48;5;{bg[0]}"
|
code += f"{';' if fg else ''}48;5;{bg[0]}"
|
||||||
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 3:
|
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 3:
|
||||||
code += f"{';' if fg else ''}48;2;{';'.join((str(i) for i in bg))}"
|
code += f"{';' if fg else ''}48;2;{';'.join((str(i) for i in bg))}"
|
||||||
else:
|
else:
|
||||||
print("Expected one or three values for bg as a list")
|
print("Expected one or three values for bg as a list")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
return code + end
|
return code + end
|
||||||
|
|
||||||
def add_cfg(self):
|
def add_cfg(self):
|
||||||
cfg_styles = {
|
cfg_styles = {
|
||||||
|
@ -112,5 +115,6 @@ class Ansi:
|
||||||
a = ansi = Ansi()
|
a = ansi = Ansi()
|
||||||
|
|
||||||
cfg = Config(
|
cfg = Config(
|
||||||
"$(DIVIDER)", "$(HELP_SEP)", f"""$(EPILOG)""", f"""$(USAGE)""",int('$(WRAP)'))
|
"$(DIVIDER)", "$(HELP_SEP)", f"""$(EPILOG)""", f"""$(USAGE)""", int("$(WRAP)")
|
||||||
|
)
|
||||||
#% endblock %#
|
#% endblock %#
|
||||||
|
|
Loading…
Reference in a new issue