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 on_select(char *item);
18 void free_todo(char** todo_list, int todo_length);
22 #define SELECTED_COLOR 1
23 #define NON_SELECTED_COLOR 2
26 main(int argc, char** argv)
39 signal(SIGWINCH, winch_handler);
41 // read command line args
42 flag = getopt(argc, argv, "o:n:");
46 // read from task file (might need to check for read and write permissions)
47 board_file = fopen(optarg, "r");
49 printf("%s does not exist\n", optarg);
53 todos = read_todo(board_file, &todo_length);
60 // make sure file does not exist
61 // however, it maybe be possible that an different error has occured (besides the file not existing)
62 if (access(optarg, F_OK) == 0) {
63 printf("%s already exists\n", optarg);
67 board_file = fopen(optarg, "w");
68 // write init stuff here
70 printf("Successfully created %s\n", optarg);
79 printf("Help string\n");
92 init_pair(SELECTED_COLOR, selected_color, COLOR_BLACK);
93 init_pair(NON_SELECTED_COLOR, non_selected_color, COLOR_BLACK);
95 getmaxyx(stdscr, height, width);
97 todo_win = create_win(20, 40, 5, 5);
98 todo_menu = create_todo_menu(todo_win, todos, todo_length);
103 while ((ch = getch()) != BINDING_QUIT) {
106 case BINDING_SCROLL_UP:
107 menu_driver(todo_menu, REQ_UP_ITEM);
109 case BINDING_SCROLL_DOWN:
110 menu_driver(todo_menu, REQ_DOWN_ITEM);
112 case BINDING_JUMP_TOP:
113 menu_driver(todo_menu, REQ_FIRST_ITEM);
115 case BINDING_JUMP_BOTTOM:
116 menu_driver(todo_menu, REQ_LAST_ITEM);
128 unpost_menu(todo_menu);
129 free_todo(todos, todo_length);
135 winch_handler(int sig)
142 read_todo(FILE* file, int* length)
143 { // apparently getline isn't rly that portable, so consider other options
155 while ((nread = getline(&lineptr, &len, file)) != -1) {
157 out_arr = realloc(out_arr, (sizeof(char*))*out_len); // bad to keep resizing?
159 lineptr[strcspn(lineptr, "\n")] = 0; // remove newline
160 out_arr[out_len-1] = lineptr;
170 create_win(int height, int width, int y, int x)
172 WINDOW* new_win = newwin(height, width, y, x);
178 create_todo_menu(WINDOW* win, char** todo_list, int todo_length)
185 item_list = malloc((todo_length+1)*sizeof(ITEM*));
186 for (int i = 0; i < todo_length; i++) {
187 item_list[i] = new_item(todo_list[i], "");
188 set_item_userptr(item_list[i], on_select);
190 item_list[todo_length] = NULL; // last item needs to be a null pointer for some reason?
192 todo_menu = new_menu(item_list);
194 getmaxyx(win, wheight, wwidth);
195 set_menu_win(todo_menu, win);
196 set_menu_sub(todo_menu, derwin(win, wheight-2, wwidth-2, 1, 2));
197 set_menu_mark(todo_menu, "");
198 set_menu_spacing(todo_menu, 1, 2, 1);
199 set_menu_fore(todo_menu, COLOR_PAIR(SELECTED_COLOR));
200 set_menu_back(todo_menu, COLOR_PAIR(NON_SELECTED_COLOR));
202 box(win, 0, 0); //temp
208 on_select(char *item)
214 free_todo(char** todo_list, int todo_length)
216 // probably check if list is too short or too long
217 for (int i = 0; i < todo_length; i++) {