From da3ee678a8f4852cdf72de3cb138d1075a11bcf5 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 18 Nov 2009 19:57:50 -0500 Subject: [PATCH] up through example 4.7 --- basics/init_func_example.c | 48 +++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/basics/init_func_example.c b/basics/init_func_example.c index e01ecb3..a453f99 100644 --- a/basics/init_func_example.c +++ b/basics/init_func_example.c @@ -1,31 +1,37 @@ #include +void _do_setup(){ + initscr(); + raw(); + keypad(stdscr, TRUE); + noecho(); +} + + +void _display_and_quit(){ + refresh(); + getch(); + endwin(); +} + + int main() -{ int ch; - - initscr(); /* Start curses mode */ - raw(); /* Line buffering disabled */ - keypad(stdscr, TRUE); /* We get F1, F2 etc.. */ - noecho(); /* Don't echo() while we do getch */ - - printw("Type any character to see it in bold\n"); - ch = getch(); /* If raw() hadn't been called - * we have to press enter before it - * 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 "); +{ + int ch; + _do_setup(); + + printw("Type any character to see it in bold\n"); + ch = getch(); + if(ch == KEY_F(1)){ + printw("F1 Key pressed"); + } else { + printw("The pressed key is "); attron(A_BOLD); printw("%c", ch); attroff(A_BOLD); } - refresh(); /* Print it on to the real screen */ - getch(); /* Wait for user input */ - endwin(); /* End curses mode */ + + _display_and_quit(); return 0; }