Compare commits
3 Commits
e35c11c968
...
master
Author | SHA1 | Date | |
---|---|---|---|
b0a440deae | |||
02f41a62fc | |||
7464adb129 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
test
|
72
test.c
72
test.c
@@ -1,13 +1,24 @@
|
||||
#include <ncurses.h>
|
||||
#include <menu.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int curs_init();
|
||||
void color_init();
|
||||
int curs_end(ITEM* item);
|
||||
|
||||
int main() {
|
||||
initscr();
|
||||
cbreak();
|
||||
noecho();
|
||||
curs_set(0);
|
||||
keypad(stdscr,TRUE);
|
||||
mousemask(BUTTON1_PRESSED | BUTTON1_RELEASED | BUTTON1_CLICKED,NULL);
|
||||
|
||||
curs_init();
|
||||
|
||||
color_init(); /* If the program doesn't exit after this function call, it is
|
||||
assumed that the terminal supports colors */
|
||||
|
||||
|
||||
init_pair(1,COLOR_BLACK,COLOR_WHITE);
|
||||
|
||||
|
||||
|
||||
mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED,NULL);
|
||||
MEVENT event;
|
||||
int c;
|
||||
ITEM* cur_item;
|
||||
@@ -30,7 +41,11 @@ int main() {
|
||||
|
||||
getmaxyx(stdscr,maxy,maxx);
|
||||
|
||||
WINDOW* subwindow = derwin(stdscr,1,maxx-1,1,1);
|
||||
WINDOW* subwindow = derwin(stdscr,1,maxx-1,0,0);
|
||||
|
||||
wbkgd(subwindow,COLOR_PAIR(1));
|
||||
|
||||
keypad(subwindow,TRUE);
|
||||
|
||||
set_menu_sub(menu,subwindow);
|
||||
|
||||
@@ -52,13 +67,22 @@ int main() {
|
||||
menu_driver(menu,REQ_RIGHT_ITEM);
|
||||
break;
|
||||
case KEY_MOUSE:
|
||||
if (getmouse(&event) == OK) {
|
||||
if (event.bstate & BUTTON1_DOUBLE_CLICKED) {
|
||||
cur_item = current_item(menu);
|
||||
curs_end(cur_item);
|
||||
return 0;
|
||||
} else {
|
||||
ungetmouse(&event);
|
||||
menu_driver(menu,c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 10:
|
||||
cur_item = current_item(menu);
|
||||
endwin();
|
||||
printf("You selected %s\n",item_name(cur_item));
|
||||
curs_end(cur_item);
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -69,3 +93,33 @@ int main() {
|
||||
|
||||
endwin();
|
||||
}
|
||||
|
||||
|
||||
int curs_init() {
|
||||
initscr();
|
||||
cbreak();
|
||||
noecho();
|
||||
curs_set(0);
|
||||
keypad(stdscr,TRUE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void color_init() {
|
||||
|
||||
if (has_colors() == FALSE) {
|
||||
endwin();
|
||||
printf("Your terminal does not support colors.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
start_color();
|
||||
|
||||
}
|
||||
|
||||
|
||||
int curs_end(ITEM* item) {
|
||||
endwin();
|
||||
printf("You selected %s\n",item_name(item));
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user