up through example 4.7

cat-town
Dan Buch 15 years ago
parent b45b438a4f
commit da3ee678a8

@ -1,31 +1,37 @@
#include <ncurses.h> #include <ncurses.h>
void _do_setup(){
initscr();
raw();
keypad(stdscr, TRUE);
noecho();
}
void _display_and_quit(){
refresh();
getch();
endwin();
}
int main() int main()
{ int ch; {
int ch;
initscr(); /* Start curses mode */ _do_setup();
raw(); /* Line buffering disabled */
keypad(stdscr, TRUE); /* We get F1, F2 etc.. */ printw("Type any character to see it in bold\n");
noecho(); /* Don't echo() while we do getch */ ch = getch();
if(ch == KEY_F(1)){
printw("Type any character to see it in bold\n"); printw("F1 Key pressed");
ch = getch(); /* If raw() hadn't been called } else {
* we have to press enter before it printw("The pressed key is ");
* gets to the program */
if(ch == KEY_F(1)) /* Without keypad enabled this will */
printw("F1 Key pressed");/* not get to us either */
/* Without noecho() some ugly escape
* charachters might have been printed
* on screen */
else
{ printw("The pressed key is ");
attron(A_BOLD); attron(A_BOLD);
printw("%c", ch); printw("%c", ch);
attroff(A_BOLD); attroff(A_BOLD);
} }
refresh(); /* Print it on to the real screen */
getch(); /* Wait for user input */ _display_and_quit();
endwin(); /* End curses mode */
return 0; return 0;
} }

Loading…
Cancel
Save