menu test
[taskasaur.git] / menutest.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <ncurses.h>
4 #include <menu.h>
5
6 WINDOW* create_list_win(int height, int width, int y, int x);
7
8 int 
9 main(int argc, char** argv) 
10 {
11     int height, width;
12     int ch;
13
14     WINDOW* todo_win;
15     char* todos[] = {"eat bread", "eat milk", "eat cheese"};
16     int todo_length;
17     ITEM** todo_items;
18     MENU* todo_menu;
19     ITEM* cur_item;
20
21     // start ncurses 
22     initscr();
23     cbreak();
24     noecho();
25     curs_set(0);
26     start_color();
27
28     getmaxyx(stdscr, height, width);
29     refresh();
30
31     /* init todo menu stuff */
32
33     todo_win = create_list_win(20, 40, 5, 5);
34     todo_length = sizeof(todos)/sizeof(todos[0]);
35
36     todo_items = malloc((todo_length+1)*sizeof(ITEM*));
37     for (int i = 0; i < todo_length; i++) {
38         todo_items[i] = new_item(todos[i], "");
39     }
40     todo_items[todo_length] = NULL; // last item needs to be a null pointer for some reason?
41
42     todo_menu = new_menu(todo_items);
43     post_menu(todo_menu);
44
45     /* todo_menu = new_menu(); */
46
47     /* for (int i = 0; i < todo_length; i++) { */
48     /*     mvwprintw(todo_win, i, 0, todos[i]); */
49     /* } */
50     wrefresh(todo_win);
51
52     while ((ch = getch()) != 113) { // while not q
53         
54         // ofc the first thing we need is vim keys 
55         switch (ch) {
56             case 106: // j
57                 menu_driver(todo_menu, REQ_DOWN_ITEM);
58                 break;
59             case 107: // k
60                 menu_driver(todo_menu, REQ_UP_ITEM);
61                 break;
62         } 
63
64         refresh();
65         /* clear(); */
66     }
67
68     endwin();
69
70     return 0;
71 }
72
73 WINDOW* 
74 create_list_win(int height, int width, int y, int x)
75 {
76     WINDOW* new_win = newwin(height, width, y, x);
77     wrefresh(new_win);
78     return new_win;
79 }