diff options
| author | Julian Hurst <ark@mansus.space> | 2025-03-22 18:39:17 +0100 |
|---|---|---|
| committer | Julian Hurst <ark@mansus.space> | 2025-03-22 18:39:17 +0100 |
| commit | 4c3c071e7b8f34d3b77a0232ef907350a992a49e (patch) | |
| tree | dae02bea0265101493e5ad5df26713a317c5d2a3 /tui/widget/text/text.ha | |
| parent | e55266b83db116e1610b562bf186dbda94c549b4 (diff) | |
| download | hare-tui-4c3c071e7b8f34d3b77a0232ef907350a992a49e.tar.gz | |
Refactor styles to be widget specific (except border)
Diffstat (limited to 'tui/widget/text/text.ha')
| -rw-r--r-- | tui/widget/text/text.ha | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/tui/widget/text/text.ha b/tui/widget/text/text.ha index 40b3f58..0055d96 100644 --- a/tui/widget/text/text.ha +++ b/tui/widget/text/text.ha @@ -2,13 +2,25 @@ use io; use unix::tty; use tui; use tui::widget; +use strings; export type text = struct { widget: widget::widget, txt: str, + style: *style, }; -export fn newtext(state: *tui::tui, txt: str, pos: widget::coords, style: (*widget::style | void)) text = { +export def DEFAULTSTYLE = style { + style = void, + normal = widget::color::DEFAULTFG, +}; + +export type style = struct { + style: (void | *widget::style), + normal: widget::color, +}; + +export fn newtext(state: *tui::tui, txt: str, pos: widget::coords, style: *style) text = { return text { widget = widget::widget { state = state, @@ -17,11 +29,12 @@ export fn newtext(state: *tui::tui, txt: str, pos: widget::coords, style: (*widg finish = &finishtext, pos = pos, sz = void, - style = style, + style = style.style, damage = widget::damageall, ... }, txt = txt, + style = style, }; }; @@ -29,6 +42,7 @@ fn printtext(widget: *widget::widget) void = { const widget = widget: *text; widget.widget.buf = widget::linesbuf { lines = [widget.txt], + styles = &styles, ... }; widget::print(widget); @@ -45,3 +59,10 @@ export fn settext(text: *text, txt: str) void = { fn finishtext(widget: *widget::widget) void = { widget::finish(widget); }; + +fn styles(widget: *widget::widget, txt: str, idx: size) str = { + const txtw = widget: *text; + const s = widget::color_to_str(txtw.style.normal); + defer free(s); + return strings::concat(s, txt, "\x1B[0m"); +}; |
