From: Daniel Liu <mr.picklepinosaur@gmail.com>
Date: Sun, 24 Jan 2021 22:19:41 +0000 (-0500)
Subject: colors on select
X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=7cd288f609ab7d99e5fb5b8da07d2c1b6f32907d;p=taskasaur.git

colors on select
---

diff --git a/config.h b/config.h
index 24434da..153eb9c 100644
--- a/config.h
+++ b/config.h
@@ -1,4 +1,9 @@
 
+#ifndef __CONFIG_H__
+#define __CONFIG_H__
+
+#include <ncurses.h>
+
 static char font[] = "Source Code Pro:size=12";
 
 
@@ -26,3 +31,4 @@ static int non_selected_color = COLOR_WHITE;
 #define BINDING_JUMP_BOTTOM 'G'
 #define BINDING_SELECT '\n'
 
+#endif
diff --git a/headers/render.h b/headers/render.h
index c3407f9..4232f92 100644
--- a/headers/render.h
+++ b/headers/render.h
@@ -5,7 +5,7 @@
 #include <ncurses.h>
 
 enum TaskasaurColors {
-    TS_SELECTED,
+    TS_SELECTED = 1,
     TS_NONSELECTED
 };
 
diff --git a/makefile b/makefile
index 4e10dde..eaa0b02 100644
--- a/makefile
+++ b/makefile
@@ -16,6 +16,8 @@ menu.o: menu.c headers/menu.h
 utils.o: utils.c headers/utils.h
 	$(CC) -c utils.c
 
+# include config.h as depend
+
 taskasaur: taskasaur.c parser.o render.o menu.o utils.o
 	$(CC) -o $@ $^ -lncurses -lmd4c
 
diff --git a/menu.c b/menu.c
index 2c1975f..f077fd2 100644
--- a/menu.c
+++ b/menu.c
@@ -4,6 +4,7 @@
 #include <ncurses.h>
 
 #include "headers/menu.h"
+#include "headers/render.h"
 #include "headers/utils.h"
 
 typedef struct MenuItem {
@@ -77,13 +78,24 @@ render_menu(Menu* menu)
     cur_line = 0;
 
     for (int i = 0; i < menu->menu_length; i++) {
+
+        int wrapped_lines;
+        char* wrapped_text;
+        int text_color;
         
         /* wrap text by inserting newlines */
-        mvwprintw(menu->menu_win, cur_line, 0, menu->menu_items[i]->contents);
+        wrapped_text = wrap_text(menu->menu_items[i]->contents, menu->max_width, &wrapped_lines);        
 
         /* color selected item */
+        text_color = (i == menu->selected_item) ? TS_SELECTED : TS_NONSELECTED;
+
+        wattron(menu->menu_win, COLOR_PAIR(text_color));
+        mvwprintw(menu->menu_win, cur_line, 0, wrapped_text);
+        wattroff(menu->menu_win, COLOR_PAIR(text_color));
+
+        cur_line += wrapped_lines;
 
-        cur_line += 1;
+        free(wrapped_text);
 
     }
 
diff --git a/taskasaur.c b/taskasaur.c
index af7b3d3..647c848 100644
--- a/taskasaur.c
+++ b/taskasaur.c
@@ -17,9 +17,8 @@ main(int argc, char** argv)
 
     MenuItem** item_list = malloc(4*sizeof(MenuItem*));   
     for (int i = 0; i < 3; i++) {
-        item_list[i] = create_menuitem("lmao");
+        item_list[i] = create_menuitem("Many of you are probably feeling a little sad."); 
     }
-    item_list[3] = 0;
 
     Menu* menu = create_menu(item_list);
 
diff --git a/utils.c b/utils.c
index ecf4b70..a649239 100644
--- a/utils.c
+++ b/utils.c
@@ -39,7 +39,6 @@ wrap_text(char* str, int max_width, int* lines)
 
         str_read += max_width;
         line_count += 1;
-
     }
 
     *lines = line_count;