summaryrefslogtreecommitdiff
path: root/tui/widget/widget.ha
diff options
context:
space:
mode:
Diffstat (limited to 'tui/widget/widget.ha')
-rw-r--r--tui/widget/widget.ha19
1 files changed, 12 insertions, 7 deletions
diff --git a/tui/widget/widget.ha b/tui/widget/widget.ha
index dbbfa11..f2510c6 100644
--- a/tui/widget/widget.ha
+++ b/tui/widget/widget.ha
@@ -100,10 +100,18 @@ export fn print(w: *widget) void = {
fmt::fprintf(w.out, "\x1B[{};{}H", w.pos.0, w.pos.1)!;
let s = truncate_to_size(w);
+ defer free(s);
- let sstyle = match (w.style) {
+ let sstyle = applystyles(w.style, s);
+ defer free(sstyle);
+
+ fmt::fprint(w.out, sstyle)!;
+};
+
+// Applies styling (style) to the given string
+fn applystyles(st: (*style | void), s: str) str = {
+ return match (st) {
case let st: *style =>
- defer free(s);
let sborder = if (st.border) {
yield border(s);
} else {
@@ -116,12 +124,8 @@ export fn print(w: *widget) void = {
defer free(defcolor);
yield strings::concat(scolor, sborder, defcolor);
case void =>
- yield s;
+ yield strings::dup(s);
};
-
- defer free(sstyle);
-
- fmt::fprint(w.out, sstyle)!;
};
// Truncates the text of the widget to the widget's size (rows and columns) and
@@ -148,6 +152,7 @@ fn truncate_to_size(w: *widget) str = {
return strings::dup(memio::string(&st)!);
};
+// Add a border around a string
fn border(s: str) str = {
let st = memio::dynamic();
defer io::close(&st)!;