Source Code File 02-06_typewriter

02-06_typewriter.c

#include <ncurses.h>
   
int main()
{
    int ch;
    
    initscr();
    addstr("Type a few lines of text\n");
    addstr("Press ~ to quit\n");
    refresh();
    
    while( (ch = getch()) != '~')
        ;
    
    endwin();
    return(0);
}

Output Screenshot

Notes

* Certain keys' behavior might not be what you expect. For example, the Enter/Return key may not add a line feed. The Backspace key may be interpreted as ^? or "delete."

* A true typewriter (or text editor) program in Ncurses must interpret input before display.