diff options
author | John Ankarström <john@ankarstrom.se> | 2020-11-08 00:46:57 +0100 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2020-11-08 00:46:57 +0100 |
commit | 0b53bf08b02736ca4facdc13099ae360bbe4a541 (patch) | |
tree | 8ed9d82de38c80a6be9fa3ec88e36da32c131522 /tea.c | |
parent | 9c52b38325662d66bc87b639d3043141c9305372 (diff) | |
download | tea-0b53bf08b02736ca4facdc13099ae360bbe4a541.tar.gz |
keep track of line breaks in variable
Diffstat (limited to 'tea.c')
-rw-r--r-- | tea.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -20,10 +20,14 @@ char **lines; int lines_c; int lines_s; -char *src; +char *src; /* source text */ int src_l; int src_s; +int *breaks; /* position of broken lines in source text */ + /* (1 where a character is displayed on a new line, + 0 otherwise.) */ + int x, y; /* current cursor position */ int w, h; /* terminal width, height */ int margin = 10; @@ -99,8 +103,8 @@ int left() {} void addc(char c) { if (c != '\n' && x + 1 > w) { - prn("\r"); - addc('\n'); + prn("\r\n"); + breaks[src_l + 1] = 1; x = margin + 1; prn(CSI "%dC", margin - 1); if (y == h) yorig--; @@ -126,6 +130,11 @@ int main() { if (src == NULL) err(1, "malloc"); src_l = -1; + breaks = malloc(src_s * sizeof(int)); + if (breaks == NULL) err(1, "malloc"); + for (i = 0; i < src_s; i++) + breaks[i] = 0; + ttyfd = open("/dev/tty", O_RDWR); if (ttyfd == -1) rerr(1, "open"); |