9 void winch_handler(int sig);
11 char** read_todo(FILE* file, int* length);
13 WINDOW* create_win(int height, int width, int y, int x);
14 MENU* create_todo_menu(char** todo_list, int todo_length);
19 main(int argc, char** argv)
32 signal(SIGWINCH, winch_handler);
34 // read command line args
35 flag = getopt(argc, argv, "o:n:");
39 // read from task file (might need to check for read and write permissions)
40 board_file = fopen(optarg, "r");
42 printf("%s does not exist\n", optarg);
46 todos = read_todo(board_file, &todo_length);
53 // make sure file does not exist
54 // however, it maybe be possible that an different error has occured (besides the file not existing)
55 if (access(optarg, F_OK) == 0) {
56 printf("%s already exists\n", optarg);
60 board_file = fopen(optarg, "w");
61 // write init stuff here
63 printf("Successfully created %s\n", optarg);
72 printf("Help string\n");
76 /* for (int i = 0; i < todo_length; i++) { */
77 /* printf("%p\n", todos[i]); */
78 /* printf(todos[i]); */
89 getmaxyx(stdscr, height, width);
92 /* todo_win = create_win(20, 40, 5, 5); */
93 char* test_todo[] = {"1lmao", "2pee", "3poo", "4feces"};
94 /* todo_menu = create_todo_menu(test_todo, 4); */
95 todo_menu = create_todo_menu(todos, todo_length);
98 while ((ch = getch()) != 'q') {
102 menu_driver(todo_menu, REQ_DOWN_ITEM);
105 menu_driver(todo_menu, REQ_UP_ITEM);
107 case 'G': // try to implement gg too
108 menu_driver(todo_menu, REQ_LAST_ITEM);
117 free(todos); // prob need to free each string in list too
123 winch_handler(int sig)
130 read_todo(FILE* file, int* length)
131 { // apparently getline isn't rly that portable, so consider other options
143 while ((nread = getline(&lineptr, &len, file)) != -1) {
145 out_arr = realloc(out_arr, (sizeof(char*))*out_len); // bad to keep resizing?
147 lineptr[strcspn(lineptr, "\n")] = 0; // remove newline
149 out_arr[out_len-1] = lineptr;
159 create_win(int height, int width, int y, int x)
161 WINDOW* new_win = newwin(height, width, y, x);
167 create_todo_menu(char** todo_list, int todo_length)
173 item_list = malloc((todo_length+1)*sizeof(ITEM*));
174 for (int i = 0; i < todo_length; i++) {
175 printf(todo_list[i]);
176 item_list[i] = new_item(todo_list[i], "");
178 item_list[todo_length] = NULL; // last item needs to be a null pointer for some reason?
180 todo_menu = new_menu(item_list);