curses_private.h revision 1.17 1 1.17 blymn /* $NetBSD: curses_private.h,v 1.17 2001/12/02 09:14:21 blymn Exp $ */
2 1.1 blymn
3 1.1 blymn /*-
4 1.1 blymn * Copyright (c) 1998-2000 Brett Lymn
5 1.1 blymn * (blymn (at) baea.com.au, brett_lymn (at) yahoo.com.au)
6 1.1 blymn * All rights reserved.
7 1.1 blymn *
8 1.1 blymn * This code has been donated to The NetBSD Foundation by the Author.
9 1.1 blymn *
10 1.1 blymn * Redistribution and use in source and binary forms, with or without
11 1.1 blymn * modification, are permitted provided that the following conditions
12 1.1 blymn * are met:
13 1.1 blymn * 1. Redistributions of source code must retain the above copyright
14 1.1 blymn * notice, this list of conditions and the following disclaimer.
15 1.1 blymn * 2. The name of the author may not be used to endorse or promote products
16 1.16 wiz * derived from this software without specific prior written permission
17 1.1 blymn *
18 1.1 blymn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 blymn * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 blymn * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 blymn * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 blymn * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.1 blymn * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1 blymn * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1 blymn * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1 blymn * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.1 blymn * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1 blymn *
29 1.1 blymn *
30 1.1 blymn */
31 1.1 blymn
32 1.17 blymn #include <termios.h>
33 1.17 blymn
34 1.1 blymn /* Private structure definitions for curses. */
35 1.1 blymn /*
36 1.1 blymn * A window an array of __LINE structures pointed to by the 'lines' pointer.
37 1.1 blymn * A line is an array of __LDATA structures pointed to by the 'line' pointer.
38 1.1 blymn *
39 1.1 blymn * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new
40 1.1 blymn * fields are added -- padding fields with *constant values* should ensure
41 1.1 blymn * that the compiler will not generate any padding when storing an array of
42 1.1 blymn * __LDATA structures. This is to enable consistent use of memcmp, and memcpy
43 1.1 blymn * for comparing and copying arrays.
44 1.1 blymn */
45 1.1 blymn
46 1.1 blymn struct __ldata {
47 1.1 blymn wchar_t ch; /* Character */
48 1.1 blymn attr_t attr; /* Attributes */
49 1.5 jdc wchar_t bch; /* Background character */
50 1.5 jdc attr_t battr; /* Background attributes */
51 1.1 blymn };
52 1.1 blymn
53 1.1 blymn #define __LDATASIZE (sizeof(__LDATA))
54 1.1 blymn
55 1.1 blymn struct __line {
56 1.1 blymn #define __ISDIRTY 0x01 /* Line is dirty. */
57 1.1 blymn #define __ISPASTEOL 0x02 /* Cursor is past end of line */
58 1.1 blymn unsigned int flags;
59 1.1 blymn unsigned int hash; /* Hash value for the line. */
60 1.1 blymn int *firstchp, *lastchp; /* First and last chngd columns ptrs */
61 1.1 blymn int firstch, lastch; /* First and last changed columns. */
62 1.1 blymn __LDATA *line; /* Pointer to the line text. */
63 1.1 blymn };
64 1.1 blymn
65 1.1 blymn struct __window { /* Window structure. */
66 1.1 blymn struct __window *nextp, *orig; /* Subwindows list and parent. */
67 1.1 blymn int begy, begx; /* Window home. */
68 1.1 blymn int cury, curx; /* Current x, y coordinates. */
69 1.1 blymn int maxy, maxx; /* Maximum values for curx, cury. */
70 1.1 blymn short ch_off; /* x offset for firstch/lastch. */
71 1.1 blymn __LINE **lines; /* Array of pointers to the lines */
72 1.1 blymn __LINE *lspace; /* line space (for cleanup) */
73 1.1 blymn __LDATA *wspace; /* window space (for cleanup) */
74 1.1 blymn
75 1.1 blymn #define __ENDLINE 0x00000001 /* End of screen. */
76 1.1 blymn #define __FLUSH 0x00000002 /* Fflush(stdout) after refresh. */
77 1.1 blymn #define __FULLWIN 0x00000004 /* Window is a screen. */
78 1.1 blymn #define __IDLINE 0x00000008 /* Insert/delete sequences. */
79 1.1 blymn #define __SCROLLWIN 0x00000010 /* Last char will scroll window. */
80 1.1 blymn #define __SCROLLOK 0x00000020 /* Scrolling ok. */
81 1.1 blymn #define __CLEAROK 0x00000040 /* Clear on next refresh. */
82 1.1 blymn #define __LEAVEOK 0x00000100 /* If cursor left */
83 1.1 blymn #define __KEYPAD 0x00010000 /* If interpreting keypad codes */
84 1.1 blymn #define __NOTIMEOUT 0x00020000 /* Wait indefinitely for func keys */
85 1.1 blymn unsigned int flags;
86 1.1 blymn int delay; /* delay for getch() */
87 1.1 blymn attr_t wattr; /* Character attributes */
88 1.5 jdc wchar_t bch; /* Background character */
89 1.2 jdc attr_t battr; /* Background attributes */
90 1.14 jdc int scr_t, scr_b; /* Scrolling region top, bottom */
91 1.1 blymn };
92 1.5 jdc
93 1.5 jdc /* Set of attributes unset by 'me' - 'mb', 'md', 'mh', 'mk', 'mp' and 'mr'. */
94 1.5 jdc #define __TERMATTR \
95 1.5 jdc (__REVERSE | __BLINK | __DIM | __BOLD | __BLANK | __PROTECT)
96 1.2 jdc
97 1.3 jdc struct __winlist {
98 1.3 jdc struct __window *winp; /* The window. */
99 1.3 jdc struct __winlist *nextp; /* Next window. */
100 1.3 jdc };
101 1.3 jdc
102 1.17 blymn struct __color {
103 1.17 blymn short num;
104 1.17 blymn short red;
105 1.17 blymn short green;
106 1.17 blymn short blue;
107 1.17 blymn int flags;
108 1.17 blymn };
109 1.17 blymn
110 1.17 blymn /* List of colour pairs */
111 1.17 blymn struct __pair {
112 1.17 blymn short fore;
113 1.17 blymn short back;
114 1.17 blymn int flags;
115 1.17 blymn };
116 1.17 blymn
117 1.17 blymn /* Maximum colours */
118 1.17 blymn #define MAX_COLORS 64
119 1.17 blymn /* Maximum colour pairs - determined by number of colour bits in attr_t */
120 1.17 blymn #define MAX_PAIRS 64 /* PAIR_NUMBER(__COLOR) + 1 */
121 1.17 blymn
122 1.17 blymn typedef struct keymap keymap_t;
123 1.17 blymn
124 1.17 blymn /* this is the encapsulation of the terminal definition, one for
125 1.17 blymn * each terminal that curses talks to.
126 1.17 blymn */
127 1.17 blymn struct __screen {
128 1.17 blymn FILE *infd, *outfd; /* input and output file descriptors */
129 1.17 blymn WINDOW *curscr; /* Current screen. */
130 1.17 blymn WINDOW *stdscr; /* Standard screen. */
131 1.17 blymn WINDOW *__virtscr; /* Virtual screen (for doupdate()). */
132 1.17 blymn int curwin; /* current window for refresh */
133 1.17 blymn short lx, ly; /* loop parameters for refresh */
134 1.17 blymn int COLS; /* Columns on the screen. */
135 1.17 blymn int LINES; /* Lines on the screen. */
136 1.17 blymn int COLORS; /* Maximum colors on the screen */
137 1.17 blymn int COLOR_PAIRS; /* Maximum color pairs on the screen */
138 1.17 blymn int My_term; /* Use Def_term regardless. */
139 1.17 blymn char GT; /* Gtty indicates tabs. */
140 1.17 blymn char NONL; /* Term can't hack LF doing a CR. */
141 1.17 blymn char UPPERCASE; /* Terminal is uppercase only. */
142 1.17 blymn
143 1.17 blymn /* BEWARE!!! The order of the following terminal capabilities */
144 1.17 blymn /* (tc_foo) is important - do not update without fixing the zap */
145 1.17 blymn /* function in setterm.c */
146 1.17 blymn char tc_am, tc_bs, tc_cc, tc_da, tc_eo, tc_hc, tc_hl, tc_in, tc_mi,
147 1.17 blymn tc_ms, tc_nc, tc_ns, tc_os, tc_ul, tc_ut, tc_xb, tc_xn, tc_xt,
148 1.17 blymn tc_xs, tc_xx;
149 1.17 blymn int flag_count;
150 1.17 blymn int tc_pa, tc_Co, tc_NC;
151 1.17 blymn int int_count;
152 1.17 blymn char *tc_AB, *tc_ac, *tc_ae, *tc_AF, *tc_AL,
153 1.17 blymn *tc_al, *tc_as, *tc_bc, *tc_bl, *tc_bt,
154 1.17 blymn *tc_cd, *tc_ce, *tc_cl, *tc_cm, *tc_cr,
155 1.17 blymn *tc_cs, *tc_dc, *tc_DL, *tc_dl, *tc_dm,
156 1.17 blymn *tc_DO, *tc_do, *tc_eA, *tc_ed, *tc_ei,
157 1.17 blymn *tc_ho, *tc_Ic, *tc_ic, *tc_im, *tc_Ip,
158 1.17 blymn *tc_ip, *tc_k0, *tc_k1, *tc_k2, *tc_k3,
159 1.17 blymn *tc_k4, *tc_k5, *tc_k6, *tc_k7, *tc_k8,
160 1.17 blymn *tc_k9, *tc_kd, *tc_ke, *tc_kh, *tc_kl,
161 1.17 blymn *tc_kr, *tc_ks, *tc_ku, *tc_LE, *tc_ll,
162 1.17 blymn *tc_ma, *tc_mb, *tc_md, *tc_me, *tc_mh,
163 1.17 blymn *tc_mk, *tc_mm, *tc_mo, *tc_mp, *tc_mr,
164 1.17 blymn *tc_nd, *tc_nl, *tc_oc, *tc_op, *tc_pc,
165 1.17 blymn *tc_rc, *tc_RI, *tc_Sb, *tc_sc, *tc_se,
166 1.17 blymn *tc_SF, *tc_Sf, *tc_sf, *tc_so, *tc_sp,
167 1.17 blymn *tc_SR, *tc_sr, *tc_ta, *tc_te, *tc_ti,
168 1.17 blymn *tc_uc, *tc_ue, *tc_UP, *tc_up, *tc_us,
169 1.17 blymn *tc_vb, *tc_ve, *tc_vi, *tc_vs;
170 1.17 blymn char CA;
171 1.17 blymn int str_count;
172 1.17 blymn chtype acs_char[NUM_ACS];
173 1.17 blymn struct __color colours[MAX_COLORS];
174 1.17 blymn struct __pair colour_pairs[MAX_PAIRS];
175 1.17 blymn attr_t nca;
176 1.17 blymn
177 1.17 blymn /* Style of colour manipulation */
178 1.17 blymn #define COLOR_NONE 0
179 1.17 blymn #define COLOR_ANSI 1 /* ANSI/DEC-style colour manipulation */
180 1.17 blymn #define COLOR_HP 2 /* HP-style colour manipulation */
181 1.17 blymn #define COLOR_TEK 3 /* Tektronix-style colour manipulation */
182 1.17 blymn #define COLOR_OTHER 4 /* None of the others but can set fore/back */
183 1.17 blymn int color_type;
184 1.17 blymn
185 1.17 blymn attr_t mask_op;
186 1.17 blymn attr_t mask_me;
187 1.17 blymn attr_t mask_ue;
188 1.17 blymn attr_t mask_se;
189 1.17 blymn struct tinfo *cursesi_genbuf;
190 1.17 blymn int old_mode; /* old cursor visibility state for terminal */
191 1.17 blymn keymap_t *base_keymap;
192 1.17 blymn int echoit;
193 1.17 blymn int pfast;
194 1.17 blymn int rawmode;
195 1.17 blymn int noqch;
196 1.17 blymn int clearok;
197 1.17 blymn int useraw;
198 1.17 blymn struct __winlist *winlistp;
199 1.17 blymn struct termios cbreakt, rawt, *curt, save_termios;
200 1.17 blymn struct termios orig_termios, baset, savedtty;
201 1.17 blymn int ovmin;
202 1.17 blymn int ovtime;
203 1.17 blymn char *stdbuf;
204 1.17 blymn unsigned int len;
205 1.17 blymn int meta_state;
206 1.17 blymn char pad_char;
207 1.17 blymn char ttytype[1024];
208 1.17 blymn int endwin;
209 1.17 blymn };
210 1.17 blymn
211 1.17 blymn
212 1.11 jdc extern char __GT; /* Gtty indicates tabs. */
213 1.11 jdc extern char __NONL; /* Term can't hack LF doing a CR. */
214 1.11 jdc extern char __UPPERCASE; /* Terminal is uppercase only. */
215 1.11 jdc extern int My_term; /* Use Def_term regardless. */
216 1.11 jdc extern const char *Def_term; /* Default terminal type. */
217 1.17 blymn extern SCREEN *_cursesi_screen; /* The current screen in use */
218 1.11 jdc
219 1.2 jdc /* Private functions. */
220 1.2 jdc #ifdef DEBUG
221 1.4 blymn void __CTRACE(const char *fmt, ...);
222 1.2 jdc #endif
223 1.17 blymn void _cursesi_free_keymap(keymap_t *map);
224 1.17 blymn int _cursesi_gettmode(SCREEN *screen);
225 1.17 blymn void _cursesi_reset_acs(SCREEN *screen);
226 1.17 blymn void _cursesi_resetterm(SCREEN *screen);
227 1.17 blymn int _cursesi_setterm(char *type, SCREEN *screen);
228 1.4 blymn int __delay(void);
229 1.4 blymn unsigned int __hash(char *s, int len);
230 1.4 blymn void __id_subwins(WINDOW *orig);
231 1.17 blymn void __init_getch(SCREEN *screen);
232 1.17 blymn void __init_acs(SCREEN *screen);
233 1.4 blymn char *__longname(char *bp, char *def); /* Original BSD version */
234 1.4 blymn int __mvcur(int ly, int lx, int y, int x, int in_refresh);
235 1.17 blymn WINDOW *__newwin(SCREEN *screen, int lines, int cols, int y, int x);
236 1.4 blymn int __nodelay(void);
237 1.4 blymn int __notimeout(void);
238 1.4 blymn char *__parse_cap(const char *, ...);
239 1.4 blymn void __restartwin(void);
240 1.4 blymn void __restore_colors(void);
241 1.6 blymn void __restore_cursor_vis(void);
242 1.6 blymn void __restore_meta_state(void);
243 1.4 blymn void __restore_termios(void);
244 1.4 blymn void __restore_stophandler(void);
245 1.4 blymn void __save_termios(void);
246 1.4 blymn void __set_color(attr_t attr);
247 1.4 blymn void __set_stophandler(void);
248 1.4 blymn void __set_subwin(WINDOW *orig, WINDOW *win);
249 1.17 blymn void __startwin(SCREEN *screen);
250 1.4 blymn void __stop_signal_handler(int signo);
251 1.4 blymn int __stopwin(void);
252 1.4 blymn void __swflags(WINDOW *win);
253 1.4 blymn int __timeout(int delay);
254 1.10 mycroft int __touchline(WINDOW *win, int y, int sx, int ex);
255 1.4 blymn int __touchwin(WINDOW *win);
256 1.4 blymn char *__tscroll(const char *cap, int n1, int n2);
257 1.7 jdc void __unsetattr(int);
258 1.4 blymn int __waddch(WINDOW *win, __LDATA *dp);
259 1.15 jdc int __wgetnstr(WINDOW *, char *, int);
260 1.2 jdc
261 1.2 jdc /* Private #defines. */
262 1.2 jdc #define min(a,b) (a < b ? a : b)
263 1.2 jdc #define max(a,b) (a > b ? a : b)
264 1.2 jdc
265 1.2 jdc /* Private externs. */
266 1.3 jdc extern int __echoit;
267 1.3 jdc extern int __endwin;
268 1.3 jdc extern int __pfast;
269 1.3 jdc extern int __rawmode;
270 1.3 jdc extern int __noqch;
271 1.3 jdc extern attr_t __nca;
272 1.11 jdc extern attr_t __mask_op, __mask_me, __mask_ue, __mask_se;
273 1.3 jdc extern struct __winlist *__winlistp;
274 1.7 jdc extern WINDOW *__virtscr;
275