diff options
Diffstat (limited to 'tui/widget/widget.ha')
| -rw-r--r-- | tui/widget/widget.ha | 32 |
1 files changed, 25 insertions, 7 deletions
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; +}; |
