sim

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

commit 551df9960b8d98ef506f000e5133c90380907813
parent 06d88ffe6a4dab1d05e86524dcf48c78e1fbb5b7
Author: ssnf <ssnf@ssnf.xyz>
Date:   Tue, 28 Jan 2025 16:09:48 +0000

add visual cursor position to status

Diffstat:
Msim.c | 32+++++++++++++++++++++++---------
1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/sim.c b/sim.c @@ -1,3 +1,4 @@ +#include <assert.h> #include <stdio.h> #include <stdarg.h> #include <stdlib.h> @@ -88,7 +89,9 @@ static void buf_add( uint c, uint arg, uint count, Posn p0 ); static void change(int arg); +static uint charsiz(char c, ulong wx); static void count(int arg); +static uint curpos(void); static void delete(int arg); static void dot(int arg); static void redo(int arg); @@ -193,15 +196,9 @@ blind_reader(Frame* fr, Posn p0) a.p0 = a.p1 = p0; do { for (wx = 0; wx < w.wx && a.p1 < f->s->n;) { - switch (f->s->s[a.p1]) { - case '\t': - wx += w.t - (wx % w.t); + if (f->s->s[a.p1] == '\n') break; - case '\n': - goto endloop; - default: - ++wx; - } + wx += charsiz(f->s->s[a.p1], wx); if (wx < w.wx) ++a.p1; if (wx >= w.wx) { @@ -211,7 +208,6 @@ blind_reader(Frame* fr, Posn p0) ++a.p1; } } - endloop: fr_add(fr, a); a.p0 = ++a.p1; } while (a.p1 <= f->s->n && f->s->s[a.p1 - 1] != '\n'); @@ -292,6 +288,13 @@ change(int arg) fr_update(); } +static uint +charsiz(char c, ulong wx) +{ + assert(c != '\n'); + return (c == '\t') ? w.t - (wx % w.t) : 1; +} + static void count(int arg) { @@ -303,6 +306,17 @@ count(int arg) counter += arg; } +static uint +curpos(void) +{ + ulong i, wx; + + wx = 0; + for (i = fr->a[fr->cur].p0; i < f->dot.p1; ++i) + wx += charsiz(f->s->s[i], wx); + return wx; +} + static void delete(int arg) {