1Curses
~~~~~~~~~~~~~~~~~~~~~
1.1 curses Package content
========================
* Curses. h
Mainly controls screen input and output, cursor operations, window creation and operations, etc.
* Panel. h
Similar to the window stack, different windows can be stored and moved.
* Menu. h
It mainly includes functions for creating menus and interacting with them, and is mainly used to accept users' choices.
* Form
Including creating forms and interacting functions, which are mainly used to accept user data input.
1.2 start using the curses package
==================================
1.2.1 curses Initialization
-------------------
* In general, you must call initscr () before other cuses functions are called ().
* The difference between stdscr and curscr lies in
* Stdscr indicates a logical screen.
* Curscr indicates a physical screen.
* The wfresh function updates the physical screen based on the differences between stdscr and curscr.
* If the program uses multiple terminals
* Use newterm () instead of initscr ()
* Every terminal that you want to interact with calls newterm () once ()
* Newterm () returns a SCREEN structure to reference a terminal.
* When receiving input and output from a terminal, you must use set_term (SCREEN) to set it to the current terminal.
1.2.2 Terminal Mode settings
-------------------
* The terminal mode is actually a series of switch attributes that directly affect how the terminal processes input and output.
* Keypad (stdscr, TRUE)
Used to control whether to convert special characters on the keyboard into the corresponding special keys in the curses package
* Nonl ()
Used to control the program to convert the Enter key to a line break
* Cbreak ()
Read all characters except DELETE or CTRL
* Noecho ()
Make the characters entered by the keyboard do not need to be displayed directly on the screen
1.2.3 Color Processing
---------------
* Use the has_colors () function to determine whether the terminal supports color.
* Use init_pair (0, COLOR_GREEN, COLOR_BLACK) to initialize the color pairing table and set the foreground color and background color of the character.
* Use attron (A_BLINK | COLOR_PAIR (2) to set how to display characters
1.2.4 use refresh and wrefresh for screen update
----------------------------------------
* Refresh is actually a macro definition of wrefresh (stdscr ).
1.2.5 Use the endwin () function to interrupt the curses Program
-------------------------------------
* Endwin () is the last function called by the program. It matches the initscr () function.
* After endwin () is executed, the cursor moves to the lower left of the screen
1.3 compile
==========
* If the program uses libraries such as panel, menu, and form, the-lcurses option must be placed after the remaining options
1.4 example
==========
#include <curses.h> static void finish(int sig); int main() { initscr(); keypad(stdscr,TRUE); nonl(); cbreak(); noecho(); if(has_colors()) { start_color(); init_pair(0,COLOR_BLACK,COLOR_BLACK); init_pair(1,COLOR_GREEN,COLOR_BLACK); init_pair(2,COLOR_RED,COLOR_BLACK); init_pair(3,COLOR_CYAN,COLOR_BLACK); init_pair(4,COLOR_WHITE,COLOR_BLACK); init_pair(5,COLOR_MAGENTA,COLOR_BLACK); init_pair(6,COLOR_BLUE,COLOR_BLACK); init_pair(7,COLOR_YELLOW,COLOR_BLACK); } attron(A_BLINK|COLOR_PAIR(2)); move(LINES/2+1,COLS-4); addstr("Eye"); refresh(); sleep(2); move(LINES/2-3,COLS/2-3); addstr("Bulls"); refresh(); sleep(2); finish(0); } static void finish(int sig) { endwin(); exit(0); }
This article is from the "dark day" blog, please be sure to keep this source http://darksun.blog.51cto.com/3874064/1281711