diff options
Diffstat (limited to 'cmd/il.ha')
| -rw-r--r-- | cmd/il.ha | 71 |
1 files changed, 66 insertions, 5 deletions
@@ -1,4 +1,5 @@ use tui; +use tui::widget; use tui::widget::list; use tui::layout; use bufio; @@ -6,8 +7,55 @@ use os; use strings; use fmt; use io; +use getopt; + +fn strtocolor(s: str, df: widget::color) widget::color = { + return switch (s) { + case "red" => + yield widget::color::REDFG; + case "blue" => + yield widget::color::BLUEFG; + case "green" => + yield widget::color::GREENFG; + case "brown" => + yield widget::color::BROWNFG; + case "cyan" => + yield widget::color::CYANFG; + case "black" => + yield widget::color::BLACKFG; + case "white" => + yield widget::color::WHITEFG; + case "magenta" => + yield widget::color::MAGENTAFG; + case => + yield widget::color::DEFAULTFG; + }; +}; export fn main() void = { + const cmd = getopt::parse(os::args, + "interactive list", + ('n', "colour", "normal colour"), + ('m', "colour", "marked colour"), + ('b', "draw border"), + ); + defer getopt::finish(&cmd); + + let normalst = list::DEFAULTSTYLE.normal; + let markedst = list::DEFAULTSTYLE.marked; + let border = false; + for (let opt .. cmd.opts) { + switch (opt.0) { + case 'n' => + normalst = strtocolor(opt.1, normalst); + case 'm' => + markedst = strtocolor(opt.1, markedst) + 10; + case 'b' => + border = true; + case => abort(); + }; + }; + const scanner = bufio::newscanner(os::stdin); defer bufio::finish(&scanner); @@ -32,11 +80,24 @@ export fn main() void = { const state = tui::init()!; defer tui::finish(&state); - let li = list::newscrolllist( + //let li = list::newlist( + // &state, + // (1, 1), + // void, + // &list::DEFAULTSTYLE, + // items... + //)!; + let li = list::newlist( &state, (1, 1), void, - void, + &list::style { + style = &widget::style { + border = border, + }, + normal = normalst, + marked = markedst, + }, items... )!; let vl = layout::newvlayout(&li); @@ -107,7 +168,7 @@ export fn main() void = { }; }; -fn search(state: *tui::tui, li: *list::scrolllist, prefix: (str | rune) = '/') (str | void) = { +fn search(state: *tui::tui, li: *list::list, prefix: (str | rune) = '/') (str | void) = { tui::unraw(state); defer tui::raw(state)!; fmt::fprint(state.out, prefix)!; @@ -121,7 +182,7 @@ fn search(state: *tui::tui, li: *list::scrolllist, prefix: (str | rune) = '/') ( return strings::dup(strings::fromutf8(uline)!); }; -fn nextsearch(li: *list::scrolllist, term: (str | void)) void = { +fn nextsearch(li: *list::list, term: (str | void)) void = { const term = match (term) { case let term: str => yield term; @@ -136,7 +197,7 @@ fn nextsearch(li: *list::scrolllist, term: (str | void)) void = { }; }; -fn prevsearch(li: *list::scrolllist, term: (str | void)) void = { +fn prevsearch(li: *list::list, term: (str | void)) void = { const term = match (term) { case let term: str => yield term; |
