feat(cli): implement true-color ANSI support for response text

- Added support for true-color ANSI escape codes in the HermesCLI to enhance the visual appearance of streamed content.
- Introduced a fallback mechanism for text color in case of errors while retrieving the color from the active skin.
- Updated the output formatting to include the new text color in both line emissions and buffer flushing.

These changes improve the user experience by ensuring consistent and visually appealing text output in the command-line interface.
This commit is contained in:
Test
2026-03-20 21:02:34 -07:00
parent 45058b4105
commit f7e2ed20fa

18
cli.py
View File

@@ -1620,8 +1620,19 @@ class HermesCLI:
from hermes_cli.skin_engine import get_active_skin
_skin = get_active_skin()
label = _skin.get_branding("response_label", "⚕ Hermes")
_text_hex = _skin.get_color("banner_text", "#FFF8DC")
except Exception:
label = "⚕ Hermes"
_text_hex = "#FFF8DC"
# Build a true-color ANSI escape for the response text color
# so streamed content matches the Rich Panel appearance.
try:
_r = int(_text_hex[1:3], 16)
_g = int(_text_hex[3:5], 16)
_b = int(_text_hex[5:7], 16)
self._stream_text_ansi = f"\033[38;2;{_r};{_g};{_b}m"
except (ValueError, IndexError):
self._stream_text_ansi = ""
w = shutil.get_terminal_size().columns
fill = w - 2 - len(label)
_cprint(f"\n{_GOLD}╭─{label}{'' * max(fill - 1, 0)}{_RST}")
@@ -1629,9 +1640,10 @@ class HermesCLI:
self._stream_buf += text
# Emit complete lines, keep partial remainder in buffer
_tc = getattr(self, "_stream_text_ansi", "")
while "\n" in self._stream_buf:
line, self._stream_buf = self._stream_buf.split("\n", 1)
_cprint(line)
_cprint(f"{_tc}{line}{_RST}" if _tc else line)
def _flush_stream(self) -> None:
"""Emit any remaining partial line from the stream buffer and close the box."""
@@ -1639,7 +1651,8 @@ class HermesCLI:
self._close_reasoning_box()
if self._stream_buf:
_cprint(self._stream_buf)
_tc = getattr(self, "_stream_text_ansi", "")
_cprint(f"{_tc}{self._stream_buf}{_RST}" if _tc else self._stream_buf)
self._stream_buf = ""
# Close the response box
@@ -1652,6 +1665,7 @@ class HermesCLI:
self._stream_buf = ""
self._stream_started = False
self._stream_box_opened = False
self._stream_text_ansi = ""
self._stream_prefilt = ""
self._in_reasoning_block = False
self._reasoning_box_opened = False