Use shared ANSI stripping in Hermes Console
This commit is contained in:
parent
f7d90edd8b
commit
1e7111d25d
2 changed files with 34 additions and 9 deletions
|
|
@ -9,11 +9,10 @@ from __future__ import annotations
|
|||
|
||||
import argparse
|
||||
import contextlib
|
||||
import importlib
|
||||
import difflib
|
||||
import importlib
|
||||
import io
|
||||
import json
|
||||
import re
|
||||
import shlex
|
||||
import sys
|
||||
from dataclasses import dataclass, replace
|
||||
|
|
@ -21,6 +20,8 @@ from pathlib import Path
|
|||
from typing import Callable, Iterable, Literal, NoReturn, Sequence
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from tools.ansi_strip import strip_ansi as _strip_ansi
|
||||
|
||||
|
||||
ConsoleStatus = Literal["ok", "error", "confirm_required", "exit", "clear"]
|
||||
ConsoleContext = Literal["local", "hosted"]
|
||||
|
|
@ -73,13 +74,6 @@ def _capture_output(fn: Callable[[], object]) -> str:
|
|||
return text.rstrip()
|
||||
|
||||
|
||||
_ANSI_RE = re.compile(r"\x1b\[[0-?]*[ -/]*[@-~]")
|
||||
|
||||
|
||||
def _strip_ansi(text: str) -> str:
|
||||
return _ANSI_RE.sub("", text)
|
||||
|
||||
|
||||
def _is_status_footer_rule(line: str) -> bool:
|
||||
stripped = _strip_ansi(line).strip()
|
||||
if len(stripped) < 8:
|
||||
|
|
|
|||
|
|
@ -271,6 +271,37 @@ def test_console_status_hides_cli_next_step_footer(
|
|||
assert "\u2500" not in result.output
|
||||
|
||||
|
||||
def test_console_status_hides_osc_linked_cli_next_step_footer(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
_isolate_hermes_home,
|
||||
):
|
||||
import hermes_cli.status as status_mod
|
||||
|
||||
def osc_link(text: str) -> str:
|
||||
return f"\x1b]8;;https://example.test\x1b\\{text}\x1b]8;;\x1b\\"
|
||||
|
||||
def fake_show_status(_args):
|
||||
print("◆ Sessions")
|
||||
print("Active: 3 session(s)")
|
||||
print()
|
||||
print(osc_link("\u2500" * 60))
|
||||
print(osc_link(" Run 'hermes doctor' for detailed diagnostics"))
|
||||
print(osc_link(" Run 'hermes setup' to configure"))
|
||||
print()
|
||||
|
||||
monkeypatch.setattr(status_mod, "show_status", fake_show_status)
|
||||
|
||||
result = HermesConsoleEngine().execute("status")
|
||||
|
||||
assert result.status == "ok"
|
||||
assert "Sessions" in result.output
|
||||
assert "Active: 3 session(s)" in result.output
|
||||
assert "hermes doctor" not in result.output
|
||||
assert "hermes setup" not in result.output
|
||||
assert "https://example.test" not in result.output
|
||||
assert "\u2500" not in result.output
|
||||
|
||||
|
||||
def test_console_help_uses_cli_subcommand_summaries():
|
||||
help_text = HermesConsoleEngine().help_text()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue