They can conquer who believe they can .--Virgil |
CursesIs a UNIX-like systemTerminal control libraryUsed to build the application of the text User Interface [text User Interface (tui )]Program. The name is derived from pun on [cursor optimization ]. It is used to manage applications that use character terminals (character-cell terminals) as interfaces, such as VT100.
Curses-based softwareTypes of Software generally implement the curses library or its compatible Library (such as the ncurses library ). The curses library is mainly used to create "Graphical" applications on character devices, such as common SSH and Telnet clients. When using some programs, the simulated GUI is displayed as a character.
Curses are usually used in Unix-like systems, but they are also implemented in windows.ConioLibrary to complete similar tasks.
This function is usually implemented by using the conio library on windows. You need to replace it with the curses library when porting it to Linux. Add [-Lcurses] Parameters.
$ GCC test. C-lcurses Test. C: 2: 27: Error: Curses. h: the file or directory does not exist. |
This error occurs because the corresponding curses library is not installed. In ubuntu, you can use the following statement to install the curses library.
$ Sudo apt-Get install libncurses5-dev |
For example, the following program reads user-input characters from the command line and determines whether the character is Q
"★
/* Turbo C version */# include <stdio. h> # include <conio. h> intmain (void) {char C; while (C = getch ())! = 'Q') {printf ("You have enter % C \ n", c );}}
To run the preceding program on Linux, you must use the functions provided by the curses library.
"★
/* Use the cursee library to obtain characters from the client */# include <stdio. h> # include <curses. h> intmain (void) {char C; int ROW = 0; int Col = 0; initscr (); While (C = getch ())! = 'Q') {// move the cursor to the row, Col column move (row ++, col); // call the delch () insch () function, use C to replace the current character delch (); insch (c) ;}endwin (); Return 0 ;}
Note that when using the curses library function, you must first use the initscr () function to initialize the window. At the end of the program, call endwin () to return to the console and exit.
"★
/* cursee library template */# include
# include
intmain (void ){... initscr ();... endwin ();... return 0 ;}