Skip to content

Commit 26f3dc7

Browse files
Kasper JungeRalphify
authored andcommitted
refactor: extract _peek_status_msg to eliminate duplicated peek message conditional
The structured-vs-raw peek message selection was duplicated in both toggle_peek() and _on_run_started(). Centralizing it in a single helper makes the logic easier to follow and provides one place to change if the messages evolve. Co-authored-by: Ralphify <noreply@ralphify.co>
1 parent 800528f commit 26f3dc7

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

src/ralphify/_console_emitter.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,12 @@ def wants_agent_output_lines(self) -> bool:
859859
# always called regardless of this gate.
860860
return self._peek_enabled
861861

862+
def _peek_status_msg(self, enabled: bool) -> str:
863+
"""Return the peek status message for the given on/off state."""
864+
if not enabled:
865+
return _PEEK_OFF_MSG
866+
return _PEEK_ON_MSG_STRUCTURED if self._structured_agent else _PEEK_ON_MSG_RAW
867+
862868
def toggle_peek(self) -> bool:
863869
"""Flip live-output rendering on or off.
864870
@@ -870,14 +876,7 @@ def toggle_peek(self) -> bool:
870876
with self._console_lock:
871877
self._peek_enabled = not self._peek_enabled
872878
enabled = self._peek_enabled
873-
if enabled:
874-
msg = (
875-
_PEEK_ON_MSG_STRUCTURED
876-
if self._structured_agent
877-
else _PEEK_ON_MSG_RAW
878-
)
879-
else:
880-
msg = _PEEK_OFF_MSG
879+
msg = self._peek_status_msg(enabled)
881880

882881
renderable = self._active_renderable
883882
if renderable is not None:
@@ -945,12 +944,7 @@ def _on_run_started(self, data: RunStartedData) -> None:
945944
if info:
946945
self._console.print(f" [dim]{info}[/]")
947946
if self._peek_enabled:
948-
msg = (
949-
_PEEK_ON_MSG_STRUCTURED
950-
if self._structured_agent
951-
else _PEEK_ON_MSG_RAW
952-
)
953-
self._console.print(msg)
947+
self._console.print(self._peek_status_msg(True))
954948

955949
def _start_live_unlocked(self) -> None:
956950
"""Start the iteration panel. Caller must hold ``_console_lock``."""

0 commit comments

Comments
 (0)