sim

the sim text editor
git clone git://ssnf.xyz/sim
Log | Files | Refs | README

commit 522e2a66457a2343fe7d04d0df9f164a80dd2d62
parent 0c56b3f56aa0efb732673ef492eb476053d82239
Author: ssnf <ssnf@ssnf.xyz>
Date:   Thu, 11 Aug 2022 13:33:08 +0000

improved tab handling. Makefile BSD support

Diffstat:
MMakefile | 3++-
Mposix.c | 5++++-
Msim.c | 8++++----
Msim.h | 1+
4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,6 +1,7 @@ CC = c89 CFLAGS = -Os -Wall -Wpedantic -Wno-deprecated-declarations -Wno-return-type -SRC = ${wildcard *.c} +#CFLAGS = -O0 -g -Wall -Wpedantic +SRC = sim.c posix.c OBJ = ${SRC:.c=.o} all: sim diff --git a/posix.c b/posix.c @@ -18,7 +18,7 @@ win_end() } void -win_init() +win_init(Window* w) { struct termios raw_state; @@ -27,6 +27,9 @@ win_init() raw_state.c_lflag &= ~(ECHO|ICANON|ISIG); tcsetattr(0, TCSAFLUSH, &raw_state); setbuf(stdout, NULL); + printf(CSI "H\t" CSI "6n"); + scanf("\x1b[%*d;%huR", &w->t); + --w->t; } void diff --git a/sim.c b/sim.c @@ -190,7 +190,7 @@ blind_reader(Frame* fr, String* s, Posn p0) for (wx = 0; wx < w.wx && p1 < s->n;) { switch (s->s[p1]) { case '\t': - wx += 4 - (wx % 4); + wx += w.t - (wx % w.t); break; case '\n': goto endloop; @@ -500,7 +500,7 @@ init() { uint i; - win_init(); + win_init(&w); for (i = 0; i < FILECOUNT; ++i) { file_init(&file[i]); fr_init(&frame[i]); @@ -689,8 +689,8 @@ fr_update() printf(CSI "%uH", w.wy); printf(STATUS); for (p0 = fr->a[fr->dot].p0, p1 = 1; p0 < f->dot.p1; ++p0) { - if (f->s->s[p0] == '\t' && p1 % 4) - p1 += 5 - (p1 % 4); + if (f->s->s[p0] == '\t' && p1 % w.t) + p1 += (w.t + 1) - (p1 % w.t); else ++p1; } diff --git a/sim.h b/sim.h @@ -9,6 +9,7 @@ typedef unsigned short ushort; typedef struct { ushort wx, wy; + ushort t; } Window; void die(char* fmt, ...);