hachem.wtf
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-29 16:46:58 +0200
committerhachem <im@hachem.wtf>2026-09-29 16:46:58 +0200
commita90c210784ec9e3b4115b9f46c1fc3664340f0ae (patch)
tree6960a61baee75385c9fb7d70427b6c8ddab7eb07
parente715956c729e30f34ab03ce9f2baee2d50cdbb44 (diff)
feat: add more keybindings
-rw-r--r--todo.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/todo.c b/todo.c
index 7894a3f..12f5d93 100644
--- a/todo.c
+++ b/todo.c
@@ -164,6 +164,11 @@ static void delete_item(struct List* list, int index)
list->count--;
}
+static int is_separator(const struct Item* item)
+{
+ return item->text[0] == '\0';
+}
+
static struct termios saved_termios;
static void restore_terminal(void)
@@ -366,6 +371,92 @@ static int normal_key(struct List* list, const char* path, int* cursor, enum Mod
break;
+ case 'g':
+ {
+ char next;
+
+ if (read(STDIN_FILENO, &next, 1) == 1 && next == 'g')
+ *cursor = 0;
+
+ break;
+ }
+
+ case 'G':
+ *cursor = list->count - 1;
+ break;
+
+ case '}':
+ {
+ int next = *cursor + 1;
+
+ while (next < list->count && !is_separator(&list->items[next]))
+ next++;
+
+ *cursor = next < list->count ? next : list->count - 1;
+ break;
+ }
+
+ case '{':
+ {
+ int previous = *cursor - 1;
+
+ while (previous >= 0 && !is_separator(&list->items[previous]))
+ previous--;
+
+ *cursor = previous >= 0 ? previous : 0;
+ break;
+ }
+
+ case 'd':
+ {
+ char next;
+
+ if (read(STDIN_FILENO, &next, 1) == 1 && next == 'd')
+ {
+ delete_item(list, *cursor);
+ save(list, path);
+ }
+
+ break;
+ }
+
+ case 'J':
+ if (*cursor >= 0 && *cursor + 1 < list->count)
+ {
+ struct Item moved = list->items[*cursor];
+ list->items[*cursor] = list->items[*cursor + 1];
+ list->items[*cursor + 1] = moved;
+ (*cursor)++;
+ save(list, path);
+ }
+
+ break;
+
+ case 'K':
+ if (*cursor > 0 && *cursor < list->count)
+ {
+ struct Item moved = list->items[*cursor];
+ list->items[*cursor] = list->items[*cursor - 1];
+ list->items[*cursor - 1] = moved;
+ (*cursor)--;
+ save(list, path);
+ }
+
+ break;
+
+ case 'D':
+ {
+ int kept = 0;
+
+ for (int i = 0; i < list->count; i++)
+ if (list->items[i].state != STATE_DONE)
+ list->items[kept++] = list->items[i];
+
+ list->count = kept;
+ save(list, path);
+ break;
+ }
+
default:
break;
}