Skip to content

Commit f2e0303

Browse files
Kasper JungeRalphify
authored andcommitted
refactor: extract _teardown_fullscreen_unlocked to eliminate duplicated cleanup logic
The fullscreen Live stop + state clear + deferred flush sequence appeared identically in both exit_fullscreen() and _on_run_stopped(). Pulling it into _teardown_fullscreen_unlocked() means a single place to maintain. Co-authored-by: Ralphify <noreply@ralphify.co>
1 parent 8688b31 commit f2e0303

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

src/ralphify/_console_emitter.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,15 +1376,27 @@ def exit_fullscreen(self) -> None:
13761376
Live for the currently-active iteration (if any).
13771377
"""
13781378
with self._console_lock:
1379-
if self._fullscreen_view is None:
1379+
if not self._teardown_fullscreen_unlocked():
13801380
return
1381-
if self._fullscreen_live is not None:
1382-
self._fullscreen_live.stop()
1383-
self._fullscreen_live = None
1384-
self._fullscreen_view = None
1385-
self._flush_deferred_unlocked()
13861381
self._restart_compact_unlocked()
13871382

1383+
def _teardown_fullscreen_unlocked(self) -> bool:
1384+
"""Stop the fullscreen Live and clear fullscreen state.
1385+
1386+
Flushes any buffered prints so the terminal scrollback stays
1387+
consistent. Returns True if fullscreen was active, False if it
1388+
was already inactive (caller can skip any follow-up steps).
1389+
Caller must hold _console_lock.
1390+
"""
1391+
if self._fullscreen_view is None:
1392+
return False
1393+
if self._fullscreen_live is not None:
1394+
self._fullscreen_live.stop()
1395+
self._fullscreen_live = None
1396+
self._fullscreen_view = None
1397+
self._flush_deferred_unlocked()
1398+
return True
1399+
13881400
def _restart_compact_unlocked(self) -> None:
13891401
"""Bring the compact Live back after a fullscreen exit.
13901402
@@ -1575,12 +1587,7 @@ def _on_run_stopped(self, data: RunStoppedData) -> None:
15751587
# Tear down everything — the run is done. If the user is
15761588
# still inside fullscreen, exit it first and replay buffered
15771589
# prints so the terminal scrollback shows the full history.
1578-
if self._fullscreen_view is not None:
1579-
if self._fullscreen_live is not None:
1580-
self._fullscreen_live.stop()
1581-
self._fullscreen_live = None
1582-
self._fullscreen_view = None
1583-
self._flush_deferred_unlocked()
1590+
self._teardown_fullscreen_unlocked()
15841591
self._stop_live_unlocked()
15851592
if data["reason"] != STOP_COMPLETED:
15861593
return

0 commit comments

Comments
 (0)