Linux curses function library and curses function library

Source: Internet
Author: User

Linux curses function library and curses function library

Fedora20, install yum install ncurses-devel

Compile time:-lncurses

Header file: # include <curses. h>

Reference: man ncurses \ linux Program Design

 

I. Screen

1. Start with initscr () and end with endwin ();

WINDOW * initscr (void); // Initialization

Int endwin (void); // exit curses, Return OK/ERR

 

2. output to the screen

Int addch (const chtype ch); // add ch at the current position

Int addchstr (chtype * const str); // add str at the current position

Int printw (char * format,...); // class printf, formatted output

Int refresh (void); // refresh the physical screen. To change the logic screen, refresh the logical screen before it can be displayed on the physical screen.

Int box (WINDOW * ptr, chtype v_ch, chtype h_ch); // draw a box around the specified ptr WINDOW, vertical/horizontal direction character v_ch/h_ch

Int insch (chtype ch); // insert ch, right shift

Int insertln (void); // insert a blank row and move it down

Int delch (void); // Delete the cursor position character, move left

Int deleteln (void) // Delete the current row, move up

Int beep (void); // voice

Int flash (void); // flashing Screen

 

3. Read from the screen

Chtype inch (void); // read the cursor position character

Int instr (char * string); // read string to str, to NUL, not always supported

Int innstr (char * str, int n_of_str); // reads n characters to str, or NUL, not always supported

 

4. Clear the screen

Int erase (void); // clear the screen, filled with blank characters

Int clear (void); // clear the screen

Int clrtobot (void); // clear to the end of the screen

Int clrtoeol (void); // clear to the end of the row

 

5. move the cursor

Int move (int new_y, int new_x); // y vertical direction, x horizontal direction

Int leaveok (WINDOW * ptr, bool lf); // false. After refreshing, the hardware cursor position is the same as the logic cursor position. true. After refreshing, the hardware cursor is randomly positioned. Generally, the default options meet your needs.

 

6. character attributes

Int attron (chtype attr); // start the specified attribute (other attributes are not affected)

Int attroff (chtype attr); // close the specified attribute (other attributes are not affected)

Attrset (chtype attr); // you can specify the character attribute.

Int standout (void); // "highlight" mode, open

Int standend (void); // "highlight" mode, off

A_NORMAL

A_STANDOUT

A_UNDERLINE

A_REVERSE

Man curs_attr

 

2. keyboard

 

1. keyboard Mode

Int echo (void); // input character echo, enabled

Int noecho (void); // disable

Int cbreak (void); // In cbreak mode, the keyboard input is processed immediately and enabled; the default cooked mode is used.

Int nocbreak (void); // close

Int raw (void); // disable the special character processing function;

Int noraw (void); // disable both raw and cbreak.

 

2. keyboard input

Int getch (void );

Int getstr (char * str );

Int getnstr (char * str, int n_of_str );

Int scanw (char * format ,...);

 

3. Window

 

  

1. WINDOW structure

WINDOW * newwin (int n_of_lines, int n_of_cols, int start_y, int start_x); // create a WINDOW

Int delwin (WINDOW * ptr); // destroy the WINDOW

 

2. Common functions

Example:

Int addch (const chtype ch );

Int waddch (WINDOW * ptr, const chtype ch );

Int mvaddch (int y, int x, const chtype ch );

Int mvwaddch (WINDOW * ptr, int y, int x, const chtype ch );

Prefix w is used for window, mv is used for moving the cursor, and mvw is used to move the cursor in the window

Many other functions have similar generic functions. For more information, see man ncurses.

 

3. Move and update the window

Int mvwin (WINDOW * ptr, int new_y, int new_x );

Int wrefresh (WINDOW * ptr );

Int wclear (WINDOW * ptr );

Int werase (WINDOW * ptr );

Int touchwin (WINDOW * ptr); // notifies the curses function library. The ptr specifies that the WINDOW changes. The WINDOW needs to be re-painted next time wrefresh. Use this function to arrange the window to be displayed

Int scrolok (WINDOW * ptr, bool sf); // true, allows WINDOW scrolling. Not allowed by default

Int scroll (WINDOW * ptr); // call scrolok and then scroll to roll the WINDOW content to a row.

4. Optimized screen refresh

Int wnoutrefresh (WINDOW * ptr );

Int doupdate (void );

 

4. subwindow

WINDOW * subwin (WINDOW * parent, int n_of_lines, int n_of_cols, int start_y, int start_x );

Int delwin (WINDOW * ptr );

You must call the touchwin function for the parent window before using the child window.

 

V. keypad Mode

 

Int keypad (WINDOW * ptr, bool keypad_on );

 

Vi. Color Display

 

Bool has_colors (void); // If color is supported, true is returned. Otherwise, false is returned.

Int start_color (void); // initialize the color display function, OK/ERR

Int init_pair (short pair_number, short foreground, short background); // eg: init_pair (1, COLOR_RED, COLOR_GREEN), the red foreground green background is defined as the first color combination.

Int COLOR_PAIR (int pair_number); // eg: COLOR_PAIR (1), which is accessed as an attribute, same as A_BOLD

Int pair_content (short pair_number, short * foreground, short * background); // opposite to init_pair, the color is obtained by a combination of colors.

COLOR_BLACK red green yellow blue megenta red cyan blue-GREEN WHITE

Int init_color (short color_number, short red, short green, short blue); // use red green blue to combine colors.

  

7. pad

 

All the curses functions that execute write window operations can also be used for pad

WINDOW * newpad (int n_of_lines, int n_of_columns); // create a logical screen, which can be larger than the physical screen. Two Parameters represent the logical screen size and return a pointer to the WINDOW structure.

Int prefresh (WINDOW * pad_ptr, int pad_row, int pad_column,

Int screen_row_min, int screen_col_min, int screen_row_max, int screen_col_max );

Pad_ptr pointer, pointer returned by newpad;

Pad_row, pad_column, specifies the position on pad

Screen_row_min, screen_col_min

Screen_row_max, screen_col_max, which specifies the display area of the physical screen.

The pnoutrefresh function serves the same purpose as the wnoutrefresh function, in order to refresh the screen more effectively.

 

8. For more functions, refer to man ncurses.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.