From b9cf4251f8dcd843bba3a984ac87950fc78eb7f3 Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Fri, 16 Dec 2022 11:12:47 +0100 Subject: Add support for nul terminated output --- handlers.ha | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'handlers.ha') 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; -- cgit v1.2.3