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 --- cmd/list.ha | 6 +++--- cmd/list_nostyle.ha | 6 +++--- cmd/list_strictsz.ha | 6 +++--- cmd/text.ha | 20 +++++++++++++++++--- 4 files changed, 26 insertions(+), 12 deletions(-) (limited to 'cmd') diff --git a/cmd/list.ha b/cmd/list.ha index 0148adb..1db46b4 100644 --- a/cmd/list.ha +++ b/cmd/list.ha @@ -8,9 +8,9 @@ use fmt; use time; export fn main() void = { - const out = tui::init()!; - defer io::close(out)!; - let li = list::newlist(out, (1, 1), void, &widget::style { + const state = tui::init()!; + defer tui::finish(&state); + let li = list::newlist(&state, (1, 1), void, &widget::style { border = true, colorfg = widget::color::REDFG, colorbg = widget::color::REDBG, diff --git a/cmd/list_nostyle.ha b/cmd/list_nostyle.ha index 4e77955..4454220 100644 --- a/cmd/list_nostyle.ha +++ b/cmd/list_nostyle.ha @@ -8,9 +8,9 @@ use fmt; use time; export fn main() void = { - const out = tui::init()!; - defer io::close(out)!; - let li = list::newlist(out, (1, 1), void, void,"hello", "world", "bye", "world")!; + const state = tui::init()!; + defer tui::finish(&state); + let li = list::newlist(&state, (1, 1), void, void,"hello", "world", "bye", "world")!; let l = layout::newvlayout(&li); l.layout.print(&l); }; diff --git a/cmd/list_strictsz.ha b/cmd/list_strictsz.ha index 13c2808..e0a371d 100644 --- a/cmd/list_strictsz.ha +++ b/cmd/list_strictsz.ha @@ -8,9 +8,9 @@ use fmt; use time; export fn main() void = { - const out = tui::init()!; - defer io::close(out)!; - let li = list::newlist(out, (1, 1), tty::ttysize { + const state = tui::init()!; + defer tui::finish(&state); + let li = list::newlist(&state, (1, 1), tty::ttysize { rows = 3, columns = 4, }, &widget::style { diff --git a/cmd/text.ha b/cmd/text.ha index 3ec0f2a..f7ce1fc 100644 --- a/cmd/text.ha +++ b/cmd/text.ha @@ -7,9 +7,9 @@ use fmt; use time; export fn main() void = { - const out = tui::init()!; - defer io::close(out)!; - let txt = text::newtext(out, "hello world", (50, 20), &widget::style { + const state = tui::init()!; + defer tui::finish(&state); + let txt = text::newtext(&state, "hello world", (50, 20), &widget::style { border = true, colorfg = widget::color::REDFG, colorbg = widget::color::REDBG, @@ -17,32 +17,46 @@ export fn main() void = { let l = layout::newvlayout(&txt); l.layout.print(&l); + tui::clear(&state); + time::sleep(1 * time::SECOND); let st = txt.widget.style as *widget::style; st.colorfg = widget::color::GREENFG; text::settext(&txt, "bye world"); l.layout.print(&l); + tui::clear(&state); + time::sleep(1 * time::SECOND); st.colorfg = widget::color::BROWNFG; l.layout.print(&l); + tui::clear(&state); + time::sleep(1 * time::SECOND); st.colorfg = widget::color::BLUEFG; l.layout.print(&l); + tui::clear(&state); + time::sleep(1 * time::SECOND); st.colorfg = widget::color::MAGENTAFG; l.layout.print(&l); + tui::clear(&state); + time::sleep(1 * time::SECOND); st.colorfg = widget::color::CYANFG; l.layout.print(&l); + tui::clear(&state); + time::sleep(1 * time::SECOND); st.colorfg = widget::color::WHITEFG; l.layout.print(&l); + tui::clear(&state); + time::sleep(1 * time::SECOND); st.colorfg = widget::color::DEFAULTFG; l.layout.print(&l); -- cgit v1.2.3