diff options
Diffstat (limited to 'main.ha')
| -rw-r--r-- | main.ha | 183 |
1 files changed, 3 insertions, 180 deletions
@@ -9,8 +9,6 @@ use os; use strings; use unix::tty; use unix::signal; -use bufio; -use regex; let u: mainUI = mainUI {...}; @@ -21,182 +19,6 @@ type mainUI = struct { list: *list::listwidget, }; -fn globalrunehandler(ui: *libui::ttyui, r: rune) bool = { - if (r == 'q') { - return true; - }; - return false; -}; - -fn runehandler(l: *widget::widget, r: rune) bool = { - const l = l: *list::listwidget; - switch (r) { - case 'j' => - list::down(l); - case 'k' => - list::up(l); - case 'd' => - list::pagedown(l); - case 'u' => - list::pageup(l); - case 'l' => - // to print properly suspend the ui, print, then resume - libui::suspend(&l.ui); - //fmt::println(l.items[l.cursor])!; - match (list::selected(*l)) { - case let s: str => - fmt::println(s)!; - case let s: []str => - defer free(s); - const out = strings::join("\n", s...); - defer free(out); - fmt::println(out)!; - }; - libui::resume(&l.ui); - return true; - case 'g' => - list::top(l); - case 'G' => - list::bottom(l); - case 'n' => - if (searchforward) { - list::search(l, searchterm); - } else { - list::rsearch(l, searchterm); - }; - case 'N' => - if (searchforward) { - list::rsearch(l, searchterm); - } else { - list::search(l, searchterm); - }; - case '?' => - // TODO add commandline support maybe - libui::suspend(&l.ui); - fmt::fprint(l.ui.f, '?')!; - 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); - searchterm = strings::fromutf8(line); - searchforward = false; - let c = l.cursor; - list::rsearch(l, searchterm); - libui::resume(&l.ui); - case '/' => - // TODO add commandline support maybe - libui::suspend(&l.ui); - fmt::fprint(l.ui.f, '/')!; - 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); - searchterm = strings::fromutf8(line); - searchforward = true; - 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")!; - yield; - case => - let us = utf8::encoderune(r); - if (len(us) > 0 && us[0] == 13u8) { - fmt::fprintln(os::stderr, "newline")!; - }; - yield; - }; - libui::clear(l.ui); - match (list::print(l)) { - case void => - yield; - case let e: io::error => - fmt::fprintln(os::stderr, io::strerror(e))!; - return true; - case let e: tty::error => - fmt::fprintln(os::stderr, tty::strerror(e))!; - return true; - }; - return false; -}; - fn sighandler(sig: int, info: *signal::siginfo, ucontext: *void) void = { switch (sig) { case signal::SIGWINCH => @@ -221,7 +43,9 @@ export fn main() void = { defer free(in); let sin = strings::fromutf8(in); sin = strings::trim(sin, '\n'); - let items = strings::split(sin, "\n"); + let items = strings::split(sin, "\n"); // freed by list::finish + itemscopy = strings::dupall(items); + defer strings::freeall(itemscopy); let ui = libui::init(); defer libui::finish(&ui); @@ -230,7 +54,6 @@ export fn main() void = { widget::addlistener(&l, &runehandler); let layout = layout::newlayout(&l); - defer layout::finishall(&layout); //defer free(searchterm); |
