Spaces:
Paused
Paused
Download hermes_cli/colors.py from abc1181/HermesAgent: direct link, hf CLI and curl.
- Browser
- Download file 937 Bytes
-
https://huggingface.co/spaces/abc1181/HermesAgent/resolve/main/hermes_cli/colors.py
- Command line
-
hf download hf://spaces/abc1181/HermesAgent/hermes_cli/colors.py
-
curl -L -o colors.py https://huggingface.co/spaces/abc1181/HermesAgent/resolve/main/hermes_cli/colors.py
937 Bytes
| """Shared ANSI color utilities for Hermes CLI modules.""" | |
| import os | |
| 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: | |
| RESET = "\033[0m" | |
| BOLD = "\033[1m" | |
| DIM = "\033[2m" | |
| RED = "\033[31m" | |
| GREEN = "\033[32m" | |
| YELLOW = "\033[33m" | |
| BLUE = "\033[34m" | |
| MAGENTA = "\033[35m" | |
| CYAN = "\033[36m" | |
| def color(text: str, *codes) -> str: | |
| """Apply color codes to text (only when color output is appropriate).""" | |
| if not should_use_color(): | |
| return text | |
| return "".join(codes) + text + Colors.RESET | |