Module: Thaum::Suspender
- Defined in:
- lib/thaum/run_loop.rb
Overview
Handles a dequeued :suspend sentinel: tear the terminal down, actually stop the process, then on resume re-setup, repartition with current size, and force a re-render. Drains stray sentinels that arrive between teardown and resume. Internal — not delivered to App handlers per the spec.
Class Method Summary collapse
Class Method Details
.drain_until_resume(queue:) ⇒ Object
173 174 175 176 177 178 179 180 |
# File 'lib/thaum/run_loop.rb', line 173 def drain_until_resume(queue:) loop do msg = queue.pop break if msg == :resume # Ignore everything else during the suspended window — we # re-render from scratch on resume anyway. end end |
.suspend(app:, terminal:, queue:) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/thaum/run_loop.rb', line 153 def suspend(app:, terminal:, queue:) Thaum.safe_invoke("Terminal#teardown(suspend)") { terminal.teardown } # Reset TSTP to default so kill("TSTP", pid) actually stops us. prev_tstp = Signal.trap("TSTP", "DEFAULT") Process.kill("TSTP", Process.pid) # ── process is stopped here; resumes when shell sends SIGCONT ── Signal.trap("TSTP", prev_tstp) drain_until_resume(queue:) Thaum.safe_invoke("Terminal#setup(resume)") { terminal.setup } cols, rows = terminal.size Thaum.safe_invoke("App#run_partition(resume)") do app.run_partition(rect: Rect.new(x: 0, y: 0, width: cols, height: rows)) end app.request_render [cols, rows] end |