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(WINDOW* win, char** todo_list, int todo_length);
16 void free_todo(char** todo_list, int todo_length);
21 main(int argc, char** argv)
34 signal(SIGWINCH, winch_handler);
36 // read command line args
37 flag = getopt(argc, argv, "o:n:");
41 // read from task file (might need to check for read and write permissions)
42 board_file = fopen(optarg, "r");
44 printf("%s does not exist\n", optarg);
48 todos = read_todo(board_file, &todo_length);
55 // make sure file does not exist
56 // however, it maybe be possible that an different error has occured (besides the file not existing)
57 if (access(optarg, F_OK) == 0) {
58 printf("%s already exists\n", optarg);
62 board_file = fopen(optarg, "w");
63 // write init stuff here
65 printf("Successfully created %s\n", optarg);
74 printf("Help string\n");
78 /* for (int i = 0; i < todo_length; i++) { */
79 /* printf("%p\n", todos[i]); */
80 /* printf(todos[i]); */
91 getmaxyx(stdscr, height, width);
93 todo_win = create_win(20, 40, 5, 5);
95 todo_menu = create_todo_menu(todo_win, todos, todo_length);
99 while ((ch = getch()) != 'q') {
103 menu_driver(todo_menu, REQ_DOWN_ITEM);
106 menu_driver(todo_menu, REQ_UP_ITEM);
108 case 'G': // try to implement gg too
109 menu_driver(todo_menu, REQ_LAST_ITEM);
120 free_todo(todos, todo_length);
126 winch_handler(int sig)
133 read_todo(FILE* file, int* length)
134 { // apparently getline isn't rly that portable, so consider other options
146 while ((nread = getline(&lineptr, &len, file)) != -1) {
148 out_arr = realloc(out_arr, (sizeof(char*))*out_len); // bad to keep resizing?
150 lineptr[strcspn(lineptr, "\n")] = 0; // remove newline
151 out_arr[out_len-1] = lineptr;
161 create_win(int height, int width, int y, int x)
163 WINDOW* new_win = newwin(height, width, y, x);
169 create_todo_menu(WINDOW* win, char** todo_list, int todo_length)
176 item_list = malloc((todo_length+1)*sizeof(ITEM*));
177 for (int i = 0; i < todo_length; i++) {
178 item_list[i] = new_item(todo_list[i], "");
180 item_list[todo_length] = NULL; // last item needs to be a null pointer for some reason?
182 todo_menu = new_menu(item_list);
184 getmaxyx(stdscr, wheight, wwidth);
185 set_menu_win(todo_menu, win);
186 set_menu_sub(todo_menu, derwin(win, wheight, wwidth, 0, 0));
188 box(win, 0, 0); //temp
194 free_todo(char** todo_list, int todo_length)
196 // probably check if list is too short or too long
197 for (int i = 0; i < todo_length; i++) {