-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathncursesDemo.cpp
More file actions
74 lines (57 loc) · 1.29 KB
/
ncursesDemo.cpp
File metadata and controls
74 lines (57 loc) · 1.29 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
#include <ncurses.h>
using namespace std;
WINDOW *create_newwin(int height, int width, int starty, int startx);
void destroy_win(WINDOW *localwin);
int main(argc, char *argv[])
{
WINDOW *menu;
int height = 0, width = 0, starty = 0, startx = 0;
int ch = 0;
initscr();
noecho();
keypad(stdscr, TRUE);
printw("Press F1 to exit program");
height = 3;
width = 10;
starty = (LINES - height)/2;
startx = (COLS - width)/2;
refresh();
menu = create_newwin(height, width, starty, startx);
while((ch = getch()) != KEY_F(1))
{
switch(ch)
{
case KEY_UP:
destroy_win(menu);
menu = create_newwin(height, width, --starty, startx);
break;
case KEY_DOWN:
destroy_win(menu);
menu = create_newwin(height, width, ++starty, startx);
break;
case KEY_LEFT:
destroy_win(menu);
menu = create_newwin(height, width, starty, --startx);
break;
case KEY_RIGHT:
destroy_win(menu);
menu = create_newwin(height, width, starty, ++startx);
break;
}
}
endwin();
return 0;
}
WINDOW *create_newwin(int height, int width, int starty, int startx)
{
WINDOW *localwin = newwin(height, width, starty, startx);
box(localwin,0,0);
wrefresh(localwin);
return localwin;
}
void destroy_win(WINDOW *localwin)
{
wborder(localwin,' ',' ',' ',' ',' ',' ',' ',' ');
wrefresh(localwin);
delwin(localwin);
}