summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/scrolllist.ha8
-rw-r--r--tui/tui.ha12
-rw-r--r--tui/widget/list/scrolllist.ha2
-rw-r--r--tui/widget/widget.ha32
4 files changed, 43 insertions, 11 deletions
diff --git a/cmd/scrolllist.ha b/cmd/scrolllist.ha
index 6b631fc..428b7d8 100644
--- a/cmd/scrolllist.ha
+++ b/cmd/scrolllist.ha
@@ -15,8 +15,8 @@ export fn main() void = {
columns = 50u16,
},
&widget::style {
- border = true,
- colorfg = widget::color::REDFG,
+ border = false,
+ colorfg = widget::color::BLUEFG,
colorbg = widget::color::REDBG,
},"hello", "world", "bye", "world")!;
@@ -44,6 +44,10 @@ export fn main() void = {
if (r == 'G') {
list::bottom(&li);
};
+ if (r == 'l') {
+ fmt::println(li.items[li.cursor])!;
+ break;
+ };
if (r == 'q') {
break;
};
diff --git a/tui/tui.ha b/tui/tui.ha
index f6014a6..90a9286 100644
--- a/tui/tui.ha
+++ b/tui/tui.ha
@@ -20,7 +20,8 @@ export type key = (skey | rune);
export fn init() (tui | tty::error | errors::error) = {
const f = tty::open()?;
const tq = tty::termios_query(f)?;
- tty::noncanonical(&tq)?;
+ tty::makeraw(&tq)?;
+ //tty::noncanonical(&tq)?;
doclear(f);
return tui {
out = f,
@@ -53,3 +54,12 @@ export fn finish(state: *tui) void = {
tty::termios_restore(&state.tq);
io::close(state.out)!;
};
+
+export fn unraw(state: *tui) void = {
+ tty::termios_restore(&state.tq);
+};
+
+export fn raw(state: *tui) (void | errors::error) = {
+ const tq = tty::termios_query(state.out)?;
+ tty::makeraw(&tq)?;
+};
diff --git a/tui/widget/list/scrolllist.ha b/tui/widget/list/scrolllist.ha
index 5ffa70f..959b9c0 100644
--- a/tui/widget/list/scrolllist.ha
+++ b/tui/widget/list/scrolllist.ha
@@ -71,7 +71,7 @@ fn printscrolllist(widget: *widget::widget) void = {
memio::concat(&st, "\x1B[27m")!;
};
if (i != list.frame.end - 1) {
- memio::concat(&st, "\n")!;
+ memio::concat(&st, widget::NEWLINE)!;
};
};
list.widget.buf = memio::string(&st)!;
diff --git a/tui/widget/widget.ha b/tui/widget/widget.ha
index 426d844..6697935 100644
--- a/tui/widget/widget.ha
+++ b/tui/widget/widget.ha
@@ -71,6 +71,8 @@ export def DEFAULT_STYLE: style = style {
colorbg = color::DEFAULTBG,
};
+export def NEWLINE: str = "\r\n";
+
def gotoroot: str = "\x1B[1;1H";
def UNDERLINE: str = "\x1B[4m";
@@ -126,6 +128,9 @@ fn clearrow(row: uint) str = fmt::asprintf("\x1B[{}d{}", row, CLEARROW);
export fn print(w: *widget) void = {
+ //tui::unraw(w.state);
+ //defer tui::raw(w.state)!;
+
const clear = match (w.damage) {
case all =>
yield strings::dup(CLEAR);
@@ -187,10 +192,12 @@ fn applystyles(st: (*style | void), s: str) str = {
// Truncates the text of the widget to the widget's size (rows and columns) and
// returns the resulting string.
fn truncate_to_size(w: *widget) str = {
- let spl = strings::split(w.buf, "\n");
+ let spl = splitstr(w.buf, NEWLINE);
+ defer free(spl);
const st = memio::dynamic();
defer io::close(&st)!;
- for (let i = 0z; i < minrows(w.state.out, len(spl): u16, w.sz)!; i += 1) {
+ const nbrows = minrows(w.state.out, len(spl): u16, w.sz)!;
+ for (let i = 0z; i < nbrows; i += 1) {
const line = spl[i];
let item = match (w.sz) {
case let sz: tty::ttysize =>
@@ -199,11 +206,10 @@ fn truncate_to_size(w: *widget) str = {
case void =>
yield strings::dup(line);
};
+ //fmt::println(item)!;
defer free(item);
memio::concat(&st, item)!;
- if (i < len(spl) - 1) {
- memio::concat(&st, "\n")!;
- };
+ memio::concat(&st, NEWLINE)!;
};
return strings::dup(memio::string(&st)!);
};
@@ -212,7 +218,9 @@ fn truncate_to_size(w: *widget) str = {
fn border(s: str) str = {
let st = memio::dynamic();
defer io::close(&st)!;
- let spl = strings::split(s, "\n");
+ //let spl = strings::split(s, NEWLINE);
+ let spl = splitstr(s, NEWLINE);
+ defer free(spl);
for (let i = 0z; i < len(spl); i += 1) {
const s = strings::concat("|", spl[i], "|");
//const s = strings::dup(spl[i]);
@@ -227,7 +235,7 @@ fn border(s: str) str = {
memio::concat(&st, s)!;
if (i < len(spl) - 1) {
- memio::concat(&st, "\n")!;
+ memio::concat(&st, NEWLINE)!;
};
};
return strings::dup(memio::string(&st)!);
@@ -259,3 +267,13 @@ export fn cleardamage(w: *widget) void = {
delete(dam[i]);
};
};
+
+fn splitstr(s: str, delim: str) []str = {
+ let spl = strings::split(s, delim);
+ for (let i = 0z; i < len(spl); i += 1) {
+ if (spl[i] == "") {
+ delete(spl[i]);
+ };
+ };
+ return spl;
+};