From e074c936bb99ccfce311445f4dbf42ba964b44a4 Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Wed, 12 Mar 2025 22:36:13 +0100 Subject: Implement global state and clear scheduling --- tui/tui.ha | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'tui/tui.ha') diff --git a/tui/tui.ha b/tui/tui.ha index 871f847..4f6c1d5 100644 --- a/tui/tui.ha +++ b/tui/tui.ha @@ -2,13 +2,30 @@ use fmt; use io; use unix::tty; -export fn init() (io::file | tty::error) = { +export type tui = struct { + out: io::file, + clear: bool, +}; + +export fn init() (tui | tty::error) = { const f = tty::open()?; - clear(f); - return f; + doclear(f); + return tui { + out = f, + clear = false, + }; }; -export fn clear(out: io::file) void = { +fn doclear(out: io::file) void = { fmt::fprint(out, "\x1B[2J\x1B[1;1H")!; }; + +export fn clear(state: *tui) void = { + state.clear = true; + //fmt::fprint(out, "\x1B[2J\x1B[1;1H")!; +}; + +export fn finish(state: *tui) void = { + io::close(state.out)!; +}; -- cgit v1.2.3