aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Hurst <ark@mansus.space>2022-05-17 17:23:15 +0200
committerJulian Hurst <ark@mansus.space>2022-05-17 17:23:15 +0200
commit5e1a84d707b0ef7f8a80868870a7f2fc12f75a31 (patch)
treedaab3945317927e1eca324e308cba1afdf3d293c
parenta421424dda24a25f5e8c0387fff54296d821e8bb (diff)
downloadilhare-5e1a84d707b0ef7f8a80868870a7f2fc12f75a31.tar.gz
Create consts for ansi colour codes in list
-rw-r--r--libui/widget/list/list.ha16
1 files changed, 8 insertions, 8 deletions
diff --git a/libui/widget/list/list.ha b/libui/widget/list/list.ha
index efed759..6506ce1 100644
--- a/libui/widget/list/list.ha
+++ b/libui/widget/list/list.ha
@@ -96,6 +96,10 @@ export fn setitems(list: *listwidget, items: str...) void = {
//append(list.listeners, l);
//};
+const SELECTED: str = "\x1B[104;1m\x1B[30m";
+const MARKED: str = "\x1B[46;1m\x1B[30m";
+const RESET: str = "\x1B[0m";
+
// Print the list's items while truncating the items to not be wider than the
// list.sz.cols.
export fn print(list: *widget::widget) (void | widget::error) = {
@@ -114,17 +118,13 @@ export fn print(list: *widget::widget) (void | widget::error) = {
let st = strio::dynamic();
strio::concat(&st, "\r")?;
for (let i = list.frame.start; i < list.frame.end: u16; i += 1) {
- let item = list.items[i];
- let truncitem = wcwidth::truncate(item, list.sz.cols);
+ const item = list.items[i];
+ const truncitem = wcwidth::truncate(item, list.sz.cols);
if (list.cursor == i) {
- strio::concat(&st, "\x1B[104;1m\x1B[30m")?;
- strio::concat(&st, truncitem)?;
- strio::concat(&st, "\x1B[0m")?;
+ strio::concat(&st, SELECTED, truncitem, RESET)?;
//libui::print(list.ui, strings::concat("\x1B[31;1m> ", list.items[i], "\x1B[0m"));
} else if (set::contains(list.marked, i) is size){
- strio::concat(&st, "\x1B[46;1m\x1B[30m")?;
- strio::concat(&st, truncitem)?;
- strio::concat(&st, "\x1B[0m")?;
+ strio::concat(&st, MARKED, truncitem, RESET)?;
//libui::print(list.ui, list.items[i]);
} else {
strio::concat(&st, truncitem)?;