aboutsummaryrefslogtreecommitdiff
path: root/tea.c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2020-11-08 00:46:57 +0100
committerJohn Ankarström <john@ankarstrom.se>2020-11-08 00:46:57 +0100
commit0b53bf08b02736ca4facdc13099ae360bbe4a541 (patch)
tree8ed9d82de38c80a6be9fa3ec88e36da32c131522 /tea.c
parent9c52b38325662d66bc87b639d3043141c9305372 (diff)
downloadtea-0b53bf08b02736ca4facdc13099ae360bbe4a541.tar.gz
keep track of line breaks in variable
Diffstat (limited to 'tea.c')
-rw-r--r--tea.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/tea.c b/tea.c
index d580493..5839ef9 100644
--- a/tea.c
+++ b/tea.c
@@ -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");