From 35639332a5dc8e9b26e8299c999940a9b6ca2ddb Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Sun, 15 May 2022 01:36:43 +0200 Subject: Add marking support (contains, fnmatch, regex) --- main.ha | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 2 deletions(-) (limited to 'main.ha') diff --git a/main.ha b/main.ha index 4809a18..2f96e56 100644 --- a/main.ha +++ b/main.ha @@ -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); +}; -- cgit v1.2.3