|
|
|
#include <ncurses.h>
|
|
|
|
#include <menu.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
int curs_init();
|
|
|
|
void color_init();
|
|
|
|
int curs_end(ITEM* item);
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
ITEM* items[] = {
|
|
|
|
new_item("File",""),
|
|
|
|
new_item("Edit",""),
|
|
|
|
new_item("Compile",""),
|
|
|
|
new_item("Help",""),
|
|
|
|
new_item("Quit",""),
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
MENU* menu = new_menu(items);
|
|
|
|
|
|
|
|
set_menu_win(menu,stdscr);
|
|
|
|
|
|
|
|
int maxx;
|
|
|
|
int maxy;
|
|
|
|
|
|
|
|
getmaxyx(stdscr,maxy,maxx);
|
|
|
|
|
|
|
|
WINDOW* subwindow = derwin(stdscr,1,maxx-1,0,0);
|
|
|
|
|
|
|
|
wbkgd(subwindow,COLOR_PAIR(1));
|
|
|
|
|
|
|
|
keypad(subwindow,TRUE);
|
|
|
|
|
|
|
|
set_menu_sub(menu,subwindow);
|
|
|
|
|
|
|
|
set_menu_format(menu,1,maxx);
|
|
|
|
set_menu_mark(menu,"");
|
|
|
|
|
|
|
|
post_menu(menu);
|
|
|
|
refresh();
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
c = getch();
|
|
|
|
|
|
|
|
switch(c) {
|
|
|
|
case KEY_LEFT:
|
|
|
|
menu_driver(menu,REQ_LEFT_ITEM);
|
|
|
|
break;
|
|
|
|
case KEY_RIGHT:
|
|
|
|
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);
|
|
|
|
curs_end(cur_item);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|