aboutsummaryrefslogtreecommitdiff
path: root/tea.c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2020-11-08 01:59:08 +0100
committerJohn Ankarström <john@ankarstrom.se>2020-11-08 01:59:08 +0100
commitaf2265d59a0cbeff953af2d7a3e2765df82ecfb2 (patch)
tree1343dcc8c7380be02f97d1f057561b2a8bc9a932 /tea.c
parent8941f5dc629c99b183ec09e79b838dc10c86a0ea (diff)
downloadtea-af2265d59a0cbeff953af2d7a3e2765df82ecfb2.tar.gz
fix line breaking bug
Diffstat (limited to 'tea.c')
-rw-r--r--tea.c24
1 files changed, 17 insertions, 7 deletions
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;
}
}