From Hackepedia
Revision as of 12:52, 12 March 2007 by Pbug (talk | contribs) (minor link edit)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Ncurses stands for New Curses which is provided by the GNU team. It is the GUI between console and graphical to the point where you can use a mouse on such environments as X or Windows. For the pedantic, I'm aware you can use a mouse in ncurses, such as software like gpm.

Curses where ncurses is derived from provides a terminal independent API to the termcap (truly terminal independent) functions. Any terminal that runs UNIX will be able to interpret the screen commands such as clearing a screen or moving the cursor to given x/y coordinates, except where colours come into play and the terminal is monochrome.

Let's try to make a Hello World program with ncurses. You will require gcc installed to try this, as well as an editor such as vi. Create a file called ncurses.c and enter the following into it:

#include <ncurses.h>
int main()
initscr();			/* Start curses mode 		  */
printw("Hello World");	/* Print Hello World		  */
refresh();			/* Print it on to the real screen */
getch();			/* Wait for user input */
endwin();			/* End curses mode		  */
return 0;

once you save the file, let's compile it:

$ gcc -Wall -lncurses -o ncurses ncurses.c

-Wall will print all warnings, but you should have none. Now we will run our executable:

$ ./ncurses

You should see your screen completely get cleared (this was initscr()) and then it will print Hello World. For your next steps, check out the Manual at

$ man 3 ncurses