Compare commits

..

3 Commits

Author SHA1 Message Date
e97e106001 add csv export 2025-12-22 04:03:26 +01:00
6862af407e add uninstall task 2025-09-18 01:59:12 +02:00
6a8bb3f5d4 use stdbool for true/false 2025-09-18 01:59:04 +02:00
4 changed files with 38 additions and 4 deletions

View File

@@ -12,7 +12,6 @@ main.o:
clean:
rm -f *.o
rm -f todd
rm /usr/local/bin/todd || true
todd: todo.o main.o
$(CC) $(CFLAGS) todo.o main.o -lncurses -o todd
@@ -21,3 +20,6 @@ all: todd
install: todd
cp todd /usr/local/bin/todd
uninstall:
rm /usr/local/bin/todd || true

View File

@@ -1,6 +1,7 @@
#include "todo.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
// Memory management
@@ -54,3 +55,20 @@ char *todo_item_serialize(TodoItem *item, int *buffer_size_out) {
return buffer;
}
// Exports
void todo_export_as_csv(TodoItem *items, int item_count, const char *filename) {
FILE *file = fopen(filename, "w");
if (file == NULL) {
perror("Failed to open file for writing");
return;
}
// Write CSV header
fprintf(file, "Title,Completed\n");
for (int i = 0; i < item_count; i++) {
fprintf(file, "\"%s\",%s\n", items[i].title,
items[i].completed ? "Yes" : "No");
}
fclose(file);
}

View File

@@ -2,8 +2,6 @@
#define TODO_H
#define TODO_MAX_TITLE_LENGTH 255
#define true 1
#define false 0
typedef unsigned char bool_t;
typedef struct {
@@ -22,4 +20,7 @@ void todo_print_item(TodoItem *item);
// Serialization
char *todo_item_serialize(TodoItem *item, int *buffer_size_out);
// Exports
void todo_export_as_csv(TodoItem *items, int item_count, const char *filename);
#endif

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;