9 #define SELECTED_COLOR 1
10 #define NON_SELECTED_COLOR 2
18 void winch_handler(int sig);
20 char** read_todo(FILE* file, int* length);
22 WINDOW* create_win(int height, int width, int y, int x);
23 MENU* create_todo_menu(WINDOW* win, char** todo_list, int todo_length);
25 void on_select(char *item);
27 void free_todo(char** todo_list, int todo_length);
32 main(int argc, char** argv)
45 signal(SIGWINCH, winch_handler);
47 // read command line args
48 flag = getopt(argc, argv, "o:n:");
52 // read from task file (might need to check for read and write permissions)
53 board_file = fopen(optarg, "r");
55 printf("%s does not exist\n", optarg);
59 todos = read_todo(board_file, &todo_length);
66 // make sure file does not exist
67 // however, it maybe be possible that an different error has occured (besides the file not existing)
68 if (access(optarg, F_OK) == 0) {
69 printf("%s already exists\n", optarg);
73 board_file = fopen(optarg, "w");
74 // write init stuff here
76 printf("Successfully created %s\n", optarg);
85 printf("Help string\n");
98 init_pair(SELECTED_COLOR, selected_color, COLOR_BLACK);
99 init_pair(NON_SELECTED_COLOR, non_selected_color, COLOR_BLACK);
101 getmaxyx(stdscr, height, width);
103 todo_win = create_win(20, 40, 5, 5);
104 todo_menu = create_todo_menu(todo_win, todos, todo_length);
105 post_menu(todo_menu);
109 while ((ch = getch()) != BINDING_QUIT) {
112 case BINDING_SCROLL_UP:
113 menu_driver(todo_menu, REQ_UP_ITEM);
115 case BINDING_SCROLL_DOWN:
116 menu_driver(todo_menu, REQ_DOWN_ITEM);
118 case BINDING_JUMP_TOP:
119 menu_driver(todo_menu, REQ_FIRST_ITEM);
121 case BINDING_JUMP_BOTTOM:
122 menu_driver(todo_menu, REQ_LAST_ITEM);
134 unpost_menu(todo_menu);
135 free_todo(todos, todo_length);
141 winch_handler(int sig)
148 read_todo(FILE* file, int* length)
149 { // apparently getline isn't rly that portable, so consider other options
161 while ((nread = getline(&lineptr, &len, file)) != -1) {
163 out_arr = realloc(out_arr, (sizeof(char*))*out_len); // bad to keep resizing?
165 lineptr[strcspn(lineptr, "\n")] = 0; // remove newline
166 out_arr[out_len-1] = lineptr;
176 create_win(int height, int width, int y, int x)
178 WINDOW* new_win = newwin(height, width, y, x);
184 create_todo_menu(WINDOW* win, char** todo_list, int todo_length)
191 item_list = malloc((todo_length+1)*sizeof(ITEM*));
192 for (int i = 0; i < todo_length; i++) {
193 item_list[i] = new_item(todo_list[i], "");
194 set_item_userptr(item_list[i], on_select);
196 item_list[todo_length] = NULL; // last item needs to be a null pointer for some reason?
198 todo_menu = new_menu(item_list);
200 getmaxyx(win, wheight, wwidth);
201 set_menu_win(todo_menu, win);
202 set_menu_sub(todo_menu, derwin(win, wheight-2, wwidth-2, 1, 2));
203 set_menu_mark(todo_menu, "");
204 set_menu_spacing(todo_menu, 1, 2, 1);
205 set_menu_fore(todo_menu, COLOR_PAIR(SELECTED_COLOR));
206 set_menu_back(todo_menu, COLOR_PAIR(NON_SELECTED_COLOR));
208 box(win, 0, 0); //temp
214 on_select(char *item)
220 free_todo(char** todo_list, int todo_length)
222 // probably check if list is too short or too long
223 for (int i = 0; i < todo_length; i++) {