Linux Curses function library

Source: Internet
Author: User
Tags clear screen

FEDORA20, installing yum install Ncurses-devel

Compile time:-lncurses

Header files: #include <curses.h>

Reference: Man ncurses \linux Program design

One, the screen

1, beginning with INITSCR (), to Endwin (); end

WINDOW *initscr (void); Initialization

int Endwin (void); Exit curses, return to Ok/err

2, output to screen

int addch (const chtype CH); Current position Add CH

int addchstr (chtype *const str); Current location Add str

int printw (char *format,...); Class printf, formatted output

int refresh (void); Refresh the physical screen, change the logic screen, must be refreshed to display on the physical screen

int box (WINDOW *ptr, Chtype v_ch, Chtype h_ch); Specifies the window frame around PTR, vertical/horizontal character v_ch/h_ch

int Insch (Chtype ch); Insert CH, move right

int insertln (void); Insert a blank line, move Down

int Delch (void); Remove the cursor position character, move left

int Deleteln (void)//delete current line, move up

int beep (void); Sounder

int flash (void); splash screen

3, read from screen

Chtype inch (void); Read cursor position character

int InStr (char *string); Read string to STR, to NUL, not always supported

int Innstr (char *str, int n_of_str); Read n characters to Str, or NUL, not always supported

4. Clear the screen

int erase (void); Clear screen, filled with blank characters

int clear (void); Clear Screen

int Clrtobot (void); Clear to the end of the screen

int clrtoeol (void); Clear to end of line

5, move 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 positions with the logical cursor; True, after the hardware cursor is refreshed, the random position. The general default option is in line with user requirements.

6, Character properties

int Attron (Chtype attr); Launches the specified property (does not affect the other)

int Attroff (Chtype attr); Close the specified property (without affecting the other)

Attrset (Chtype attr); Set character properties

int standout (void); "Highlight" mode, open

int standend (void); "Highlight" mode, off

A_normal

A_standout

A_underline

A_reverse

Detailed Man Curs_attr

Two, keyboard

1, keyboard mode

int echo (void); Input word echo, open

int noecho (void); Shut down

int cbreak (void); Cbreak mode, keyboard input immediately processing, open; Default cooked mode, enter post processing

int nocbreak (void); Shut down

int raw (void); Turn off the processing function of special characters, turn on;

int Noraw (void); Off, while closing raw,cbreak

2, keyboard input

int getch (void);

int Getstr (char *str);

int Getnstr (char *str, int n_of_str);

int Scanw (char *format,...);

Three, window

  

1,window structure

WINDOW *newwin (int n_of_lines, int n_of_cols, int start_y, int start_x); New Window

int Delwin (WINDOW *ptr); Destroying Windows

2, General function

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 for window, MV for cursor movement, MVW for moving cursor in window

Many other functions have similar general functions, man ncurses view

3, move and update windows

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 that the PTR specified window has changed, and the next time Wrefresh, the window needs to be redrawn. Use this function to schedule the window to be displayed

int Scrollok (WINDOW *ptr, bool SF); True to allow the window to roll the screen. Not allowed by default

int scroll (WINDOW *ptr); After calling Scrollok, call scroll again to roll up the contents of the window.

4. Optimize screen Refresh

int Wnoutrefresh (WINDOW *ptr);

int doupdate (void);

Four, child window

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

int Delwin (WINDOW *ptr);

Before using a child window, you must call the Touchwin function on its parent window

Five, keypad mode

int keypad (WINDOW *ptr, bool keypad_on);

Six, color display

BOOL Has_colors (void); Supports color display, returns TRUE, otherwise false

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), defines the red foreground green background as a color combination.

int Color_pair (int pair_number); Eg:color_pair (1), accessed as a property, with A_bold

int Pair_content (short pair_number, short *foreground, short *background); In contrast to Init_pair, color combinations are obtained by color combination numbers.

Color_black RED Green YELLOW blue Megenta magenta cyan Blue Green White

int Init_color (short color_number, short red, short green, short blue); Color combination with red green blue

  

Seven, pad

All curses functions that perform write-window operations are also available for pad

WINDOW *newpad (int n_of_lines, int n_of_columns); To create a logical screen that is larger than the physical screen, two parameters represent the logical screen size, and a pointer to the window structure is returned

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, NEWPAD returns the pointer;

Pad_row, Pad_column, specify position on pad

Screen_row_min, Screen_col_min

Screen_row_max, Screen_col_max, specifying the physical screen display area

The Pnoutrefresh function, like the Wnoutrefresh function, refreshes the screen more efficiently.

Eight, more functions reference man ncurses

Linux Curses function library

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.