diff options
author | John Ankarström <john@ankarstrom.se> | 2020-11-08 01:59:08 +0100 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2020-11-08 01:59:08 +0100 |
commit | af2265d59a0cbeff953af2d7a3e2765df82ecfb2 (patch) | |
tree | 1343dcc8c7380be02f97d1f057561b2a8bc9a932 /tea.c | |
parent | 8941f5dc629c99b183ec09e79b838dc10c86a0ea (diff) | |
download | tea-af2265d59a0cbeff953af2d7a3e2765df82ecfb2.tar.gz |
fix line breaking bug
Diffstat (limited to 'tea.c')
-rw-r--r-- | tea.c | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -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; } } |