-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenuWin.c
51 lines (47 loc) · 1.1 KB
/
menuWin.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <ncurses.h>
int main()
{
initscr();
noecho();
int yMax, xMax;
getmaxyx(stdscr, yMax, xMax);
WINDOW *menuwin = newwin(6, xMax - 12, yMax - 8, 5);
box(menuwin, 0, 0);
refresh();
wrefresh(menuwin);
// so that we can use special macros like KEY_UP
keypad(menuwin, true);
char *choices[3] = {"File", "Edit", "View"};
int choice;
int highlight = 0;
while (1)
{
for (int i = 0; i < 3; i++)
{
if (i == highlight)
wattron(menuwin, A_REVERSE);
mvwprintw(menuwin, i + 1, 1, choices[i]);
wattroff(menuwin, A_REVERSE);
}
choice = wgetch(menuwin);
switch (choice)
{
case KEY_UP:
highlight = (highlight + 2) % 3;
break;
case KEY_DOWN:
highlight = (highlight + 1) % 3;
break;
default:
break;
}
// 10 is for enter key
if (choice == 10)
{
break;
}
}
printw("Your choice was %s", choices[highlight]);
getch();
endwin();
}