Skip to content

Commit deb7df0

Browse files
Kasper Jungeclaude
authored andcommitted
refactor: extract icon constants and simplify queue drain loop
Replace magic Unicode escape codes in _console_emitter.py with named module-level constants (_ICON_SUCCESS, _ICON_FAILURE, etc.), eliminating duplication between _on_iteration_ended and _on_checks_completed. Simplify _drain_events inner loop in app.py by removing the redundant queue.empty() check — the try/except Empty already handles termination. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9ee1672 commit deb7df0

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

src/ralphify/_console_emitter.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
from ralphify._events import Event, EventType
1616
from ralphify._output import format_duration
1717

18+
# Status icons shared by iteration and check result rendering.
19+
_ICON_SUCCESS = "\u2713" # ✓
20+
_ICON_FAILURE = "\u2717" # ✗
21+
_ICON_TIMEOUT = "\u23f1" # ⏱
22+
_ICON_ARROW = "\u2192" # →
23+
_ICON_DASH = "\u2014" # —
24+
1825

1926
class ConsoleEmitter:
2027
"""Renders engine events to the Rich console, reproducing original CLI output."""
@@ -54,15 +61,15 @@ def _on_iteration_started(self, data: dict) -> None:
5461
def _on_iteration_ended(self, data: dict) -> None:
5562
returncode = data.get("returncode")
5663
if returncode is None:
57-
color, icon = "yellow", "\u23f1"
64+
color, icon = "yellow", _ICON_TIMEOUT
5865
elif returncode == 0:
59-
color, icon = "green", "\u2713"
66+
color, icon = "green", _ICON_SUCCESS
6067
else:
61-
color, icon = "red", "\u2717"
68+
color, icon = "red", _ICON_FAILURE
6269

6370
status_msg = f"[{color}]{icon} Iteration {data['iteration']} {data['detail']}"
6471
if data.get("log_file"):
65-
status_msg += f" \u2192 {data['log_file']}"
72+
status_msg += f" {_ICON_ARROW} {data['log_file']}"
6673
status_msg += f"[/{color}]"
6774
self._rprint(status_msg)
6875

@@ -75,11 +82,11 @@ def _on_checks_completed(self, data: dict) -> None:
7582
self._rprint(f" [bold]Checks:[/bold] {', '.join(parts)}")
7683
for r in data["results"]:
7784
if r["passed"]:
78-
self._rprint(f" [green]\u2713[/green] {r['name']}")
85+
self._rprint(f" [green]{_ICON_SUCCESS}[/green] {r['name']}")
7986
elif r["timed_out"]:
80-
self._rprint(f" [yellow]\u23f1[/yellow] {r['name']} (timed out)")
87+
self._rprint(f" [yellow]{_ICON_TIMEOUT}[/yellow] {r['name']} (timed out)")
8188
else:
82-
self._rprint(f" [red]\u2717[/red] {r['name']} (exit {r['exit_code']})")
89+
self._rprint(f" [red]{_ICON_FAILURE}[/red] {r['name']} (exit {r['exit_code']})")
8390

8491
def _on_log_message(self, data: dict) -> None:
8592
msg = data.get("message", "")
@@ -98,7 +105,7 @@ def _on_run_stopped(self, data: dict) -> None:
98105
completed = data.get("completed", 0)
99106
failed = data.get("failed", 0)
100107
timed_out_count = data.get("timed_out", 0)
101-
summary = f"\n[green]Done: {total} iteration(s) \u2014 {completed} succeeded"
108+
summary = f"\n[green]Done: {total} iteration(s) {_ICON_DASH} {completed} succeeded"
102109
if failed:
103110
summary += f", {failed} failed"
104111
if timed_out_count:

src/ralphify/ui/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async def _drain_events(manager: RunManager) -> None:
2525
"""
2626
while True:
2727
for managed in manager.list_runs():
28-
while not managed.emitter.queue.empty():
28+
while True:
2929
try:
3030
event: Event = managed.emitter.queue.get_nowait()
3131
except Empty:

0 commit comments

Comments
 (0)