Compare commits
60 Commits
14cc20f6c3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
e97e106001
|
|||
|
6862af407e
|
|||
|
6a8bb3f5d4
|
|||
|
557a4affa6
|
|||
|
3b99b87c22
|
|||
|
f40b4001c7
|
|||
|
143feaac83
|
|||
|
972bd28b6f
|
|||
|
8421e3ee01
|
|||
|
bda1c18a52
|
|||
|
37cd828c21
|
|||
|
c746cad281
|
|||
|
0abfa4af0f
|
|||
|
ceede3001a
|
|||
|
29eeef56b8
|
|||
|
e6203f70a9
|
|||
|
d8a3fe0d7a
|
|||
|
7c060419f4
|
|||
|
c3b1797bd9
|
|||
|
e9d8988ef2
|
|||
|
476428b7de
|
|||
|
58eda93cbb
|
|||
|
21a6c077fd
|
|||
|
2e0f7501d7
|
|||
|
3809b5b96a
|
|||
|
79a313a03e
|
|||
|
c3dee6a8ef
|
|||
|
20d6e4a8b1
|
|||
|
65d591a455
|
|||
|
65b5e45cba
|
|||
|
e3f807bd7f
|
|||
|
9bd8817797
|
|||
|
e8e0babfaa
|
|||
|
3159a34c9a
|
|||
|
1267fc54bb
|
|||
|
613071c8f5
|
|||
|
0cf3febd2b
|
|||
|
76396a3022
|
|||
|
e900ffc0d7
|
|||
|
dd148396f1
|
|||
|
71939366c7
|
|||
|
a5734d1323
|
|||
|
14f177e3f9
|
|||
|
881d13b546
|
|||
|
a852107b62
|
|||
|
3acbe3eb33
|
|||
|
672998b17b
|
|||
|
01e6a6064d
|
|||
|
d0ec4b758b
|
|||
|
b27047e7d1
|
|||
|
71e935c8ad
|
|||
|
44a4374fd1
|
|||
|
76c620c142
|
|||
|
b49b728a4c
|
|||
|
bb0c5c173a
|
|||
|
b476873ede
|
|||
|
78a190b28f
|
|||
|
21dd4c988e
|
|||
|
e875f6fab3
|
|||
|
06a0b782cf
|
74
.github/workflows/build.yml
vendored
74
.github/workflows/build.yml
vendored
@@ -1,74 +0,0 @@
|
|||||||
name: Build Todd
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ "main" ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ "main" ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-linux:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: awalsh128/cache-apt-pkgs-action@latest
|
|
||||||
with:
|
|
||||||
packages: libncurses5-dev
|
|
||||||
version: "1.0"
|
|
||||||
- name: make
|
|
||||||
run: make
|
|
||||||
- name: copy to build folder
|
|
||||||
run: |
|
|
||||||
mkdir -p build
|
|
||||||
cp ./todd build/
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: todd-linux
|
|
||||||
path: build
|
|
||||||
|
|
||||||
build-mac:
|
|
||||||
|
|
||||||
runs-on: macos-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: make
|
|
||||||
run: make
|
|
||||||
- name: copy to build folder
|
|
||||||
run: |
|
|
||||||
mkdir -p build
|
|
||||||
cp ./todd build/
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: todd-mac
|
|
||||||
path: build
|
|
||||||
|
|
||||||
build-windows:
|
|
||||||
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: msys2 {0}
|
|
||||||
|
|
||||||
runs-on: windows-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: msys2/setup-msys2@v2
|
|
||||||
with:
|
|
||||||
msystem: mingw64
|
|
||||||
update: true
|
|
||||||
install: >-
|
|
||||||
gcc
|
|
||||||
make
|
|
||||||
ncurses-devel
|
|
||||||
- name: make
|
|
||||||
run: make
|
|
||||||
- name: copy to build folder
|
|
||||||
run: |
|
|
||||||
mkdir -p build
|
|
||||||
cp ./todd.exe build/
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: todd-windows
|
|
||||||
path: build
|
|
||||||
6
Makefile
6
Makefile
@@ -1,7 +1,7 @@
|
|||||||
.DEFAULT_GOAL := all
|
.DEFAULT_GOAL := all
|
||||||
|
|
||||||
CC=gcc
|
CC=gcc
|
||||||
CFLAGS=-Wall -Wextra -Werror -pedantic -std=c99 -g
|
CFLAGS=-Wall -Wextra -Werror -pedantic -std=c99 -O3
|
||||||
|
|
||||||
todo.o:
|
todo.o:
|
||||||
$(CC) $(CFLAGS) -c engine/todo.c -o todo.o
|
$(CC) $(CFLAGS) -c engine/todo.c -o todo.o
|
||||||
@@ -12,7 +12,6 @@ main.o:
|
|||||||
clean:
|
clean:
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
rm -f todd
|
rm -f todd
|
||||||
rm /usr/local/bin/todd || true
|
|
||||||
|
|
||||||
todd: todo.o main.o
|
todd: todo.o main.o
|
||||||
$(CC) $(CFLAGS) todo.o main.o -lncurses -o todd
|
$(CC) $(CFLAGS) todo.o main.o -lncurses -o todd
|
||||||
@@ -21,3 +20,6 @@ all: todd
|
|||||||
|
|
||||||
install: todd
|
install: todd
|
||||||
cp todd /usr/local/bin/todd
|
cp todd /usr/local/bin/todd
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
rm /usr/local/bin/todd || true
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "todo.h"
|
#include "todo.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// Memory management
|
// Memory management
|
||||||
@@ -54,3 +55,20 @@ char *todo_item_serialize(TodoItem *item, int *buffer_size_out) {
|
|||||||
|
|
||||||
return buffer;
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
#define TODO_H
|
#define TODO_H
|
||||||
#define TODO_MAX_TITLE_LENGTH 255
|
#define TODO_MAX_TITLE_LENGTH 255
|
||||||
|
|
||||||
#define true 1
|
|
||||||
#define false 0
|
|
||||||
typedef unsigned char bool_t;
|
typedef unsigned char bool_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -22,4 +20,7 @@ void todo_print_item(TodoItem *item);
|
|||||||
|
|
||||||
// Serialization
|
// Serialization
|
||||||
char *todo_item_serialize(TodoItem *item, int *buffer_size_out);
|
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
|
#endif
|
||||||
|
|||||||
30
main.c
30
main.c
@@ -17,7 +17,7 @@
|
|||||||
#define COMPLETED_PAIR 3
|
#define COMPLETED_PAIR 3
|
||||||
|
|
||||||
#include "3rd-party/stb-ds.h"
|
#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;
|
bool dirty = false;
|
||||||
char SAVE_FILE[MAX_PATH_LENGTH] = "";
|
char SAVE_FILE[MAX_PATH_LENGTH] = "";
|
||||||
@@ -32,6 +32,7 @@ enum Command {
|
|||||||
|
|
||||||
WRITE_TO_FILE = 'w',
|
WRITE_TO_FILE = 'w',
|
||||||
LOAD_FROM_FILE = 'l',
|
LOAD_FROM_FILE = 'l',
|
||||||
|
EXPORT_AS_CSV = 'e',
|
||||||
|
|
||||||
UP = 'k',
|
UP = 'k',
|
||||||
DOWN = 'j',
|
DOWN = 'j',
|
||||||
@@ -235,12 +236,22 @@ void add_command_handler(int width, int height) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void view_command_handler(int width, int height, int index) {
|
void view_command_handler(int width, int height, int index) {
|
||||||
|
// check if the index is out of bounds
|
||||||
|
if (index < 0 || index >= arrlen(todos)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TodoItem item = todos[index];
|
TodoItem item = todos[index];
|
||||||
// create an alert in the middle of the screen
|
// create an alert in the middle of the screen
|
||||||
alert(item.title, width, height);
|
alert(item.title, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mark_command_handler(int index) {
|
void mark_command_handler(int index) {
|
||||||
|
// check if the index is out of bounds
|
||||||
|
if (index < 0 || index >= arrlen(todos)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TodoItem item = todos[index];
|
TodoItem item = todos[index];
|
||||||
|
|
||||||
todo_mark_item(&item, !item.completed);
|
todo_mark_item(&item, !item.completed);
|
||||||
@@ -252,6 +263,11 @@ void mark_command_handler(int index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void remove_command_handler(int index) {
|
void remove_command_handler(int index) {
|
||||||
|
// check if the index is out of bounds
|
||||||
|
if (index < 0 || index >= arrlen(todos)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
arrdel(todos, index);
|
arrdel(todos, index);
|
||||||
|
|
||||||
// set the dirty flag
|
// set the dirty flag
|
||||||
@@ -331,6 +347,14 @@ void load_from_file_handler(void) {
|
|||||||
dirty = false;
|
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 main(int argc, char **argv) {
|
||||||
int terminal_width = 0;
|
int terminal_width = 0;
|
||||||
int terminal_height = 0;
|
int terminal_height = 0;
|
||||||
@@ -375,6 +399,10 @@ int main(int argc, char **argv) {
|
|||||||
write_to_file_handler();
|
write_to_file_handler();
|
||||||
alert("Saved!", terminal_width, terminal_height);
|
alert("Saved!", terminal_width, terminal_height);
|
||||||
break;
|
break;
|
||||||
|
case EXPORT_AS_CSV:
|
||||||
|
export_as_csv_handler();
|
||||||
|
alert("Exported as CSV!", terminal_width, terminal_height);
|
||||||
|
break;
|
||||||
case ADD:
|
case ADD:
|
||||||
add_command_handler(terminal_width, terminal_height);
|
add_command_handler(terminal_width, terminal_height);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user