1820590 Members
1898 Online
109626 Solutions
New Discussion юеВ

Re: using Curses

 
yatin
Frequent Advisor

using Curses

I want to write a very simple program using curses.Where can i find a tutorial on curses.If possible can anyone mail me a simple program
3 REPLIES 3
Nicolas Dumeige
Esteemed Contributor

Re: using Curses

Eric Raymond has written a famous tutotial :
http://web.cs.mun.ca/~rod/ncurses/ncurses.html


All different, all Unix
Mark Grant
Honored Contributor

Re: using Curses

Can't mail you a program from work but if you need to, I can mail you one from home later. However, is is actually very simple.

You just need to include the curses headers. Set up a screen with "initscr()". You probably want to follow that up with "cbreak()" and "noecho()" and you're away. By default, the window you write to is stdscr and you can start playing with all the nice little (n)curses functions. Most of which don't even take an argument so are very simple. When finished, you link your program against "curses" and, on older systems tcap/terminfo as well.

I miss curses programming as there isn't much call for it these days but it was fun. So much fun I once did a "curses.sh" providing most curses functionality for shell scripters but sadly no longer have the code :(
Never preceed any demonstration with anything more predictive than "watch this"
Nicolas Dumeige
Esteemed Contributor

Re: using Curses

If you want a dumb example :

#include

int main()
{ WINDOW *my_wins[3];
PANEL *my_panels[3];
int lines = 10, cols = 40, y = 2, x = 4, i;

initscr();
cbreak();
noecho();

/* Create windows for the panels */
my_wins[0] = newwin(lines, cols, y, x);
my_wins[1] = newwin(lines, cols, y + 1, x + 5);
my_wins[2] = newwin(lines, cols, y + 2, x + 10);

/*
* Create borders around the windows so that you can see the effect
* of panels
*/
for(i = 0; i < 3; +++i)
box(my_wins[i], 0, 0);

/* Attach a panel to each window */ /* Order is bottom up */
my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */
my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */
my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */

/* Update the stacking order. 2nd panel will be on top */
update_panels();

/* Show it on the screen */
doupdate();

getch();
endwin();
}


All different, all Unix