From 1f320b7ff1421b76afc9d1634bc2c8b01b60e329 Mon Sep 17 00:00:00 2001 From: rolandnsharp Date: Sun, 5 Apr 2026 19:59:01 +1000 Subject: [PATCH] Handle terminal resize dynamically Co-Authored-By: Claude Opus 4.6 (1M context) --- src/osc.nim | 11 +++++++++-- src/osc/scope.nim | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/osc.nim b/src/osc.nim index 7162168..7f07396 100644 --- a/src/osc.nim +++ b/src/osc.nim @@ -19,8 +19,8 @@ proc main() = setControlCHook(exitProc) hideCursor() - let w = terminalWidth() - let h = terminalHeight() + var w = terminalWidth() + var h = terminalHeight() var tb = newTerminalBuffer(w, h) crtTurnOn(tb, w, h) @@ -30,6 +30,13 @@ proc main() = var running = true while running: + let nw = terminalWidth() + let nh = terminalHeight() + if nw != w or nh != h: + w = nw + h = nh + scope.resize(w, h) + if not scope.frozen: audio.readSamples(scope) diff --git a/src/osc/scope.nim b/src/osc/scope.nim index d85830c..8cb918a 100644 --- a/src/osc/scope.nim +++ b/src/osc/scope.nim @@ -39,6 +39,10 @@ proc initScope*(w, h: int): Scope = proc w*(s: Scope): int = s.phosphor.w proc h*(s: Scope): int = s.phosphor.h +proc resize*(scope: var Scope, w, h: int) = + if w == scope.w and h == scope.h: return + scope.phosphor = initPhosphor(w, h) + # ── Trace rendering ────────────────────────────────────────────────── proc renderTrace*(scope: var Scope) =