X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=taskasaur.c;h=39eaca6e9ba669a8c1b76bb14fbd06fbd040d389;hb=103d9d622254eb6257565bd08da27376c12510fd;hp=a4c0f4e4938827982894b5ab6b367bdd6e12c68c;hpb=f74c3f9aca7f090530179355c399a08bb9ae164a;p=taskasaur.git diff --git a/taskasaur.c b/taskasaur.c index a4c0f4e..39eaca6 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -1,15 +1,18 @@ #include -#include -#include #include +#include #include +#include +#include void winch_handler(int sig); -char** read_todo(FILE* file); +char** read_todo(FILE* file, int* length); WINDOW* create_list_win(int height, int width, int y, int x); +void draw_todo(WINDOW* todo_win, char** todo_list, int todo_length); + #include "config.h" int @@ -17,6 +20,8 @@ main(int argc, char** argv) { int flag; FILE* board_file; + char** todos; + int todo_length; int height, width; int x, y; int ch; @@ -36,8 +41,7 @@ main(int argc, char** argv) return 1; } - char** todos = read_todo(board_file); - printf(todos[0]); + todos = read_todo(board_file, &todo_length); fclose(board_file); break; @@ -51,7 +55,14 @@ main(int argc, char** argv) 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: @@ -61,14 +72,12 @@ main(int argc, char** argv) } - - return 0; - // start ncurses initscr(); cbreak(); /* raw(); */ noecho(); + curs_set(0); start_color(); init_pair(1, COLOR_CYAN, COLOR_BLACK); @@ -78,7 +87,8 @@ main(int argc, char** argv) x = y = 0; refresh(); - todo_win = create_list_win(20, 20, 5, 5); + todo_win = create_list_win(20, 40, 5, 5); + draw_todo(todo_win, todos, todo_length); move(y,x); while ((ch = getch()) != 113) { // while not q @@ -105,6 +115,10 @@ main(int argc, char** argv) } endwin(); + + /* Free mem */ + free(todos); // prob need to free each string in list too + return 0; } @@ -115,9 +129,8 @@ winch_handler(int sig) refresh(); } - char** -read_todo(FILE* file) +read_todo(FILE* file, int* length) { // apparently getline isn't rly that portable, so consider other options char** out_arr; int out_len; @@ -133,13 +146,13 @@ read_todo(FILE* file) while ((nread = getline(&lineptr, &len, file)) != -1) { out_len++; out_arr = realloc(out_arr, (sizeof(char*))*out_len); // bad to keep resizing? - printf("Pointer set to: %p\n", lineptr); out_arr[out_len-1] = lineptr; lineptr = NULL; len = 0; } - + + *length = out_len; return out_arr; } @@ -147,7 +160,15 @@ WINDOW* create_list_win(int height, int width, int y, int x) { WINDOW* new_win = newwin(height, width, y, x); - box(new_win, 0, 0); wrefresh(new_win); return new_win; } + +void +draw_todo(WINDOW* todo_win, char** todo_list, int todo_length) { + for (int i = 0; i < todo_length; i++) { + mvwprintw(todo_win, i+1, 2, todo_list[i]); + } + box(todo_win, 0, 0); + wrefresh(todo_win); +}