mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
feat: respect NO_COLOR env var and TERM=dumb (#4079)
Add should_use_color() function to hermes_cli/colors.py that checks NO_COLOR (https://no-color.org/) and TERM=dumb before emitting ANSI escapes. The existing color() helper now uses this function instead of a bare isatty() check. This is the foundation — cli.py and banner.py still have inline ANSI constants that bypass this module (tracked in #4071). Closes #4066 Co-authored-by: SHL0MS <SHL0MS@users.noreply.github.com>
This commit is contained in:
parent
13f3e67165
commit
3c8f910973
1 changed files with 18 additions and 2 deletions
|
|
@ -1,8 +1,24 @@
|
||||||
"""Shared ANSI color utilities for Hermes CLI modules."""
|
"""Shared ANSI color utilities for Hermes CLI modules."""
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def should_use_color() -> bool:
|
||||||
|
"""Return True when colored output is appropriate.
|
||||||
|
|
||||||
|
Respects the NO_COLOR environment variable (https://no-color.org/)
|
||||||
|
and TERM=dumb, in addition to the existing TTY check.
|
||||||
|
"""
|
||||||
|
if os.environ.get("NO_COLOR") is not None:
|
||||||
|
return False
|
||||||
|
if os.environ.get("TERM") == "dumb":
|
||||||
|
return False
|
||||||
|
if not sys.stdout.isatty():
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class Colors:
|
class Colors:
|
||||||
RESET = "\033[0m"
|
RESET = "\033[0m"
|
||||||
BOLD = "\033[1m"
|
BOLD = "\033[1m"
|
||||||
|
|
@ -16,7 +32,7 @@ class Colors:
|
||||||
|
|
||||||
|
|
||||||
def color(text: str, *codes) -> str:
|
def color(text: str, *codes) -> str:
|
||||||
"""Apply color codes to text (only when output is a TTY)."""
|
"""Apply color codes to text (only when color output is appropriate)."""
|
||||||
if not sys.stdout.isatty():
|
if not should_use_color():
|
||||||
return text
|
return text
|
||||||
return "".join(codes) + text + Colors.RESET
|
return "".join(codes) + text + Colors.RESET
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue