summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.in10
-rw-r--r--src/draw.c104
2 files changed, 97 insertions, 17 deletions
diff --git a/src/Makefile.in b/src/Makefile.in
index 5a3588b..6618dd0 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -86,6 +86,8 @@ POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
bin_PROGRAMS = assignment-list-tui$(EXEEXT)
subdir = src
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -236,7 +238,11 @@ am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
+build = @build@
build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
@@ -244,7 +250,11 @@ default_db = @default_db@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
+host = @host@
host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
diff --git a/src/draw.c b/src/draw.c
index 26d4d55..c6fb82c 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -9,13 +9,27 @@
#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);
+// main window-related globals
+WINDOW *w_main;
+Tui_text *main_text = NULL; // keep track of text location - this array will be in order - top to bottom
+
+// hover-related globals
+int hover_index; // current hover (as index for Tui_text, usually main_text)
+int hover_count; // number of hovers available
+
+
+// initialize a window
+void draw_data(Group **groups, int g_count, Entry **entries, int e_count, WINDOW *w, int start_x, int start_y);
+
+// move hover to a new Tui_text in window w
+void hover_move(WINDOW *w, int new_hover_index);
+
+// handle feedback loop
+void feedback_loop();
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
signal(SIGINT, tui_end);
@@ -32,10 +46,17 @@ void tui_init(Group **groups, int g_count, Entry **entries, int e_count) {
refresh();
// draw groups and entries
- draw_data(&main_text, groups, g_count, entries, e_count, w_main, 1, 1);
+ draw_data(groups, g_count, entries, e_count, w_main, 1, 1);
wrefresh(w_main);
- input = getch();
+ // initialize hover
+ hover_index = 0;
+ hover_move(w_main, 0);
+ wrefresh(w_main);
+
+ // feedback loop
+ feedback_loop();
+
tui_end();
free(*groups);
free(*entries);
@@ -47,25 +68,28 @@ void tui_end() {
-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) {
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));
+ if(main_text != NULL) free(main_text);
+ main_text = malloc(sizeof(Tui_text) * (e_count + g_count));
+
+ // set hover count
+ hover_count = 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]));
+ 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;
@@ -73,7 +97,7 @@ void draw_data(Tui_text **main_text, Group **groups, int g_count, Entry **entrie
// 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");
+ mvwprintw(w, start_y, start_x, " ");
// print date if there is one
if(entry_get_due_date(&((*entries)[j])) != NULL) {
memset(buf, 0, BUF_LEN);
@@ -84,10 +108,10 @@ void draw_data(Tui_text **main_text, Group **groups, int g_count, Entry **entrie
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]));
+ tui_text_set_x(&(main_text[mt_index]), start_x+2);
+ 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;
@@ -96,3 +120,49 @@ void draw_data(Tui_text **main_text, Group **groups, int g_count, Entry **entrie
++start_y;
}
}
+
+void hover_move(WINDOW *w, int new_hover_index) {
+ // avoid going out of bounds
+ if(new_hover_index < 0) new_hover_index = 0;
+ if(new_hover_index >= hover_count) new_hover_index = hover_count-1;
+
+ // unset previous hover
+ mvwchgat(w,
+ tui_text_get_y(&(main_text[hover_index])),
+ tui_text_get_x(&(main_text[hover_index])),
+ w->_maxx - tui_text_get_x(&(main_text[hover_index])),
+ A_NORMAL, 0, NULL);
+
+ // set new hover
+ hover_index = new_hover_index;
+ mvwchgat(w,
+ tui_text_get_y(&(main_text[hover_index])),
+ tui_text_get_x(&(main_text[hover_index])),
+ w->_maxx - tui_text_get_x(&(main_text[hover_index])),
+ A_REVERSE, 0, NULL);
+}
+
+void feedback_loop() {
+ int input;
+ bool finish = false; // turn to true to break out
+
+ while(!finish) {
+ input = getch();
+
+ switch(input) {
+ case 'q':
+ finish = true;
+ break;
+
+ case KEY_UP:
+ hover_move(w_main, hover_index-1);
+ wrefresh(w_main);
+ break;
+
+ case KEY_DOWN:
+ hover_move(w_main, hover_index+1);
+ wrefresh(w_main);
+ break;
+ }
+ }
+}