diff options
| author | Julian Hurst <ark@mansus.space> | 2022-08-23 16:19:46 +0200 |
|---|---|---|
| committer | Julian Hurst <ark@mansus.space> | 2023-09-07 00:09:06 +0200 |
| commit | 77bb41094757361579b898b6a4d7f1707a237954 (patch) | |
| tree | 664f9f50328cabb06bf8dbe3f6679450fc90323e /libtui | |
| parent | b31e38c6e29b25c67e4c9d2a37cb6b6d05ba8280 (diff) | |
| download | hare-libtui-77bb41094757361579b898b6a4d7f1707a237954.tar.gz | |
Update hare-set and use sset for listwidget
Diffstat (limited to 'libtui')
| -rw-r--r-- | libtui/widget/list/list.ha | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/libtui/widget/list/list.ha b/libtui/widget/list/list.ha index 3bfd499..b255889 100644 --- a/libtui/widget/list/list.ha +++ b/libtui/widget/list/list.ha @@ -13,11 +13,12 @@ use regex; use fnmatch; use wcwidth; use set; +use set::sset; export type listwidget = struct { widget: widget::widget, items: []str, - marked: set::set, + marked: sset::sset, cursor: size, //listeners: []listener, frame: frame, @@ -59,7 +60,7 @@ export fn newlist(ui: libtui::ttyui, items: str...) listwidget = { ... }, items = strings::dupall(items), - marked = set::set {...}, + marked = sset::new(), cursor = 0z, //listeners = [], frame = frame { @@ -138,7 +139,7 @@ export fn print(list: *widget::widget) (void | widget::error) = { if (list.cursor == i) { strio::concat(&st, SELECTED, truncitem, RESET)?; //libtui::print(list.ui, strings::concat("\x1B[31;1m> ", list.items[i], "\x1B[0m")); - } else if (set::contains(list.marked, i) is size){ + } else if (set::contains(&list.marked, i)) { strio::concat(&st, MARKED, truncitem, RESET)?; //libtui::print(list.ui, list.items[i]); } else { @@ -344,10 +345,11 @@ export fn regexmark(l: *listwidget, re: *regex::regex) void = { // value is borrowed from the list's items. If []str is returned, the slice must // be freed. export fn selected(l: listwidget) (str | []str) = { - if (len(l.marked.items) > 0) { + if (set::length(&l.marked) > 0) { let result: []str = []; - for (let i = 0z; i < len(l.marked.items); i += 1) { - append(result, l.items[l.marked.items[i]]); + let its = set::items(&l.marked); + for (let i = 0z; i < len(its); i += 1) { + append(result, l.items[its[i]]); }; return result; } else { |
