diff options
| author | Julian Hurst <ark@mansus.space> | 2025-03-12 04:14:25 +0100 |
|---|---|---|
| committer | Julian Hurst <ark@mansus.space> | 2025-03-12 04:14:25 +0100 |
| commit | fcff38543be6a1b321641f26aa349cf0f02d66bb (patch) | |
| tree | a265e8c61ecbb3d73293cd47d5dd39b69794578c /tui | |
| download | hare-tui-fcff38543be6a1b321641f26aa349cf0f02d66bb.tar.gz | |
Initial commit
Diffstat (limited to 'tui')
| -rw-r--r-- | tui/layout/layout.ha | 14 | ||||
| -rw-r--r-- | tui/layout/vlayout.ha | 26 | ||||
| -rw-r--r-- | tui/tui.ha | 14 | ||||
| -rw-r--r-- | tui/widget/widget.ha | 26 |
4 files changed, 80 insertions, 0 deletions
diff --git a/tui/layout/layout.ha b/tui/layout/layout.ha new file mode 100644 index 0000000..d425891 --- /dev/null +++ b/tui/layout/layout.ha @@ -0,0 +1,14 @@ +use tui::widget; + +export type printfn = fn(l: *layout) void; +export type finishfn = fn(l: *layout) void; + +export type layout = struct { + widgets: []*widget::widget, + print: *printfn, + finish: *finishfn, +}; + +fn finish(l: *layout) void = { + free(l.widgets); +}; diff --git a/tui/layout/vlayout.ha b/tui/layout/vlayout.ha new file mode 100644 index 0000000..0381a9f --- /dev/null +++ b/tui/layout/vlayout.ha @@ -0,0 +1,26 @@ +use tui::widget; + +export type vlayout = struct { + layout: layout, +}; + +export fn newvlayout(widgets: *widget::widget...) vlayout = { + return vlayout { + layout = layout { + widgets = widgets, + print = &printvlayout, + finish = &finishvlayout, + }, + }; +}; + +fn printvlayout(l: *layout) void = { + for (let widget .. l.widgets) { + widget.print(widget); + }; +}; + +fn finishvlayout(l: *layout) void = { + let vl = l: *vlayout; + finish(&vl.layout); +}; diff --git a/tui/tui.ha b/tui/tui.ha new file mode 100644 index 0000000..871f847 --- /dev/null +++ b/tui/tui.ha @@ -0,0 +1,14 @@ +use fmt; +use io; +use unix::tty; + +export fn init() (io::file | tty::error) = { + const f = tty::open()?; + clear(f); + return f; + +}; + +export fn clear(out: io::file) void = { + fmt::fprint(out, "\x1B[2J\x1B[1;1H")!; +}; diff --git a/tui/widget/widget.ha b/tui/widget/widget.ha new file mode 100644 index 0000000..cb202be --- /dev/null +++ b/tui/widget/widget.ha @@ -0,0 +1,26 @@ +use fmt; +use unix::tty; +use io; + +export type coords = (u16, u16); + +export type printfn = fn(w: *widget) void; +export type resizefn = fn(w: *widget, ttysize: tty::ttysize) void; + +export type nosize = void; +export type widgetsize = (tty::ttysize | nosize); + +export type widget = struct { + out: io::file, + print: *printfn, + resize: *resizefn, + pos: coords, + sz: widgetsize, +}; + +def gotoroot: str = "\x1B[1;1f"; + +export fn print(out: io::file, s: str, pos: coords) void = { + fmt::fprintf(out, "\x1B[{};{}H", pos.0, pos.1)!; + fmt::fprint(out, s)!; +}; |
