summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Zelent <zelent.marcin@gmail.com>2018-02-13 15:56:58 +0100
committerMarcin Zelent <zelent.marcin@gmail.com>2018-02-13 15:56:58 +0100
commit6c3423d4a92c2d779e00ca18797d6e6a14e2f887 (patch)
tree94ac17428f3c82f39d55461e08c8deb544bb0b58
parent141a1e13868fcf9b52cb8e30013e83172a45e702 (diff)
Implemented selectable list and removed menu.h dependency.
-rw-r--r--timetracker.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/timetracker.c b/timetracker.c
index ee2d3d1..508961c 100644
--- a/timetracker.c
+++ b/timetracker.c
@@ -3,7 +3,6 @@
#include <string.h>
#include <ncurses.h>
#include <form.h>
-#include <menu.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -30,28 +29,22 @@ void print_new(WINDOW *win)
void print_activities(WINDOW *win)
{
- ITEM **items;
- MENU *menu;
- int n;
- ITEM *cur_item;
-
- while (activities[n].start) n++;
- items = (ITEM **) calloc(n + 1, sizeof(ITEM *));
- for (int i = 0; i < n; ++i) {
- char name[100][100];
- char time[100][8];
+ int sel;
+
+ for (int i = 0; activities[i].start; i++) {
+ char name[100];
+ char time[7];
long dur = difftime(activities[i].end, activities[i].start);
- snprintf(name[i], 100, "%-*s", COLS - 7, activities[i].name);
- snprintf(time[i], 8, "%0.1f ", dur / 3600.0f);
- items[i] = new_item(name[i], time[i]);
+ snprintf(name, 100, "%-*s", COLS - 6, activities[i].name);
+ snprintf(time, 7, "%0.1f ", dur / 3600.0f);
+ strcat(name, time);
+ if (i == sel) {
+ wattron(win, COLOR_PAIR(1));
+ mvwprintw(win, i + 4, 0, name);
+ wattroff(win, COLOR_PAIR(1));
+ } else mvwprintw(win, i + 4, 0, name);
}
- items[n] = (ITEM *) NULL;
- menu = new_menu((ITEM **) items);
- set_menu_win(menu, win);
- set_menu_sub(menu, derwin(win, 0, 0, 4, 0));
- set_menu_format(menu, LINES - 6, 1);
- set_menu_mark(menu, 0);
- post_menu(menu);
+
wrefresh(win);
}
@@ -315,10 +308,13 @@ void window_controller()
int main(int argc, char *argv[])
{
initscr();
+ use_default_colors();
noecho();
cbreak();
keypad(stdscr, TRUE);
curs_set(0);
+ start_color();
+ init_pair(1, COLOR_BLACK, COLOR_WHITE);
strcpy(new.name,"N/A");
new.start = time(NULL);