add csv export

This commit is contained in:
2025-12-22 04:03:26 +01:00
parent 6862af407e
commit e97e106001
3 changed files with 34 additions and 1 deletions

15
main.c
View File

@@ -17,7 +17,7 @@
#define COMPLETED_PAIR 3
#include "3rd-party/stb-ds.h"
#define KEY_BINDINGS " [a]dd [v]view [m]ark [d]elete [w]rite [l]oad [q]uit"
#define KEY_BINDINGS " [a]dd [v]view [m]ark [d]elete [e]xport csv [w]rite [l]oad [q]uit"
bool dirty = false;
char SAVE_FILE[MAX_PATH_LENGTH] = "";
@@ -32,6 +32,7 @@ enum Command {
WRITE_TO_FILE = 'w',
LOAD_FROM_FILE = 'l',
EXPORT_AS_CSV = 'e',
UP = 'k',
DOWN = 'j',
@@ -346,6 +347,14 @@ void load_from_file_handler(void) {
dirty = false;
}
void export_as_csv_handler(void) {
// create the csv file path
char csv_file_path[MAX_PATH_LENGTH + 5]; // +5 for .csv extension
snprintf(csv_file_path, sizeof(csv_file_path), "%s.csv", SAVE_FILE);
todo_export_as_csv(todos, arrlen(todos), csv_file_path);
}
int main(int argc, char **argv) {
int terminal_width = 0;
int terminal_height = 0;
@@ -390,6 +399,10 @@ int main(int argc, char **argv) {
write_to_file_handler();
alert("Saved!", terminal_width, terminal_height);
break;
case EXPORT_AS_CSV:
export_as_csv_handler();
alert("Exported as CSV!", terminal_width, terminal_height);
break;
case ADD:
add_command_handler(terminal_width, terminal_height);
break;