Handle terminal resize dynamically
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
11
src/osc.nim
11
src/osc.nim
@@ -19,8 +19,8 @@ proc main() =
|
|||||||
setControlCHook(exitProc)
|
setControlCHook(exitProc)
|
||||||
hideCursor()
|
hideCursor()
|
||||||
|
|
||||||
let w = terminalWidth()
|
var w = terminalWidth()
|
||||||
let h = terminalHeight()
|
var h = terminalHeight()
|
||||||
var tb = newTerminalBuffer(w, h)
|
var tb = newTerminalBuffer(w, h)
|
||||||
|
|
||||||
crtTurnOn(tb, w, h)
|
crtTurnOn(tb, w, h)
|
||||||
@@ -30,6 +30,13 @@ proc main() =
|
|||||||
var running = true
|
var running = true
|
||||||
|
|
||||||
while running:
|
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:
|
if not scope.frozen:
|
||||||
audio.readSamples(scope)
|
audio.readSamples(scope)
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ proc initScope*(w, h: int): Scope =
|
|||||||
proc w*(s: Scope): int = s.phosphor.w
|
proc w*(s: Scope): int = s.phosphor.w
|
||||||
proc h*(s: Scope): int = s.phosphor.h
|
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 ──────────────────────────────────────────────────
|
# ── Trace rendering ──────────────────────────────────────────────────
|
||||||
|
|
||||||
proc renderTrace*(scope: var Scope) =
|
proc renderTrace*(scope: var Scope) =
|
||||||
|
|||||||
Reference in New Issue
Block a user