summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/il.ha71
-rw-r--r--cmd/list.ha10
-rw-r--r--cmd/list_nostyle.ha3
-rw-r--r--cmd/list_strictsz.ha14
-rw-r--r--cmd/text.ha22
5 files changed, 90 insertions, 30 deletions
diff --git a/cmd/il.ha b/cmd/il.ha
index be3573c..7ccacb8 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(
+ //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;
diff --git a/cmd/list.ha b/cmd/list.ha
index 348083e..eacd69c 100644
--- a/cmd/list.ha
+++ b/cmd/list.ha
@@ -10,10 +10,12 @@ use time;
export fn main() void = {
const state = tui::init()!;
defer tui::finish(&state);
- let li = list::newlist(&state, (1, 1), void, &widget::style {
- border = true,
- colorfg = widget::color::REDFG,
- colorbg = widget::color::REDBG,
+ let li = list::newlist(&state, (1, 1), void, &list::style {
+ style = &widget::style {
+ border = true,
+ },
+ normal = widget::color::REDFG,
+ marked = widget::color::BLUEBG,
},"hello", "world", "bye", "world")!;
let l = layout::newvlayout(&li);
diff --git a/cmd/list_nostyle.ha b/cmd/list_nostyle.ha
index 4454220..133d137 100644
--- a/cmd/list_nostyle.ha
+++ b/cmd/list_nostyle.ha
@@ -4,13 +4,12 @@ use tui::widget;
use tui::widget::list;
use unix::tty;
use io;
-use fmt;
use time;
export fn main() void = {
const state = tui::init()!;
defer tui::finish(&state);
- let li = list::newlist(&state, (1, 1), void, void,"hello", "world", "bye", "world")!;
+ let li = list::newlist(&state, (1, 1), void, &list::DEFAULTSTYLE,"hello", "world", "bye", "world")!;
let l = layout::newvlayout(&li);
l.layout.print(&l);
};
diff --git a/cmd/list_strictsz.ha b/cmd/list_strictsz.ha
index e0a371d..2396e3c 100644
--- a/cmd/list_strictsz.ha
+++ b/cmd/list_strictsz.ha
@@ -4,7 +4,6 @@ use tui::widget;
use tui::widget::list;
use unix::tty;
use io;
-use fmt;
use time;
export fn main() void = {
@@ -13,11 +12,14 @@ export fn main() void = {
let li = list::newlist(&state, (1, 1), tty::ttysize {
rows = 3,
columns = 4,
- }, &widget::style {
- border = true,
- colorfg = widget::color::BLUEFG,
- colorbg = widget::color::BLUEBG,
- }, "hello", "world", "bye", "world")!;
+ }, &list::style {
+ style = &widget::style {
+ border = true,
+ },
+ normal = widget::color::DEFAULTFG,
+ marked = widget::color::DEFAULTBG,
+ },
+ "hel🎉", "world", "bye", "world")!;
let l = layout::newvlayout(&li);
l.layout.print(&l);
};
diff --git a/cmd/text.ha b/cmd/text.ha
index 7c569a8..f8696ee 100644
--- a/cmd/text.ha
+++ b/cmd/text.ha
@@ -9,55 +9,51 @@ use time;
export fn main() void = {
const state = tui::init()!;
defer tui::finish(&state);
- let txt = text::newtext(&state, "hello world", (50, 20), &widget::style {
- border = true,
- colorfg = widget::color::REDFG,
- colorbg = widget::color::REDBG,
- });
+ let txt = text::newtext(&state, "hello world", (50, 20), &text::DEFAULTSTYLE);
let l = layout::newvlayout(&txt);
l.layout.print(&l);
//tui::clear(&state);
time::sleep(1 * time::SECOND);
- let st = txt.widget.style as *widget::style;
- st.colorfg = widget::color::GREENFG;
+ let st = txt.style;
+ st.normal = widget::color::GREENFG;
text::settext(&txt, "bye world");
l.layout.print(&l);
//tui::clear(&state);
time::sleep(1 * time::SECOND);
- st.colorfg = widget::color::BROWNFG;
+ st.normal = widget::color::BROWNFG;
l.layout.print(&l);
//tui::clear(&state);
time::sleep(1 * time::SECOND);
- st.colorfg = widget::color::BLUEFG;
+ st.normal = widget::color::BLUEFG;
l.layout.print(&l);
//tui::clear(&state);
time::sleep(1 * time::SECOND);
- st.colorfg = widget::color::MAGENTAFG;
+ st.normal = widget::color::MAGENTAFG;
l.layout.print(&l);
//tui::clear(&state);
time::sleep(1 * time::SECOND);
- st.colorfg = widget::color::CYANFG;
+ st.normal = widget::color::CYANFG;
l.layout.print(&l);
//tui::clear(&state);
time::sleep(1 * time::SECOND);
- st.colorfg = widget::color::WHITEFG;
+ st.normal = widget::color::WHITEFG;
l.layout.print(&l);
//tui::clear(&state);
time::sleep(1 * time::SECOND);
- st.colorfg = widget::color::DEFAULTFG;
+ st.normal = widget::color::DEFAULTFG;
l.layout.print(&l);
};