salem, what's the difference between C99 / C89? I thought C99 was better, and ive always written like this because that's how i learned it, i didn't realize there were other ways to write it.... also, what does -W do (it's the same as wall, right? which does.... what?). and i'm guessing ansi just compiles it according to the ANSI standards.
ANOTHER UPDATE:
recompiled, new source is below.
it almost works -- the second parameter to the menu function isn't displayed ("A:LKJF:SLKDJF:LK" or something like that in my test)........ and the arrow keys don't quite work. sometimes they move it the wrong direction, and sometimes they don't do anything. also, enter doesn't end it.
Code:
#include <ncurses.h>
#include <stdarg.h>
int wannabemenu(char* title, char* opt, ...) {
clear();
va_list argslist;
char* currentarg;
int ch;
int choices = 1;
int currchoice = 1;
move(0,0);
printw("%s\n", title);
va_start(argslist, opt);
for (currentarg = va_arg(argslist, char*); currentarg != NULL; choices ++) {
printw("%d. %s\n", choices, currentarg);
currentarg = va_arg(argslist, char*);
}
va_end(argslist);
refresh();
mvchgat(currchoice, 0, 2, A_BLINK, 0, NULL);
while ((ch = getch()) != KEY_ENTER) {
switch (ch) {
case KEY_UP:
mvchgat(currchoice, 0, 2, A_BLINK, 0, NULL);
currchoice += 1;
break;
case KEY_DOWN:
mvchgat(currchoice, 0, 2, A_BLINK, 0, NULL);
currchoice -= 1;
break;
default:
break;
}
if (currchoice > choices) {
currchoice -= 1;
}
if (currchoice < 1) {
currchoice = 1;
}
refresh();
}
return currchoice;
}
int main() {
int chosen;
initscr();
raw();
keypad(stdscr, TRUE);
noecho();
chosen = wannabemenu("PICK ONE!", "ASDL:KFJS:LDKJF", "MOOCOW", "ZOOKS?", (char*)NULL);
printw("You chose #%d.", chosen);
refresh();
getch();
endwin();
return 0;
}