diff options
| author | Julian Hurst <julian.hurst92@gmail.com> | 2022-05-15 01:36:43 +0200 |
|---|---|---|
| committer | Julian Hurst <julian.hurst92@gmail.com> | 2022-05-15 01:36:43 +0200 |
| commit | 35639332a5dc8e9b26e8299c999940a9b6ca2ddb (patch) | |
| tree | 909bdfc2f6354aa25721ac67e9441c430d3b46e6 /main.ha | |
| parent | 1aece8326ee62e242f308c3dbeb5f2bb5e2d53b9 (diff) | |
| download | ilhare-35639332a5dc8e9b26e8299c999940a9b6ca2ddb.tar.gz | |
Add marking support (contains, fnmatch, regex)
Diffstat (limited to 'main.ha')
| -rw-r--r-- | main.ha | 79 |
1 files changed, 77 insertions, 2 deletions
@@ -8,6 +8,7 @@ use strings; use unix::tty; use unix::signal; use bufio; +use regex; let u: mainUI = mainUI {...}; @@ -34,7 +35,15 @@ fn runehandler(l: *list::listwidget, r: rune) bool = { case 'l' => // to print properly suspend the ui, print, then resume libui::suspend(&l.ui); - fmt::println(l.items[l.cursor])!; + //fmt::println(l.items[l.cursor])!; + match (list::selected(*l)) { + case let s: str => + fmt::println(s)!; + case let s: []str => + const out = strings::join("\n", s...); + defer free(out); + fmt::println(out)!; + }; libui::resume(&l.ui); return true; case 'g' => @@ -93,6 +102,68 @@ fn runehandler(l: *list::listwidget, r: rune) bool = { let c = l.cursor; list::search(l, searchterm); libui::resume(&l.ui); + case 's' => + // TODO add commandline support maybe + libui::suspend(&l.ui); + fmt::fprint(l.ui.f, "s: ")!; + let line = match (bufio::scanline(l.ui.f)) { + case let s: []u8 => + yield s; + case io::EOF => + fmt::fprintln(os::stderr, "EOF")!; + return true; + case let e: io::error => + fmt::fprintln(os::stderr, io::strerror(e))!; + return true; + }; + defer free(line); + list::containsmark(l, strings::fromutf8(line)); + libui::resume(&l.ui); + case 'S' => + // TODO add commandline support maybe + libui::suspend(&l.ui); + fmt::fprint(l.ui.f, "S: ")!; + let line = match (bufio::scanline(l.ui.f)) { + case let s: []u8 => + yield s; + case io::EOF => + fmt::fprintln(os::stderr, "EOF")!; + return true; + case let e: io::error => + fmt::fprintln(os::stderr, io::strerror(e))!; + return true; + }; + defer free(line); + list::fnmatchmark(l, strings::fromutf8(line)); + libui::resume(&l.ui); + case 'r' => + // TODO add commandline support maybe + libui::suspend(&l.ui); + fmt::fprint(l.ui.f, "r: ")!; + let line = match (bufio::scanline(l.ui.f)) { + case let s: []u8 => + yield s; + case io::EOF => + fmt::fprintln(os::stderr, "EOF")!; + return true; + case let e: io::error => + fmt::fprintln(os::stderr, io::strerror(e))!; + return true; + }; + defer free(line); + match (regex::compile(strings::fromutf8(line))) { + case let re: regex::regex => + list::regexmark(l, &re); + regex::finish(&re); + case let e: regex::error => + fmt::fprintln(os::stderr, regex::strerror(e))!; + }; + libui::resume(&l.ui); + case ' ' => + list::tmark(l); + list::down(l); + case 'c' => + list::clearmarked(l); case '\n' => // For some reason enter doesn't send r == '\n' fmt::fprintln(os::stderr, "This is not detected")!; @@ -151,7 +222,7 @@ export fn main() void = { let l = list::newlist(ui, items...); libui::addlistener(&ui, &globalrunehandler); list::addlistener(&l, &runehandler); - defer free(searchterm); + //defer free(searchterm); libui::clear(l.ui); match (list::print(&l)) { case void => @@ -189,3 +260,7 @@ export fn main() void = { }; }; }; + +@fini fn finish() void = { + free(searchterm); +}; |
