summaryrefslogtreecommitdiff
path: root/tui/widget/list
diff options
context:
space:
mode:
Diffstat (limited to 'tui/widget/list')
-rw-r--r--tui/widget/list/scrolllist.ha32
1 files changed, 32 insertions, 0 deletions
diff --git a/tui/widget/list/scrolllist.ha b/tui/widget/list/scrolllist.ha
index 0079363..ab1e7bc 100644
--- a/tui/widget/list/scrolllist.ha
+++ b/tui/widget/list/scrolllist.ha
@@ -11,6 +11,7 @@ export type scrolllist = struct {
items: []str,
frame: frame,
cursor: int,
+ marked: []int,
};
// Return an instance of list. out is the tty file, pos the starting position,
@@ -51,6 +52,7 @@ style: (*widget::style | void), items: str...) (scrolllist | tty::error) = {
end = end,
},
cursor = 0,
+ marked = [],
};
};
@@ -70,7 +72,9 @@ fn resizescrolllist(widget: *widget::widget, ttysize: tty::ttysize) void = {
};
fn finishscrolllist(widget: *widget::widget) void = {
+ const list = widget: *scrolllist;
widget::finish(widget);
+ free(list.marked);
};
export fn down(li: *scrolllist) void = {
@@ -152,9 +156,37 @@ fn stylesscrolllist(widget: *widget::widget, txt: str, idx: size) str = {
if (idx == list.cursor) {
memio::concat(&st, "\x1B[7m")!;
};
+ if (ismarked(*list, idx) is size) {
+ memio::concat(&st, "\x1B[44m")!;
+ };
memio::concat(&st, txt)!;
if (idx == list.cursor) {
memio::concat(&st, "\x1B[27m")!;
};
+ if (ismarked(*list, idx) is size) {
+ memio::concat(&st, "\x1B[49m")!;
+ };
return strings::dup(memio::string(&st)!);
};
+
+fn ismarked(li: scrolllist, j: int) (size | void) = {
+ for (let i = 0z; i < len(li.marked); i += 1) {
+ const idx = li.marked[i];
+ if (idx == j) {
+ return i;
+ };
+ };
+ return;
+};
+
+export fn mark(li: *scrolllist) bool = {
+ defer down(li);
+ match (ismarked(*li, li.cursor)) {
+ case let s: size =>
+ delete(li.marked[s]);
+ return false;
+ case void =>
+ append(li.marked, li.cursor);
+ return true;
+ };
+};