aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Hurst <ark@mansus.space>2022-12-16 11:12:47 +0100
committerJulian Hurst <ark@mansus.space>2022-12-16 11:12:47 +0100
commitb9cf4251f8dcd843bba3a984ac87950fc78eb7f3 (patch)
tree99fbedda7158211b496c0b54313e55837b523126
parent1edfb56af19905fb30961ee8162afe8e1719b400 (diff)
downloadilhare-b9cf4251f8dcd843bba3a984ac87950fc78eb7f3.tar.gz
Add support for nul terminated output
-rw-r--r--handlers.ha22
-rw-r--r--main.ha17
2 files changed, 33 insertions, 6 deletions
diff --git a/handlers.ha b/handlers.ha
index dda5c51..c4f28db 100644
--- a/handlers.ha
+++ b/handlers.ha
@@ -47,14 +47,19 @@ fn runehandler(l: *widget::widget, r: libtui::key) bool = {
// to print properly suspend the ui, print, then resume
libtui::suspend(&l.widget.ui);
//fmt::println(l.items[l.cursor])!;
+ const termchar = if (nulterm) {
+ yield "\0";
+ } else {
+ yield "\n";
+ };
match (list::selected(*l)) {
case let s: str =>
- fmt::println(s)!;
+ fmt::printf("{}{}", s, termchar)!;
case let s: []str =>
defer free(s);
- const out = strings::join("\n", s...);
+ const out = strings::join(termchar, s...);
defer free(out);
- fmt::println(out)!;
+ fmt::printf("{}{}", out, termchar)!;
};
libtui::resume(&l.widget.ui);
return true;
@@ -222,14 +227,19 @@ fn runehandler(l: *widget::widget, r: libtui::key) bool = {
// to print properly suspend the ui, print, then resume
libtui::suspend(&l.widget.ui);
//fmt::println(l.items[l.cursor])!;
+ const termchar = if (nulterm) {
+ yield "\0";
+ } else {
+ yield "\n";
+ };
match (list::selected(*l)) {
case let s: str =>
- fmt::println(s)!;
+ fmt::printf("{}{}", s, termchar)!;
case let s: []str =>
defer free(s);
- const out = strings::join("\n", s...);
+ const out = strings::join(termchar, s...);
defer free(out);
- fmt::println(out)!;
+ fmt::printf("{}{}", out, termchar)!;
};
libtui::resume(&l.widget.ui);
return true;
diff --git a/main.ha b/main.ha
index 40718e6..467f773 100644
--- a/main.ha
+++ b/main.ha
@@ -11,12 +11,15 @@ use unix::tty;
use unix::signal;
use unix::poll;
use errors;
+use getopt;
let u: mainUI = mainUI {...};
let searchterm: str = "";
let searchforward: bool = true;
+let nulterm: bool = false;
+
type mainUI = struct {
list: *list::listwidget,
};
@@ -72,6 +75,20 @@ fn resize(list: *list::listwidget) void = {
};
export fn main() void = {
+ const cmd = getopt::parse(os::args,
+ "interactive list",
+ ('0', "NUL terminated output")
+ );
+ defer getopt::finish(&cmd);
+
+ for (let i = 0z; i < len(cmd.opts); i += 1) {
+ const opt = cmd.opts[i];
+ switch (opt.0) {
+ case '0' =>
+ nulterm = true;
+ };
+ };
+
let in = match (io::drain(os::stdin)) {
case let in: []u8 =>
yield in;