Introduction#
GNU ncurses is a software API for controlling the writing to the console screen on Unix, Linux, and other operating systems. The ncurses library can be used to create text-based user interfaces (TUI) on Linux or Unix-like systems.
ncurses (new curses) is a programming library that provides a series of functions to facilitate the generation of text-based user interfaces.
In fact, we are not unfamiliar with ncurses itself, as the following well-known software all use ncurses:
- vim
- emacs
- lynx
- screen
- ......
Installation and Usage#
Using Ubuntu 22.04 as an example
sudo apt-get install libncurses5-dev
After installation, we can use the following code to test if the installation was successful
#include <string.h>
#include <ncurses.h>
int main(int argc, char* argv[]) {
initscr();
raw();
noecho();
curs_set(0);
char* s = "Hello, Liu Yuhe!";
// Print the string in the center of the screen
mvprintw(LINES / 2, (COLS - strlen(s)) / 2, "%s", s);
refresh();
getch();
endwin();
return 0;
}
gcc test.c -o test -lncurses