up through example 4.7

This commit is contained in:
Dan Buch 2009-11-18 19:57:50 -05:00
parent b45b438a4f
commit da3ee678a8

View File

@ -1,31 +1,37 @@
#include <ncurses.h> #include <ncurses.h>
int main() void _do_setup(){
{ int ch; initscr();
raw();
keypad(stdscr, TRUE);
noecho();
}
initscr(); /* Start curses mode */
raw(); /* Line buffering disabled */ void _display_and_quit(){
keypad(stdscr, TRUE); /* We get F1, F2 etc.. */ refresh();
noecho(); /* Don't echo() while we do getch */ getch();
endwin();
}
int main()
{
int ch;
_do_setup();
printw("Type any character to see it in bold\n"); printw("Type any character to see it in bold\n");
ch = getch(); /* If raw() hadn't been called ch = getch();
* we have to press enter before it if(ch == KEY_F(1)){
* gets to the program */ printw("F1 Key pressed");
if(ch == KEY_F(1)) /* Without keypad enabled this will */ } else {
printw("F1 Key pressed");/* not get to us either */ printw("The pressed key is ");
/* 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;
} }