From 2d4457781f7262bef67d6681767db9393ce35b6d Mon Sep 17 00:00:00 2001 From: Louie S Date: Wed, 5 Jul 2023 16:39:37 -0700 Subject: Draw due date if it exists --- src/draw.c | 22 ++++++++++++++++------ src/main.c | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/draw.c b/src/draw.c index d19a45b..b483b0c 100644 --- a/src/draw.c +++ b/src/draw.c @@ -1,12 +1,14 @@ #include #include #include +#include +#include #include "draw.h" #include "entry.h" #include "group.h" -void draw_data(Group **groups, int g_count, Entry **entries, int e_count, int start_x, int start_y); +void draw_data(Group **groups, int g_count, Entry **entries, int e_count, WINDOW *w, int start_x, int start_y); void tui_init(Group **groups, int g_count, Entry **entries, int e_count) { int input; // capture user input @@ -25,10 +27,10 @@ void tui_init(Group **groups, int g_count, Entry **entries, int e_count) { w_main = newwin(0, 0, 0, 0); box(w_main, 0, 0); refresh(); - wrefresh(w_main); // draw groups and entries - draw_data(groups, g_count, entries, e_count, 1, 1); + draw_data(groups, g_count, entries, e_count, w_main, 1, 1); + wrefresh(w_main); input = getch(); tui_end(); @@ -42,16 +44,24 @@ void tui_end() { -void draw_data(Group **groups, int g_count, Entry **entries, int e_count, int start_x, int start_y) { +void draw_data(Group **groups, int g_count, Entry **entries, int e_count, WINDOW *w, int start_x, int start_y) { int i; int j; + char buf[BUF_LEN]; for(i = 0; i < g_count; ++i) { - mvprintw(start_y, start_x, "%s", group_get_name(&((*groups)[i]))); + mvwprintw(w, start_y, start_x, "%s", group_get_name(&((*groups)[i]))); ++start_y; for(j = 0; j < e_count; ++j) { if(entry_get_group_id(&((*entries)[j])) == group_get_id(&((*groups)[i]))) { - mvprintw(start_y, start_x, "\t%s", entry_get_title(&((*entries)[i]))); + mvwprintw(w, start_y, start_x, "\t"); + if(entry_get_due_date(&((*entries)[j])) != NULL) { + memset(buf, 0, BUF_LEN); + strftime(buf, BUF_LEN, "%a, %m/%d", entry_get_due_date(&((*entries)[j]))); + wprintw(w, "%s: ", buf); + } + //mvprintw(start_y, start_x, "\t%s", entry_get_title(&((*entries)[i]))); + wprintw(w, "%s", entry_get_title(&((*entries)[i]))); ++start_y; } } diff --git a/src/main.c b/src/main.c index 70e4516..18db26b 100644 --- a/src/main.c +++ b/src/main.c @@ -45,7 +45,7 @@ int main() { if(groups == NULL) perror("could not get groups"); if(entries == NULL) perror("could not get entries"); - //tui_init(&groups, group_count, &entries, entry_count); + tui_init(&groups, group_count, &entries, entry_count); return 0; } -- cgit