diff options
author | louie <lshprung@tutanota.com> | 2023-07-07 15:03:52 -0700 |
---|---|---|
committer | louie <lshprung@tutanota.com> | 2023-07-08 17:28:21 -0700 |
commit | 15b92cd8b26116a5c59fab1490f50b33a5cdf01c (patch) | |
tree | b7ab60c0601e2dda33ef915c0919c431c355f664 /src | |
parent | 2d4457781f7262bef67d6681767db9393ce35b6d (diff) |
Create tui_text structure
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/Makefile.in | 43 | ||||
-rw-r--r-- | src/draw.c | 38 | ||||
-rw-r--r-- | src/tui_text.c | 36 | ||||
-rw-r--r-- | src/tui_text.h | 28 |
5 files changed, 129 insertions, 18 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index ed908a9..c20d9e4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = subdir-objects bin_PROGRAMS = assignment-list-tui -assignment_list_tui_SOURCES = main.c draw.c draw.h entry.c entry.h group.c group.h db/$(default_db)/db.c db/$(default_db)/db.h +assignment_list_tui_SOURCES = main.c db/$(default_db)/db.c db/$(default_db)/db.h draw.c draw.h entry.c entry.h group.c group.h tui_text.c tui_text.h assignment_list_tui_LDADD = @CURSES_LIBS@ @SQLITE3_LDFLAGS@ assignment_list_tui_CPPFLAGS = @CURSES_CFLAGS@ @SQLITE3_CFLAGS@ -Idb/$(default_db) diff --git a/src/Makefile.in b/src/Makefile.in index bf3d246..5a3588b 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -101,10 +101,11 @@ am__installdirs = "$(DESTDIR)$(bindir)" PROGRAMS = $(bin_PROGRAMS) am__dirstamp = $(am__leading_dot)dirstamp am_assignment_list_tui_OBJECTS = assignment_list_tui-main.$(OBJEXT) \ + db/$(default_db)/assignment_list_tui-db.$(OBJEXT) \ assignment_list_tui-draw.$(OBJEXT) \ assignment_list_tui-entry.$(OBJEXT) \ assignment_list_tui-group.$(OBJEXT) \ - db/$(default_db)/assignment_list_tui-db.$(OBJEXT) + assignment_list_tui-tui_text.$(OBJEXT) assignment_list_tui_OBJECTS = $(am_assignment_list_tui_OBJECTS) assignment_list_tui_DEPENDENCIES = AM_V_P = $(am__v_P_@AM_V@) @@ -126,6 +127,7 @@ am__depfiles_remade = ./$(DEPDIR)/assignment_list_tui-draw.Po \ ./$(DEPDIR)/assignment_list_tui-entry.Po \ ./$(DEPDIR)/assignment_list_tui-group.Po \ ./$(DEPDIR)/assignment_list_tui-main.Po \ + ./$(DEPDIR)/assignment_list_tui-tui_text.Po \ db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Po am__mv = mv -f AM_V_lt = $(am__v_lt_@AM_V@) @@ -268,7 +270,7 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = subdir-objects -assignment_list_tui_SOURCES = main.c draw.c draw.h entry.c entry.h group.c group.h db/$(default_db)/db.c db/$(default_db)/db.h +assignment_list_tui_SOURCES = main.c db/$(default_db)/db.c db/$(default_db)/db.h draw.c draw.h entry.c entry.h group.c group.h tui_text.c tui_text.h assignment_list_tui_LDADD = @CURSES_LIBS@ @SQLITE3_LDFLAGS@ assignment_list_tui_CPPFLAGS = @CURSES_CFLAGS@ @SQLITE3_CFLAGS@ -Idb/$(default_db) all: all-am @@ -371,6 +373,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/assignment_list_tui-entry.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/assignment_list_tui-group.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/assignment_list_tui-main.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/assignment_list_tui-tui_text.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Po@am__quote@ # am--include-marker $(am__depfiles_remade): @@ -409,6 +412,20 @@ assignment_list_tui-main.obj: main.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o assignment_list_tui-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi` +db/$(default_db)/assignment_list_tui-db.o: db/$(default_db)/db.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT db/$(default_db)/assignment_list_tui-db.o -MD -MP -MF db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Tpo -c -o db/$(default_db)/assignment_list_tui-db.o `test -f 'db/$(default_db)/db.c' || echo '$(srcdir)/'`db/$(default_db)/db.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Tpo db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='db/$(default_db)/db.c' object='db/$(default_db)/assignment_list_tui-db.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o db/$(default_db)/assignment_list_tui-db.o `test -f 'db/$(default_db)/db.c' || echo '$(srcdir)/'`db/$(default_db)/db.c + +db/$(default_db)/assignment_list_tui-db.obj: db/$(default_db)/db.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT db/$(default_db)/assignment_list_tui-db.obj -MD -MP -MF db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Tpo -c -o db/$(default_db)/assignment_list_tui-db.obj `if test -f 'db/$(default_db)/db.c'; then $(CYGPATH_W) 'db/$(default_db)/db.c'; else $(CYGPATH_W) '$(srcdir)/db/$(default_db)/db.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Tpo db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='db/$(default_db)/db.c' object='db/$(default_db)/assignment_list_tui-db.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o db/$(default_db)/assignment_list_tui-db.obj `if test -f 'db/$(default_db)/db.c'; then $(CYGPATH_W) 'db/$(default_db)/db.c'; else $(CYGPATH_W) '$(srcdir)/db/$(default_db)/db.c'; fi` + assignment_list_tui-draw.o: draw.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT assignment_list_tui-draw.o -MD -MP -MF $(DEPDIR)/assignment_list_tui-draw.Tpo -c -o assignment_list_tui-draw.o `test -f 'draw.c' || echo '$(srcdir)/'`draw.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/assignment_list_tui-draw.Tpo $(DEPDIR)/assignment_list_tui-draw.Po @@ -451,19 +468,19 @@ assignment_list_tui-group.obj: group.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o assignment_list_tui-group.obj `if test -f 'group.c'; then $(CYGPATH_W) 'group.c'; else $(CYGPATH_W) '$(srcdir)/group.c'; fi` -db/$(default_db)/assignment_list_tui-db.o: db/$(default_db)/db.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT db/$(default_db)/assignment_list_tui-db.o -MD -MP -MF db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Tpo -c -o db/$(default_db)/assignment_list_tui-db.o `test -f 'db/$(default_db)/db.c' || echo '$(srcdir)/'`db/$(default_db)/db.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Tpo db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='db/$(default_db)/db.c' object='db/$(default_db)/assignment_list_tui-db.o' libtool=no @AMDEPBACKSLASH@ +assignment_list_tui-tui_text.o: tui_text.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT assignment_list_tui-tui_text.o -MD -MP -MF $(DEPDIR)/assignment_list_tui-tui_text.Tpo -c -o assignment_list_tui-tui_text.o `test -f 'tui_text.c' || echo '$(srcdir)/'`tui_text.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/assignment_list_tui-tui_text.Tpo $(DEPDIR)/assignment_list_tui-tui_text.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tui_text.c' object='assignment_list_tui-tui_text.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o db/$(default_db)/assignment_list_tui-db.o `test -f 'db/$(default_db)/db.c' || echo '$(srcdir)/'`db/$(default_db)/db.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o assignment_list_tui-tui_text.o `test -f 'tui_text.c' || echo '$(srcdir)/'`tui_text.c -db/$(default_db)/assignment_list_tui-db.obj: db/$(default_db)/db.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT db/$(default_db)/assignment_list_tui-db.obj -MD -MP -MF db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Tpo -c -o db/$(default_db)/assignment_list_tui-db.obj `if test -f 'db/$(default_db)/db.c'; then $(CYGPATH_W) 'db/$(default_db)/db.c'; else $(CYGPATH_W) '$(srcdir)/db/$(default_db)/db.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Tpo db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='db/$(default_db)/db.c' object='db/$(default_db)/assignment_list_tui-db.obj' libtool=no @AMDEPBACKSLASH@ +assignment_list_tui-tui_text.obj: tui_text.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT assignment_list_tui-tui_text.obj -MD -MP -MF $(DEPDIR)/assignment_list_tui-tui_text.Tpo -c -o assignment_list_tui-tui_text.obj `if test -f 'tui_text.c'; then $(CYGPATH_W) 'tui_text.c'; else $(CYGPATH_W) '$(srcdir)/tui_text.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/assignment_list_tui-tui_text.Tpo $(DEPDIR)/assignment_list_tui-tui_text.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tui_text.c' object='assignment_list_tui-tui_text.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o db/$(default_db)/assignment_list_tui-db.obj `if test -f 'db/$(default_db)/db.c'; then $(CYGPATH_W) 'db/$(default_db)/db.c'; else $(CYGPATH_W) '$(srcdir)/db/$(default_db)/db.c'; fi` +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(assignment_list_tui_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o assignment_list_tui-tui_text.obj `if test -f 'tui_text.c'; then $(CYGPATH_W) 'tui_text.c'; else $(CYGPATH_W) '$(srcdir)/tui_text.c'; fi` ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique @@ -597,6 +614,7 @@ distclean: distclean-am -rm -f ./$(DEPDIR)/assignment_list_tui-entry.Po -rm -f ./$(DEPDIR)/assignment_list_tui-group.Po -rm -f ./$(DEPDIR)/assignment_list_tui-main.Po + -rm -f ./$(DEPDIR)/assignment_list_tui-tui_text.Po -rm -f db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ @@ -647,6 +665,7 @@ maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/assignment_list_tui-entry.Po -rm -f ./$(DEPDIR)/assignment_list_tui-group.Po -rm -f ./$(DEPDIR)/assignment_list_tui-main.Po + -rm -f ./$(DEPDIR)/assignment_list_tui-tui_text.Po -rm -f db/$(default_db)/$(DEPDIR)/assignment_list_tui-db.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -7,11 +7,14 @@ #include "draw.h" #include "entry.h" #include "group.h" +#include "tui_text.h" + +void draw_data(Tui_text **main_text, Group **groups, int g_count, Entry **entries, int e_count, WINDOW *w, 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 + Tui_text *main_text = NULL; // keep track of text location - this array will be in order - top to bottom WINDOW *w_main; // set an interrupt to end cleanly @@ -29,7 +32,7 @@ void tui_init(Group **groups, int g_count, Entry **entries, int e_count) { refresh(); // draw groups and entries - draw_data(groups, g_count, entries, e_count, w_main, 1, 1); + draw_data(&main_text, groups, g_count, entries, e_count, w_main, 1, 1); wrefresh(w_main); input = getch(); @@ -44,24 +47,49 @@ void tui_end() { -void draw_data(Group **groups, int g_count, Entry **entries, int e_count, WINDOW *w, int start_x, int start_y) { +void draw_data(Tui_text **main_text, Group **groups, int g_count, Entry **entries, int e_count, WINDOW *w, int start_x, int start_y) { int i; int j; + int mt_index = 0; // separate index to keep track of main_text array char buf[BUF_LEN]; + + // initialize main_text + if(*main_text != NULL) free(*main_text); + *main_text = malloc(sizeof(Tui_text) * (e_count + g_count)); for(i = 0; i < g_count; ++i) { + // print group mvwprintw(w, start_y, start_x, "%s", group_get_name(&((*groups)[i]))); + + // save group in main_text array + tui_text_set_x(&((*main_text)[mt_index]), start_x); + tui_text_set_y(&((*main_text)[mt_index]), start_y); + tui_text_set_type(&((*main_text)[mt_index]), GROUP); + tui_text_set_data(&((*main_text)[mt_index]), &((*groups)[i])); + ++mt_index; + ++start_y; for(j = 0; j < e_count; ++j) { + // check if an entry belongs to the group if(entry_get_group_id(&((*entries)[j])) == group_get_id(&((*groups)[i]))) { + // print entry mvwprintw(w, start_y, start_x, "\t"); + // print date if there is one 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]))); + // print entry title + wprintw(w, "%s", entry_get_title(&((*entries)[j]))); + + // save entry in main_text array + tui_text_set_x(&((*main_text)[mt_index]), start_x); + tui_text_set_y(&((*main_text)[mt_index]), start_y); + tui_text_set_type(&((*main_text)[mt_index]), ENTRY); + tui_text_set_data(&((*main_text)[mt_index]), &((*entries)[j])); + mt_index++; + ++start_y; } } diff --git a/src/tui_text.c b/src/tui_text.c new file mode 100644 index 0000000..d86002a --- /dev/null +++ b/src/tui_text.c @@ -0,0 +1,36 @@ +#include "tui_text.h" + +// getters +int tui_text_get_x(Tui_text *t) { + return t->start_x; +} + +int tui_text_get_y(Tui_text *t) { + return t->start_y; +} + +enum tui_text_type tui_text_get_type(Tui_text *t) { + return t->type; +} + +void *tui_text_get_data(Tui_text *t) { + return t->data; +} + + +// setters +void tui_text_set_x(Tui_text *t, int start_x) { + t->start_x = start_x; +} + +void tui_text_set_y(Tui_text *t, int start_y) { + t->start_y = start_y; +} + +void tui_text_set_type(Tui_text *t, enum tui_text_type type) { + t->type = type; +} + +void tui_text_set_data(Tui_text *t, void *data) { + t->data = data; +} diff --git a/src/tui_text.h b/src/tui_text.h new file mode 100644 index 0000000..6edc9e6 --- /dev/null +++ b/src/tui_text.h @@ -0,0 +1,28 @@ +#ifndef TUI_TEXT_H +#define TUI_TEXT_H + +enum tui_text_type { ENTRY, GROUP }; + +typedef struct tui_text { + // location of beginning of text in window + int start_x; + int start_y; + + // relevant data + enum tui_text_type type; + void *data; // should be either Entry * or Group * +} Tui_text; + +// getters +int tui_text_get_x(Tui_text *t); +int tui_text_get_y(Tui_text *t); +enum tui_text_type tui_text_get_type(Tui_text *t); +void *tui_text_get_data(Tui_text *t); + +// setters +void tui_text_set_x(Tui_text *t, int start_x); +void tui_text_set_y(Tui_text *t, int start_y); +void tui_text_set_type(Tui_text *t, enum tui_text_type type); +void tui_text_set_data(Tui_text *t, void *data); + +#endif |