-void winch_handler(int sig);
-
-char** read_todo(FILE* file, int* length);
-
-WINDOW* create_win(int height, int width, int y, int x);
-MENU* create_todo_menu(WINDOW* win, char** todo_list, int todo_length);
-
-void free_todo(char** todo_list, int todo_length);
-
-#include "config.h"
-
-int
-main(int argc, char** argv)
-{
- int flag;
- FILE* board_file;
- char** todos;
- int todo_length;
-
- int height, width;
- int ch;
-
- WINDOW* todo_win;
- MENU* todo_menu;
-
- signal(SIGWINCH, winch_handler);
-
- // read command line args
- flag = getopt(argc, argv, "o:n:");
- switch (flag) {
- case 'o':
-
- // read from task file (might need to check for read and write permissions)
- board_file = fopen(optarg, "r");
- if (!board_file) {
- printf("%s does not exist\n", optarg);
- return 1;
- }
-
- todos = read_todo(board_file, &todo_length);
- fclose(board_file);
-
- break;
-
- case 'n':
-
- // make sure file does not exist
- // however, it maybe be possible that an different error has occured (besides the file not existing)
- if (access(optarg, F_OK) == 0) {
- printf("%s already exists\n", optarg);
- return 1;
- }
- // create a file here
- board_file = fopen(optarg, "w");
- // write init stuff here
- fclose(board_file);
- printf("Successfully created %s\n", optarg);
-
- todos = malloc(0);
- todo_length = 0;
-
- break;
-
- case -1:
- case '?':
- printf("Help string\n");
- return 2;
- }
-
- /* for (int i = 0; i < todo_length; i++) { */
- /* printf("%p\n", todos[i]); */
- /* printf(todos[i]); */
- /* } */
- /* return 0; */
-
- // start ncurses
- initscr();
- cbreak();
- noecho();
- curs_set(0);
- start_color();
-
- getmaxyx(stdscr, height, width);
-
- todo_win = create_win(20, 40, 5, 5);
-
- todo_menu = create_todo_menu(todo_win, todos, todo_length);
- post_menu(todo_menu);
- refresh();
- wrefresh(todo_win);
-
- while ((ch = getch()) != 'q') {
-
- switch (ch) {
- case 'j':
- menu_driver(todo_menu, REQ_DOWN_ITEM);
- break;
- case 'k':
- menu_driver(todo_menu, REQ_UP_ITEM);
- break;
- case 'G': // try to implement gg too
- menu_driver(todo_menu, REQ_LAST_ITEM);
- break;
- }
- wrefresh(todo_win);
-
- /* wrefresh(todo_win); */
- }
-
- endwin();
-
- /* Free mem */
- unpost_menu(todo_menu);
- free_todo(todos, todo_length);
-
- return 0;
-}
-
-void
-winch_handler(int sig)