Ncurses: Difference between revisions
m A bit of explanation on curses. |
m minor link edit |
||
Line 16: | Line 16: | ||
} | } | ||
once you save the file, let's [[compile]] it: | once you save the file, let's [[compiler|compile]] it: | ||
$ gcc -Wall -lncurses -o ncurses ncurses.c | $ gcc -Wall -lncurses -o ncurses ncurses.c |
Latest revision as of 11:52, 12 March 2007
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