sim

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

commit d19a4bbb2144da607cb2882e1110a99697844840
parent ed38381d34f25c4cec990f6a50179fc429b7e06e
Author: ssnf <ssnf@ssnf.xyz>
Date:   Sun, 15 Aug 2021 17:44:39 +0000

added more movement commands

Diffstat:
Mconfig.def.h | 6++++++
Msim.c | 53+++++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -4,4 +4,10 @@ Key keys[] = { { 'j', move, Down }, { 'k', move, Up }, { 'l', move, Right }, + { Ctrl + 'u', move, HalfUp }, + { Ctrl + 'd', move, HalfDown }, + { 'G', move, Top }, + { 'g', move, Bottom }, + { '0', move, StartLine }, + { '$', move, EndLine }, }; diff --git a/sim.c b/sim.c @@ -5,8 +5,8 @@ #include "sim.h" -#define MINSIZE 16 -#define MAXEMPTY 256 +#define MINSIZE 16 +#define MAXEMPTY 256 #define FILECOUNT 8 #define LENGTH(a) (sizeof(a)/sizeof(a[0])) @@ -16,7 +16,14 @@ enum { Up, Down, Left, - Right + Right, + HalfUp, + HalfDown, + Top, + Bottom, + StartLine, + EndLine, + Ctrl = -0x60 }; typedef struct { @@ -105,6 +112,7 @@ main(int argc, char* argv[]) break; } } + fr_update(); } } @@ -345,10 +353,9 @@ fr_update() status: printf(CSI "%uH" "%lu 0x%02x", w.wy, f->dot.p1, f->s->s[f->dot.p1]); for (p0 = frame.a[frame.dot].p0, p1 = 1; p0 < f->dot.p1; ++p0) { - if (f->s->s[p0] == '\t') + if (f->s->s[p0] == '\t' && p1 % 4) { p1 += 5 - (p1 % 4); - else - ++p1; + } else ++p1; } printf(CSI "%u;%luH", half, p1); return; @@ -387,6 +394,40 @@ move(int arg) for (;++f->dot.p1, f->dot.p1 + 1 < f->s->n && f->s->s[f->dot.p1 - 1] != '\n';); f->dot.p0 = f->dot.p1; break; + case HalfUp: + if (frame.dot < w.wy/2) + f->dot.p0 = f->dot.p1 = 0; + else + f->dot.p0 = f->dot.p1 = frame.a[frame.dot - w.wy/2].p0; + break; + case HalfDown: + if (!f->s->n) + break; + if (frame.n - frame.dot <= w.wy/2) { + if (frame.a[frame.n - 1].p1 <= f->s->n) + f->dot.p0 = f->dot.p1 = frame.a[frame.n - 1].p0; + else + f->dot.p0 = f->dot.p1 = f->s->n; + } else + f->dot.p0 = f->dot.p1 = frame.a[frame.dot + w.wy/2].p0; + break; + case Top: + f->dot.p0 = f->dot.p1 = 0; + break; + case Bottom: + if (f->s->n) + f->dot.p0 = f->dot.p1 = f->s->n - 1; + break; + case StartLine: + if (f->dot.p1) + for (;f->dot.p1 && f->s->s[f->dot.p1 - 1] != '\n'; --f->dot.p1); + f->dot.p0 = f->dot.p1; + break; + case EndLine: + if (f->dot.p1 + 1 < f->s->n) + for (;f->dot.p1 + 1 < f->s->n && f->s->s[f->dot.p1] != '\n'; ++f->dot.p1); + f->dot.p0 = f->dot.p1; + break; }; }