Skip to content

Commit

Permalink
Added 2nd example.
Browse files Browse the repository at this point in the history
  • Loading branch information
drichardson committed Apr 5, 2013
1 parent fe1527d commit 7f04ee9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ncurses/Makefile
@@ -1,8 +1,13 @@
CC=clang
CFLAGS=-Wall -Werror -g

all: hellocurses hellocurses2

hellocurses: hellocurses.o
$(CC) -l ncurses $< -o $@

hellocurses2: hellocurses2.o
$(CC) -l ncurses $< -o $@

clean:
$(RM) -f hellocurses hellocurses.o
$(RM) -f hellocurses hellocurses.o hellocurses2 hellocurses2.o
36 changes: 36 additions & 0 deletions ncurses/hellocurses2.c
@@ -0,0 +1,36 @@
#include <ncurses.h>

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. Q to quit.\n");

do {
ch = getch(); /* If raw() hadn't been called
* we have to press enter before it
* gets to the program */
clear();
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);
printw("%c", ch);
attroff(A_BOLD);
}
refresh(); /* Print it on to the real screen */
} while (ch != 'Q');

endwin(); /* End curses mode */

return 0;
}

0 comments on commit 7f04ee9

Please sign in to comment.