aboutsummaryrefslogtreecommitdiffstats
path: root/ncurses.c
blob: ad7dced44e7de7ce9d8dfd7e440858a86e2b28f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#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\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 ");
        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          */

    return 0;
}