summaryrefslogtreecommitdiff
path: root/cmd/il.ha
diff options
context:
space:
mode:
authorJulian Hurst <ark@mansus.space>2025-03-22 18:39:17 +0100
committerJulian Hurst <ark@mansus.space>2025-03-22 18:39:17 +0100
commit4c3c071e7b8f34d3b77a0232ef907350a992a49e (patch)
treedae02bea0265101493e5ad5df26713a317c5d2a3 /cmd/il.ha
parente55266b83db116e1610b562bf186dbda94c549b4 (diff)
downloadhare-tui-4c3c071e7b8f34d3b77a0232ef907350a992a49e.tar.gz
Refactor styles to be widget specific (except border)
Diffstat (limited to 'cmd/il.ha')
-rw-r--r--cmd/il.ha63
1 files changed, 62 insertions, 1 deletions
diff --git a/cmd/il.ha b/cmd/il.ha
index 2101a65..e0b5f3a 100644
--- a/cmd/il.ha
+++ b/cmd/il.ha
@@ -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(
+ // &state,
+ // (1, 1),
+ // void,
+ // &list::DEFAULTSTYLE,
+ // items...
+ //)!;
let li = list::newscrolllist(
&state,
(1, 1),
void,
- void,
+ &list::liststyle {
+ style = &widget::style {
+ border = border,
+ },
+ normal = normalst,
+ marked = markedst,
+ },
items...
)!;
let vl = layout::newvlayout(&li);