summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/il.ha12
-rw-r--r--tui/widget/list/scrolllist.ha32
2 files changed, 43 insertions, 1 deletions
diff --git a/cmd/il.ha b/cmd/il.ha
index 74b4e76..2101a65 100644
--- a/cmd/il.ha
+++ b/cmd/il.ha
@@ -79,7 +79,14 @@ export fn main() void = {
break;
};
if (r == 'l') {
- fmt::println(li.items[li.cursor])!;
+ tui::unraw(&state);
+ if (len(li.marked) > 0) {
+ for (let idx .. li.marked) {
+ fmt::println(li.items[idx])!;
+ };
+ } else {
+ fmt::println(li.items[li.cursor])!;
+ };
break;
};
if (r == '/' || r == '?') {
@@ -93,6 +100,9 @@ export fn main() void = {
if (r == 'N') {
if (!revsearch) prevsearch(&li, term) else nextsearch(&li, term);
};
+ if (r == 'm') {
+ list::mark(&li);
+ };
vl.layout.print(&vl);
};
};
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;
+ };
+};