xref: /csrg-svn/lib/libcurses/curses.h (revision 2244)
1*2244Sarnold /* 01/26/81 (Berkeley) @(#)curses.h	1.1 */
2*2244Sarnold 
3*2244Sarnold # include	<stdio.h>
4*2244Sarnold 
5*2244Sarnold # include	<sgtty.h>
6*2244Sarnold 
7*2244Sarnold # define	bool	char		/* boolean variable		*/
8*2244Sarnold # define	reg	register	/* register varaible abbr.	*/
9*2244Sarnold 
10*2244Sarnold # define	TRUE	(1)
11*2244Sarnold # define	FALSE	(0)
12*2244Sarnold # define	ERR	(0)		/* default return on error	*/
13*2244Sarnold # define	OK	(1)		/* default return on good run	*/
14*2244Sarnold 
15*2244Sarnold # define	_SUBWIN		01	/* window is a subindow		*/
16*2244Sarnold # define	_ENDLINE	02	/* lines go to end of screen	*/
17*2244Sarnold # define	_FULLWIN	04	/* window is entire screen	*/
18*2244Sarnold # define	_SCROLLWIN	010	/* window could cause scroll	*/
19*2244Sarnold # define	_FLUSH		020	/* flush after refresh		*/
20*2244Sarnold # define	_STANDOUT	0200	/* standout mode in effect	*/
21*2244Sarnold # define	_NOCHANGE	-1	/* no change on this line	*/
22*2244Sarnold 
23*2244Sarnold # define	_puts(s)	tputs(s, 0, _putchar);
24*2244Sarnold 
25*2244Sarnold typedef	struct sgttyb	SGTTY;
26*2244Sarnold 
27*2244Sarnold # ifndef WINDOW
28*2244Sarnold 
29*2244Sarnold /* Copyright (c) 1979 Regents of the University of California */
30*2244Sarnold /*
31*2244Sarnold  * Capabilities from termcap
32*2244Sarnold  */
33*2244Sarnold 
34*2244Sarnold char	*AL;			/* P* Add new blank line		*/
35*2244Sarnold bool	AM;			/*    Automatic margins			*/
36*2244Sarnold char	*BC;			/*    Back cursor			*/
37*2244Sarnold bool	BS;			/*    Backspace works			*/
38*2244Sarnold char	*BT;			/* P  Back tab				*/
39*2244Sarnold bool	CA;			/*    Cursor addressible		*/
40*2244Sarnold char	*CD;			/* P* Clear to end of display		*/
41*2244Sarnold char	*CE;			/* P  Clear to end of line		*/
42*2244Sarnold char	*CL;			/* P* Clear screen			*/
43*2244Sarnold char	*CM;			/* P  Cursor motion			*/
44*2244Sarnold bool	DA;			/*    Display may be retained above	*/
45*2244Sarnold bool	DB;			/*    Display may be retained below	*/
46*2244Sarnold char	*DC;			/* P* Delete character			*/
47*2244Sarnold char	*DL;			/* P* Delete line sequence		*/
48*2244Sarnold char	*DM;			/*    Delete mode (enter)		*/
49*2244Sarnold char	*DO;			/*    Down line sequence		*/
50*2244Sarnold char	*ED;			/*    End delete mode			*/
51*2244Sarnold bool	EO;			/*    Can erase overstrikes with ' '	*/
52*2244Sarnold char	*EI;			/*    End insert mode			*/
53*2244Sarnold bool	GT;			/*    Gtty indicates tabs		*/
54*2244Sarnold char	*HO;			/*    Home cursor			*/
55*2244Sarnold bool	HZ;			/*    Hazeltine ~ braindamage		*/
56*2244Sarnold char	*IC;			/* P  Insert character			*/
57*2244Sarnold bool	IN;			/*    Insert-null blessing		*/
58*2244Sarnold char	*IM;			/*    Insrt mode (as ':im=:' if 'ic')	*/
59*2244Sarnold char	*IP;			/* P* pad after char ins'd using IM+IE	*/
60*2244Sarnold char	*LL;			/*    Quick to last line, column 0	*/
61*2244Sarnold char	*MA;			/*    Ctrl character map for cmd mode	*/
62*2244Sarnold bool	MI;			/*    can Move in Insert mode		*/
63*2244Sarnold bool	MS;			/*    can Move in Standout mode		*/
64*2244Sarnold bool	NC;			/*    No Cr: \r sends \r\n then eats \n	*/
65*2244Sarnold char	*ND;			/*    Non-destructive space		*/
66*2244Sarnold bool	OS;			/*    Overstrike works			*/
67*2244Sarnold char	PC;			/*    Pad character			*/
68*2244Sarnold char	*SE;			/*    Standout end (may leave space)	*/
69*2244Sarnold char	*SF;			/* P  Scroll forwards			*/
70*2244Sarnold char	*SO;			/*    Stand out begin (may leave space)	*/
71*2244Sarnold char	*SR;			/* P  Scroll backwards			*/
72*2244Sarnold char	*TA;			/* P  Tab (not ^I or with padding)	*/
73*2244Sarnold char	*TE;			/*    End sequence after TI		*/
74*2244Sarnold char	*TI;			/*    Terminal Initialize		*/
75*2244Sarnold char	*UC;			/*    Underline a single Character	*/
76*2244Sarnold char	*UE;			/*    Underline End sequence		*/
77*2244Sarnold bool	UL;			/*    Underlining works even though !os	*/
78*2244Sarnold char	*UP;			/*    Upline				*/
79*2244Sarnold char	*US;			/*    Underline Start sequence		*/
80*2244Sarnold char	*VB;			/*    Visible bell			*/
81*2244Sarnold char	*VE;			/*    Visual end sequence		*/
82*2244Sarnold char	*VS;			/*    Visual start sequence		*/
83*2244Sarnold bool	XN;			/*    A newline gets eaten after wrap	*/
84*2244Sarnold 	/* X? is reserved for severely nauseous glitches		*/
85*2244Sarnold 	/* If there are enough of these we may need bit masks!		*/
86*2244Sarnold 
87*2244Sarnold /*
88*2244Sarnold  * From the tty modes...
89*2244Sarnold  */
90*2244Sarnold bool	NONL;			/* Term can't hack linefeeds doing a CR	*/
91*2244Sarnold bool	UPPERCASE;		/* Ick!					*/
92*2244Sarnold 
93*2244Sarnold bool	normtty;		/* set if must normal mode from normf	*/
94*2244Sarnold bool	_pfast;			/* Have stty -nl'ed to go faster	*/
95*2244Sarnold 
96*2244Sarnold # define	WINDOW	struct _win_st
97*2244Sarnold 
98*2244Sarnold struct _win_st {		/* window description structure		*/
99*2244Sarnold 	short	_cury, _curx;		/* current y,x positions	*/
100*2244Sarnold 	short	_maxy, _maxx;		/* maximum y,x positions	*/
101*2244Sarnold 	short	_begy, _begx;		/* start y,x positions		*/
102*2244Sarnold 	short	_flags;			/* various window flags		*/
103*2244Sarnold 	bool	_clear;			/* need to clear		*/
104*2244Sarnold 	bool	_leave;			/* leave curx,y at last update	*/
105*2244Sarnold 	bool	_scroll;		/* scrolls allowed		*/
106*2244Sarnold 	char	**_y;			/* actual window		*/
107*2244Sarnold 	short	*_firstch;		/* first change on line		*/
108*2244Sarnold 	short	*_lastch;		/* last change on line		*/
109*2244Sarnold };
110*2244Sarnold 
111*2244Sarnold extern bool	My_term,	/* set if user species terminal		*/
112*2244Sarnold 		_echoit,	/* set if echoing characters		*/
113*2244Sarnold 		_rawmode,	/* set if terminal in raw mode		*/
114*2244Sarnold 		_endwin;	/* endwin has been called		*/
115*2244Sarnold 
116*2244Sarnold extern char	*Def_term,	/* default terminal type		*/
117*2244Sarnold 		ttytype[];	/* long name of current terminal	*/
118*2244Sarnold 
119*2244Sarnold extern int	LINES, COLS,	/* number of lines and columns		*/
120*2244Sarnold 		_tty_ch,	/* channel with tty on it		*/
121*2244Sarnold 		_res_flg;	/* sgtty flags stored for reset		*/
122*2244Sarnold 
123*2244Sarnold # ifdef DEBUG
124*2244Sarnold FILE		*outf;		/* error outfile			*/
125*2244Sarnold # endif
126*2244Sarnold 
127*2244Sarnold SGTTY		_tty;		/* tty structure			*/
128*2244Sarnold 
129*2244Sarnold WINDOW		*stdscr,	/* standard screen			*/
130*2244Sarnold 		*curscr;	/* current screen			*/
131*2244Sarnold 
132*2244Sarnold /*
133*2244Sarnold  *	Define VOID to stop lint from generating "null effect"
134*2244Sarnold  * comments.
135*2244Sarnold  */
136*2244Sarnold # ifdef lint
137*2244Sarnold int	__void__;		/* place to assign to			*/
138*2244Sarnold # define	VOID(x)	(__void__ = (int) (x))
139*2244Sarnold # else
140*2244Sarnold # define	VOID(x)	(x)
141*2244Sarnold # endif
142*2244Sarnold 
143*2244Sarnold # endif
144*2244Sarnold 
145*2244Sarnold /*
146*2244Sarnold  * psuedo functions for standard screen
147*2244Sarnold  */
148*2244Sarnold # define	addch(ch)	VOID(waddch(stdscr, ch))
149*2244Sarnold # define	getch()		VOID(wgetch(stdscr))
150*2244Sarnold # define	addstr(str)	VOID(waddstr(stdscr, str))
151*2244Sarnold # define	getstr(str)	VOID(wgetstr(stdscr, str))
152*2244Sarnold # define	move(y, x)	VOID(wmove(stdscr, y, x))
153*2244Sarnold # define	clear()		VOID(wclear(stdscr))
154*2244Sarnold # define	erase()		VOID(werase(stdscr))
155*2244Sarnold # define	clrtobot()	VOID(wclrtobot(stdscr))
156*2244Sarnold # define	clrtoeol()	VOID(wclrtoeol(stdscr))
157*2244Sarnold # define	insertln()	VOID(winsertln(stdscr))
158*2244Sarnold # define	deleteln()	VOID(wdeleteln(stdscr))
159*2244Sarnold # define	refresh()	VOID(wrefresh(stdscr))
160*2244Sarnold # define	inch()		VOID(winch(stdscr))
161*2244Sarnold # define	standout()	VOID(wstandout(stdscr))
162*2244Sarnold # define	standend()	VOID(wstandend(stdscr))
163*2244Sarnold 
164*2244Sarnold /*
165*2244Sarnold  * mv functions
166*2244Sarnold  */
167*2244Sarnold #define	mvwaddch(win,y,x,ch)	VOID(wmove(win,y,x)==ERR?ERR:waddch(win,ch))
168*2244Sarnold #define	mvwgetch(win,y,x)	VOID(wmove(win,y,x)==ERR?ERR:wgetch(win))
169*2244Sarnold #define	mvwaddstr(win,y,x,str)	VOID(wmove(win,y,x)==ERR?ERR:waddstr(win,str))
170*2244Sarnold #define	mvwgetstr(win,y,x)	VOID(wmove(win,y,x)==ERR?ERR:wgetstr(win))
171*2244Sarnold #define	mvwinch(win,y,x)	VOID(wmove(win,y,x) == ERR ? ERR : winch(win))
172*2244Sarnold #define	mvaddch(y,x,ch)		mvwaddch(stdscr,y,x,ch)
173*2244Sarnold #define	mvgetch(y,x)		mvwgetch(stdscr,y,x)
174*2244Sarnold #define	mvaddstr(y,x,str)	mvwaddstr(stdscr,y,x,str)
175*2244Sarnold #define	mvgetstr(y,x)		mvwgetstr(stdscr,y,x)
176*2244Sarnold #define	mvinch(y,x)		mvwinch(win,y,x)
177*2244Sarnold 
178*2244Sarnold /*
179*2244Sarnold  * psuedo functions
180*2244Sarnold  */
181*2244Sarnold 
182*2244Sarnold #define	clearok(win,bf)	 (win->_clear = bf)
183*2244Sarnold #define	leaveok(win,bf)	 (win->_leave = bf)
184*2244Sarnold #define	scrollok(win,bf) (win->_scroll = bf)
185*2244Sarnold #define flushok(win,bf)	 (bf ? (win->_flags |= _FLUSH):(win->_flags &= ~_FLUSH))
186*2244Sarnold #define	getyx(win,y,x)	 y = win->_cury, x = win->_curx
187*2244Sarnold #define	winch(win)	 (win->_y[win->_cury][win->_curx])
188*2244Sarnold 
189*2244Sarnold #define raw()	 (_tty.sg_flags|=RAW, _pfast=_rawmode=TRUE, stty(_tty_ch,&_tty))
190*2244Sarnold #define noraw()	 (_tty.sg_flags&=~RAW,_rawmode=FALSE,_pfast=!(_tty.sg_flags&CRMOD),stty(_tty_ch,&_tty))
191*2244Sarnold #define crmode() (_tty.sg_flags |= CBREAK, _rawmode = TRUE, stty(_tty_ch,&_tty))
192*2244Sarnold #define nocrmode() (_tty.sg_flags &= ~CBREAK,_rawmode=FALSE,stty(_tty_ch,&_tty))
193*2244Sarnold #define echo()	 (_tty.sg_flags |= ECHO, _echoit = TRUE, stty(_tty_ch, &_tty))
194*2244Sarnold #define noecho() (_tty.sg_flags &= ~ECHO, _echoit = FALSE, stty(_tty_ch, &_tty))
195*2244Sarnold #define nl()	 (_tty.sg_flags |= CRMOD,_pfast = _rawmode,stty(_tty_ch, &_tty))
196*2244Sarnold #define nonl()	 (_tty.sg_flags &= ~CRMOD, _pfast = TRUE, stty(_tty_ch, &_tty))
197*2244Sarnold #define	savetty() (gtty(_tty_ch, &_tty), _res_flg = _tty.sg_flags)
198*2244Sarnold #define	resetty() (_tty.sg_flags = _res_flg, stty(_tty_ch, &_tty))
199*2244Sarnold 
200*2244Sarnold WINDOW	*initscr(), *newwin(), *subwin();
201