diff options
| author | Julian Hurst <julian.hurst@digdash.com> | 2025-03-12 15:07:24 +0100 |
|---|---|---|
| committer | Julian Hurst <julian.hurst@digdash.com> | 2025-03-12 15:07:24 +0100 |
| commit | a8d7b95b05d586f3b65fbf9757fab39c8098aee9 (patch) | |
| tree | bd34e7539f2068f49a13c6c742b47f2db6c13b3e /tui/widget/text | |
| parent | 48c5f4a17840b8418cb64f6e1667da86d804ba02 (diff) | |
| download | hare-tui-a8d7b95b05d586f3b65fbf9757fab39c8098aee9.tar.gz | |
Support styling
Diffstat (limited to 'tui/widget/text')
| -rw-r--r-- | tui/widget/text/text.ha | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/tui/widget/text/text.ha b/tui/widget/text/text.ha index 5cd8da7..ecb5c2c 100644 --- a/tui/widget/text/text.ha +++ b/tui/widget/text/text.ha @@ -1,20 +1,23 @@ use io; use unix::tty; use tui::widget; +use strings; export type text = struct { widget: widget::widget, txt: str, }; -export fn newtext(out: io::file, txt: str, pos: widget::coords) text = { +export fn newtext(out: io::file, txt: str, pos: widget::coords, style: (*widget::style | void)) text = { return text { widget = widget::widget { out = out, print = &printtext, resize = &resizetext, pos = pos, - sz = widget::nosize, + sz = void, + style = style, + ... }, txt = txt, }; @@ -22,7 +25,9 @@ export fn newtext(out: io::file, txt: str, pos: widget::coords) text = { fn printtext(widget: *widget::widget) void = { const widget = widget: *text; - widget::print(widget.widget.out, widget.txt, widget.widget.pos); + widget.widget.buf = strings::dup(widget.txt); + defer free(widget.widget.buf); + widget::print(widget); }; fn resizetext(widget: *widget::widget, ttysize: tty::ttysize) void = { |
