-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathncursesMenu.cpp
More file actions
77 lines (59 loc) · 1.03 KB
/
ncursesMenu.cpp
File metadata and controls
77 lines (59 loc) · 1.03 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <string>
#include <ncurses.h>
#include "nfunctions.h"
using namespace std;
int main()
{
WINDOW * menu;
int height, width, starty, startx;
char selectKey;
char scrollKey;
initscr();
noecho();
cbreak();
keypad(stdscr, TRUE);
height = 10;
width = COLS - 60;
starty = LINES - 10;
startx = 30;
refresh();
menu = create_newwin(height, width, starty, startx);
keypad(menu,TRUE);
curs_set(0);
const string choices[3] = {"Option One", "Option Two", "Option Three"};
int choice;
int highlight = 0;
while(1)
{
for(int i = 0; i < 3; i++)
{
if(i == highlight)
wattron(menu,A_REVERSE);
mvwprintw(menu, i+1, 1,"%s", choices[i].c_str());
wattroff(menu, A_REVERSE);
}
choice = wgetch(menu);
switch(choice)
{
case KEY_UP:
highlight--;
if(highlight == -1)
highlight = 0;
break;
case KEY_DOWN:
highlight++;
if(highlight == 3)
highlight = 2;
break;
default:
break;
}
if(choice == 10)
break;
}
printw("Your choice was %s", choices[highlight].c_str());
getch();
endwin();
return 0;
}