1 / 21

The Curses Library

The Curses Library. CNS 3060. Originally developed as part of BSD Unix, the curses library provides a halfway house between line oriented terminal programs and GUI applications. Most Unix systems, including OS/X now use an updated version called ncurses.

Download Presentation

The Curses Library

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Curses Library CNS 3060

  2. Originally developed as part of BSD Unix, the curses library provides a halfway house between line oriented terminal programs and GUI applications. Most Unix systems, including OS/X now use an updated version called ncurses

  3. When compiling curses programs you must #include <curses.h> compile with -lcurses option

  4. the stdscr data structure is where data is output by default. The refresh( ) function updates the screen with the data in stdscr. The default input mode is canonical. 0,0 LINES, COLUMNS

  5. When refresh( ) is called, the contents of stdscr is compared with a like data structure, curscr, which contains the current contents of the screen. Curses uses the differences between the two data structures to update the screen. 0,0 LINES, COLUMNS

  6. #include <curses.h> int main( ) { initscr( ); move(5, 15); printw(“%s”, Hello World”); refresh( ); sleep(3); endwin( ); return 0; }

  7. gcc -lcurses -o ex1 ex1.c this option is required to link in the curses library.

  8. #include <curses.h> int main( ) { initscr( ); move(5, 15); printw(“%s”, Hello World”); refresh( ); sleep(3); endwin( ); return 0; } This statement allocates storage for the curses data structures and initializes them.

  9. #include <curses.h> int main( ) { initscr( ); move(5, 15); printw(“%s”, Hello World”); refresh( ); sleep(3); endwin( ); return 0; } This statement moves the cursor to row 5, and column 15.

  10. Hello World #include <curses.h> int main( ) { initscr( ); move(5, 15); printw(“%s”, Hello World”); refresh( ); sleep(3); endwin( ); return 0; } This statement is like printf, but it writes to stdscr.

  11. Hello World Hello World #include <curses.h> int main( ) { initscr( ); move(5, 15); printw(“%s”, Hello World”); refresh( ); sleep(3); endwin( ); return 0; } This statement causes the screen to be updated with the contents of stdscr.

  12. Hello World Hello World #include <curses.h> int main( ) { initscr( ); move(5, 15); printw(“%s”, Hello World”); refresh( ); sleep(3); endwin( ); return 0; } Sleep for a little while so that you can see the output.

  13. Hello World Hello World #include <curses.h> int main( ) { initscr( ); move(5, 15); printw(“%s”, Hello World”); refresh( ); sleep(3); endwin( ); return 0; } Terminates curses.

  14. Output to the Screen int addch(const chtype char_to_add); curses has its own character type chtype, which may have more bits than a normal character. addch adds a character at the current position. It returns 0 on success and -1 on failure.

  15. Output to the Screen int addstr(const char *string_to_add); adds the given string at the current location.

  16. Clearing the Screen int clear( ); stores blanks at every screen position.

  17. Character Attributes The curses library contains a handful of standard character attributes, defines by the constants A_BLINK A_BOLD A_DIM A_REVERSE A_STANDOUT A_UNDERLINE

  18. Character Attributes int attron (chtype attribute); int attroff(chtype attribute); int standout( ); int standend( ); mcbeth.c

  19. The Keyboard int echo( ); int noecho( ); int cbreak( ); int nocbreak( ); int raw( ) int noraw( );

  20. Keyboard Input int getch( ); int getstr(char *string); int getnstr(char *string, int num_chars); * these will cause refresh( ) to be called.

  21. For an in-depth tutorial on using curses, go to http://www.linux.com/howtos/NCURSES-Programming-HOWTO/ Includes using windows, panels, menus, etc...

More Related