NCURSES-Programming-HOWTO.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
NCURSES Programming HOWTO Pradeep Padala <[email protected]> v1.9, 2005−06−20 Revision History Revision 1.9 2005−06−20 Revised by: ppadala The license has been changed to the MIT−style license used by NCURSES. Note that the programs are also re−licensed under this. Revision 1.8 2005−06−17 Revised by: ppadala Lots of updates. Added references and perl examples. Changes to examples. Many grammatical and stylistic changes to the content. Changes to NCURSES history. Revision 1.7.1 2002−06−25 Revised by: ppadala Added a README file for building and instructions for building from source. Revision 1.7 2002−06−25 Revised by: ppadala Added "Other formats" section and made a lot of fancy changes to the programs. Inlining of programs is gone. Revision 1.6.1 2002−02−24 Revised by: ppadala Removed the old Changelog section, cleaned the makefiles Revision 1.6 2002−02−16 Revised by: ppadala Corrected a lot of spelling mistakes, added ACS variables section Revision 1.5 2002−01−05 Revised by: ppadala Changed structure to present proper TOC Revision 1.3.1 2001−07−26 Revised by: ppadala Corrected maintainers paragraph, Corrected stable release number Revision 1.3 2001−07−24 Revised by: ppadala Added copyright notices to main document (LDP license) and programs (GPL), Corrected printw_example. Revision 1.2 2001−06−05 Revised by: ppadala Incorporated ravi's changes. Mainly to introduction, menu, form, justforfun sections Revision 1.1 2001−05−22 Revised by: ppadala Added "a word about window" section, Added scanw_example. This document is intended to be an "All in One" guide for programming with ncurses and its sister libraries. We graduate from a simple "Hello World" program to more complex form manipulation. No prior experience in ncurses is assumed. Send comments to this address NCURSES Programming HOWTO Table of Contents 1. Introduction.....................................................................................................................................................1 1.1. What is NCURSES?.........................................................................................................................1 1.2. What we can do with NCURSES......................................................................................................1 1.3. Where to get it...................................................................................................................................2 1.4. Purpose/Scope of the document........................................................................................................2 1.5. About the Programs..........................................................................................................................2 1.6. Other Formats of the document........................................................................................................4 1.6.1. Readily available formats from tldp.org..................................................................................4 1.6.2. Building from source...............................................................................................................4 1.7. Credits...............................................................................................................................................5 1.8. Wish List...........................................................................................................................................5 1.9. Copyright..........................................................................................................................................5 2. Hello World !!!................................................................................................................................................7 2.1. Compiling With the NCURSES Library..........................................................................................7 2.2. Dissection..........................................................................................................................................7 2.2.1. About initscr().........................................................................................................................7 2.2.2. The mysterious refresh().........................................................................................................8 2.2.3. About endwin()........................................................................................................................8 3. The Gory Details.............................................................................................................................................9 4. Initialization...................................................................................................................................................10 4.1. Initialization functions....................................................................................................................10 4.2. raw() and cbreak()...........................................................................................................................10 4.3. echo() and noecho()........................................................................................................................10 4.4. keypad()..........................................................................................................................................10 4.5. halfdelay().......................................................................................................................................10 4.6. Miscellaneous Initialization functions............................................................................................11 4.7. An Example....................................................................................................................................11 5. A Word about Windows...............................................................................................................................12 6. Output functions...........................................................................................................................................13 6.1. addch() class of functions...............................................................................................................13 6.2. mvaddch(), waddch() and mvwaddch()..........................................................................................13 6.3. printw() class of functions..............................................................................................................14 6.3.1. printw() and mvprintw...........................................................................................................14 6.3.2. wprintw() and mvwprintw.....................................................................................................14 6.3.3. vwprintw().............................................................................................................................14 6.3.4. A Simple printw example......................................................................................................14 6.4. addstr() class of functions...............................................................................................................15 6.5. A word of caution...........................................................................................................................15 7. Input functions..............................................................................................................................................16 7.1. getch() class of functions................................................................................................................16 7.2. scanw() class of functions...............................................................................................................16 7.2.1. scanw() and mvscanw...........................................................................................................16 i NCURSES Programming HOWTO Table of Contents 7. Input functions 7.2.2. wscanw() and mvwscanw()...................................................................................................16 7.2.3. vwscanw().............................................................................................................................16 7.3. getstr() class of functions................................................................................................................16 7.4. Some examples...............................................................................................................................17 8. Attributes.......................................................................................................................................................18 8.1. The details.......................................................................................................................................19 8.2. attron() vs attrset()...........................................................................................................................19 8.3. attr_get()..........................................................................................................................................20 8.4. attr_ functions.................................................................................................................................20 8.5. wattr functions................................................................................................................................20 8.6. chgat() functions.............................................................................................................................20