summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorWormHeamer2025-12-28 16:21:06 -0500
committerWormHeamer2025-12-28 16:21:06 -0500
commitc62fdd968a95958a2cba3082524e86e5a313ddaa (patch)
tree10be7b4cd9a1a735a387bc7af7b3550345bf6533 /main.c
parent6249b0c56d8ae29ae9c533d9fe0d5ae30ef72819 (diff)
count for motions
Diffstat (limited to 'main.c')
-rw-r--r--main.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/main.c b/main.c
index bc00618..374406d 100644
--- a/main.c
+++ b/main.c
@@ -19,6 +19,7 @@ Arena scratch = { 0 };
Txt txt = { 0 };
u32 cur = 0;
int mode = 0;
+u32 count = 0;
int is_space(u32 c) {
return c <= 0x20 && c != 0;
@@ -205,6 +206,7 @@ void draw(void *ctx) {
ASSERT(start.i <= txt.ptbl.v[start.p].n);
if (!cur_found) vui_curs_pos(x, y);
u32 c = txt_chr(&txt, l);
+ vui_printf(-1, -4, "%u", count);
vui_aprintf(-1, -3, mode ? FG_BCYAN : FG_CYAN, "%s", mode ? "INSERT" : "NORMAL");
vui_printf(-1, -1, "%u - %u.%u - %02x (%c)", cur, l.p, l.i, c, (c < 0x20 || c > 0x7e) ? ' ' : c);
u32 used = scratch.beg - scratch.start, max = scratch.end - scratch.start;
@@ -212,6 +214,8 @@ void draw(void *ctx) {
}
int motion(u32 c) {
+ u32 last_cur = cur;
+loop:
switch (c) {
case KEY_LEFT:
case 'h':
@@ -297,6 +301,11 @@ int motion(u32 c) {
default:
return 0;
}
+ if (count > 1 && last_cur != cur) {
+ count--;
+ goto loop;
+ }
+ count = 0;
return 1;
}
@@ -319,7 +328,8 @@ int main(int argc, const char **argv) {
switch (c) {
case 'q':
goto brk;
- case 0x13 /* ^S */:
+ case 'z':
+ case 0x13 /* ^S */:
txt_save(&txt, path);
//txt_load(&txt, "test.txt");
break;
@@ -355,8 +365,18 @@ int main(int argc, const char **argv) {
del_between(&txt, before, cur);
if (before < cur) cur = before;
}
- break;
- }
+ } break;
+ case 'D': {
+ u32 end = txt_ofs(&txt, end_of_line(&txt, txt_at(&txt, cur)));
+ del_between(&txt, cur, end);
+ } break;
+ case 'S': {
+ TxtLoc l = start_of_line(&txt, txt_at(&txt, cur));
+ u32 end = txt_ofs(&txt, end_of_line(&txt, l));
+ del_between(&txt, txt_ofs(&txt, l), end);
+ cur = txt_ofs(&txt, l);
+ mode = 1;
+ } break;
case 'c': {
u32 before = cur;
if (motion(vui_key())) {
@@ -373,8 +393,18 @@ int main(int argc, const char **argv) {
txt_delete_c(&txt, txt_ofs(&txt, txt_next(&txt, txt_at(&txt, cur))));
mode = 1;
break;
+ case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+add_to_count:
+ count = (count % 100000000) * 10 + c - '0';
+ break;
+ case '0':
+ if (count) goto add_to_count;
+ /* fallthrough */
default:
- if (!motion(c)) {} /* TODO: bell/flash? */
+ if (!motion(c)) {
+ /* TODO: bell/flash? */
+ }
break;
}
break;
@@ -412,6 +442,7 @@ ins_newline:;
}
break;
}
+ if (mode == 1) count = 0;
}
brk:
vui_fini();