From af2265d59a0cbeff953af2d7a3e2765df82ecfb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 8 Nov 2020 01:59:08 +0100 Subject: fix line breaking bug --- tea.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'tea.c') diff --git a/tea.c b/tea.c index 940c310..db1239d 100644 --- a/tea.c +++ b/tea.c @@ -103,18 +103,16 @@ int left() {} void breakline() { prn("\r\n"); breaks[src_l + 1] = 1; - x = margin + 1; - prn(CSI "%dC", margin - 1); + x = margin; if (y == h) yorig--; else y++; + prn(CSI "%d;%dH", y, margin); } void addc(char c) { char *tmp; int i, *tmp2; - if (c != '\n' && x + 1 > w) breakline(); - else x++; if (src_l + 2 > src_s) { src_s += 50; tmp = realloc(src, (src_s + 1) * sizeof(char)); @@ -131,6 +129,10 @@ void addc(char c) { src[src_l + 1] = '\0'; } +void delc() { + src[src_l--] = '\0'; +} + int main() { bool dot; char c, *line, *p, *tmp; @@ -208,8 +210,8 @@ int main() { y = y - r; /* restore original cursor position (CUP) */ - prn(CSI "%d;%dH", yorig, xorig + margin - 1); - x = margin + 1; + prn(CSI "%d;%dH", yorig, margin); + x = margin; y = yorig; dot = false; @@ -232,14 +234,22 @@ int main() { breakline(); prn(CSI "0m"); break; + case 127: /* backspace */ + if (x == margin || x == 1) break; + prn("\b"); + delc(); + x--; + break; default: if (iscntrl(c)) break; - if (x == margin + 1 && c == '.') { + if (x == margin && c == '.') { prn(CSI "%dD", margin - 1); prn(CSI "2m"); } addc(c); + if (x + 1 > w) breakline(); prn("%c", c); + x++; break; } } -- cgit v1.2.3