From dc6db567d464bb710398c39dba67d396187f1b0c Mon Sep 17 00:00:00 2001 From: dam Date: Tue, 2 Aug 2022 01:34:29 +0000 Subject: Prototype for user interface. --- task_tracker.c | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 task_tracker.c (limited to 'task_tracker.c') diff --git a/task_tracker.c b/task_tracker.c new file mode 100644 index 0000000..6bef5d4 --- /dev/null +++ b/task_tracker.c @@ -0,0 +1,183 @@ +// Compile with: gcc task_tracker.c -O2 -m64 -lncurses -o task_tracker.x64 + +#include +#include + + +void draw_header() +{ + const char *app_name = "Task Tracker"; + const char *app_version = "v1.0"; + + int row,col; /* to store the number of rows and the number of colums of the screen */ + initscr(); /* start the curses mode */ + getmaxyx(stdscr,row,col); /* get the number of rows and columns */ + + mvaddch(0, 0, ACS_ULCORNER); + addch(ACS_HLINE); + addch(' '); + printw(app_name); + addch(' '); + for (int idx = strlen(app_name) + 4; idx < col - strlen(app_version) - 4; idx ++) { + addch(ACS_HLINE); + } + addch(' '); + printw(app_version); + addch(' '); + addch(ACS_HLINE); + addch(ACS_URCORNER); +// addch('@'); +// mvprintw(row/2,(col-strlen(mesg))/2,"%s",mesg); +} + +void draw_table() +{ + const char *table_headers[] = { "Task", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Total" }; + const int table_headers_size = sizeof(table_headers)/sizeof(char*); + + int row,col; /* to store the number of rows and the number of colums of the screen */ + initscr(); /* start the curses mode */ + getmaxyx(stdscr,row,col); /* get the number of rows and columns */ + + mvaddch(1, 0, ACS_LTEE); + for (int idx = 0; idx < table_headers_size; idx++) { + if (idx > 0) { + addch(ACS_TTEE); +// printw(" %c", ACS_PLUS); + } + addch(ACS_HLINE); + printw(" %s ", table_headers[idx]); + addch(ACS_HLINE); + + } + + int cursor_y, cursor_x; + getyx(stdscr, cursor_y, cursor_x); + for (int idx = cursor_x; idx < col-1; idx++) { + addch(ACS_HLINE); + } + addch(ACS_RTEE); +} + +void draw_footer() +{ + const char *app_name = "Task Tracker"; + const char *app_version = "v1.0"; + + int row, col; /* to store the number of rows and the number of colums of the screen */ + initscr(); /* start the curses mode */ + getmaxyx(stdscr,row,col); /* get the number of rows and columns */ + + printw("Row %d", row); + + mvaddch(row-1, 0, ACS_LLCORNER); + addch(' '); + printw(app_name); + addch(' '); + for (int idx = strlen(app_name) + 3; idx < col - strlen(app_version) - 3; idx ++) { + addch(ACS_HLINE); + } + addch(' '); + printw(app_version); + addch(' '); + addch(ACS_LRCORNER); +} + + +WINDOW *create_newwin(int height, int width, int starty, int startx); +void destroy_win(WINDOW *local_win); + +int main(int argc, char *argv[]) +{ WINDOW *my_win; + int startx, starty, width, height; + int ch; + + initscr(); /* Start curses mode */ + cbreak(); /* Line buffering disabled, Pass on + * everty thing to me */ + keypad(stdscr, TRUE); /* I need that nifty F1 */ + curs_set(0); // Set cursor invisible. + + height = 3; + width = 10; + starty = (LINES - height) / 2; /* Calculating for a center placement */ + startx = (COLS - width) / 2; /* of the window */ + printw("Press F1 to exit"); + refresh(); + my_win = create_newwin(height, width, starty, startx); + + int rows; + int colums; + + halfdelay(10); + while((ch = getch()) != KEY_F(1)) + { + draw_header(); + draw_table(); + draw_footer(); + switch(ch) + { + case KEY_RESIZE: +// getmaxyx(stdscr, rows, colums); +// resizeterm(rows, colums); + erase(); + break; + + case KEY_LEFT: + destroy_win(my_win); + my_win = create_newwin(height, width, starty,--startx); + break; + case KEY_RIGHT: + destroy_win(my_win); + my_win = create_newwin(height, width, starty,++startx); + break; + case KEY_UP: + destroy_win(my_win); + my_win = create_newwin(height, width, --starty,startx); + break; + case KEY_DOWN: + destroy_win(my_win); + my_win = create_newwin(height, width, ++starty,startx); + break; + } + } + + endwin(); /* End curses mode */ + return 0; +} + + + +WINDOW *create_newwin(int height, int width, int starty, int startx) +{ WINDOW *local_win; + + local_win = newwin(height, width, starty, startx); + box(local_win, 0 , 0); /* 0, 0 gives default characters + * for the vertical and horizontal + * lines */ + wrefresh(local_win); /* Show that box */ + + return local_win; +} + +void destroy_win(WINDOW *local_win) +{ + /* box(local_win, ' ', ' '); : This won't produce the desired + * result of erasing the window. It will leave it's four corners + * and so an ugly remnant of window. + */ + wborder(local_win, ' ', ' ', ' ',' ',' ',' ',' ',' '); + /* The parameters taken are + * 1. win: the window on which to operate + * 2. ls: character to be used for the left side of the window + * 3. rs: character to be used for the right side of the window + * 4. ts: character to be used for the top side of the window + * 5. bs: character to be used for the bottom side of the window + * 6. tl: character to be used for the top left corner of the window + * 7. tr: character to be used for the top right corner of the window + * 8. bl: character to be used for the bottom left corner of the window + * 9. br: character to be used for the bottom right corner of the window + */ + wrefresh(local_win); + delwin(local_win); +} -- cgit v1.2.3