unstack, sort: cleanup and improvement
[minix.git] / commands / elvis / curses.h
blob84c897cf738fcb0c377c1c3d842fe14d0305bee7
1 /* curses.h */
3 /* Author:
4 * Steve Kirkendall
5 * 14407 SW Teal Blvd. #C
6 * Beaverton, OR 97005
7 * kirkenda@cs.pdx.edu
8 */
11 /* This is the header file for a small, fast, fake curses package */
13 /* termcap stuff */
14 extern char *tgoto();
15 extern char *tgetstr();
16 extern void tputs();
18 #if MSDOS
19 /* BIOS interface used instead of termcap for MS-DOS */
20 extern int vmode;
21 extern void v_up();
22 extern void v_cb();
23 extern void v_cs();
24 extern void v_ce();
25 extern void v_cl();
26 extern void v_cd();
27 extern void v_al();
28 extern void v_dl();
29 extern void v_sr();
30 extern void v_move();
31 #endif
33 /* faddch() is a function. a pointer to it is passed to tputs() */
34 extern int faddch();
36 /* data types */
37 #define WINDOW char
39 /* CONSTANTS & SYMBOLS */
40 #define TRUE 1
41 #define FALSE 0
42 #define A_NORMAL 0
43 #define A_STANDOUT 1
44 #define A_BOLD 2
45 #define A_UNDERLINE 3
46 #define A_ALTCHARSET 4
47 #define A_POPUP 5
48 #define A_VISIBLE 6
49 #define KBSIZ 4096
51 /* figure out how many function keys we need to allow. */
52 #ifndef NO_FKEY
53 # ifdef NO_SHIFT_FKEY
54 # define NFKEYS 10
55 # else
56 # ifdef NO_CTRL_FKEY
57 # define NFKEYS 20
58 # else
59 # ifdef NO_ALT_FKEY
60 # define NFKEYS 30
61 # else
62 # define NFKEYS 40
63 # endif
64 # endif
65 # endif
66 extern char *FKEY[NFKEYS]; /* :k0=:...:k9=: codes sent by function keys */
67 #endif
69 /* extern variables, defined in curses.c */
70 extern char *termtype; /* name of terminal entry */
71 extern short ospeed; /* tty speed, eg B2400 */
72 #if OSK
73 extern char PC_; /* Pad char */
74 extern char *BC; /* Backspace char string */
75 #else
76 extern char PC; /* Pad char */
77 #endif
78 extern WINDOW *stdscr; /* pointer into kbuf[] */
79 extern WINDOW kbuf[KBSIZ]; /* a very large output buffer */
80 extern int LINES; /* :li#: number of rows */
81 extern int COLS; /* :co#: number of columns */
82 extern int AM; /* :am: boolean: auto margins? */
83 extern int PT; /* :pt: boolean: physical tabs? */
84 extern char *VB; /* :vb=: visible bell */
85 extern char *UP; /* :up=: move cursor up */
86 extern char *SO; /* :so=: standout start */
87 extern char *SE; /* :se=: standout end */
88 extern char *US; /* :us=: underline start */
89 extern char *UE; /* :ue=: underline end */
90 extern char *MD; /* :md=: bold start */
91 extern char *ME; /* :me=: bold end */
92 extern char *AS; /* :as=: alternate (italic) start */
93 extern char *AE; /* :ae=: alternate (italic) end */
94 #ifndef NO_VISIBLE
95 extern char *MV; /* :mv=: "visible" selection start */
96 #endif
97 extern char *CM; /* :cm=: cursor movement */
98 extern char *CE; /* :ce=: clear to end of line */
99 extern char *CD; /* :cd=: clear to end of screen */
100 extern char *AL; /* :al=: add a line */
101 extern char *DL; /* :dl=: delete a line */
102 #if OSK
103 extern char *SR_; /* :sr=: scroll reverse */
104 #else
105 extern char *SR; /* :sr=: scroll reverse */
106 #endif
107 extern char *KS; /* :ks=: init string for cursor */
108 extern char *KE; /* :ke=: restore string for cursor */
109 extern char *KU; /* :ku=: sequence sent by up key */
110 extern char *KD; /* :kd=: sequence sent by down key */
111 extern char *KL; /* :kl=: sequence sent by left key */
112 extern char *KR; /* :kr=: sequence sent by right key */
113 extern char *PU; /* :PU=: key sequence sent by PgUp key */
114 extern char *PD; /* :PD=: key sequence sent by PgDn key */
115 extern char *HM; /* :HM=: key sequence sent by Home key */
116 extern char *EN; /* :EN=: key sequence sent by End key */
117 extern char *KI; /* :kI=: key sequence sent by Insert key */
118 extern char *IM; /* :im=: insert mode start */
119 extern char *IC; /* :ic=: insert following char */
120 extern char *EI; /* :ei=: insert mode end */
121 extern char *DC; /* :dc=: delete a character */
122 extern char *TI; /* :ti=: terminal init */ /* GB */
123 extern char *TE; /* :te=: terminal exit */ /* GB */
124 #ifndef NO_CURSORSHAPE
125 extern char *CQ; /* :cQ=: normal cursor */
126 extern char *CX; /* :cX=: cursor used for EX command/entry */
127 extern char *CV; /* :cV=: cursor used for VI command mode */
128 extern char *CI; /* :cI=: cursor used for VI input mode */
129 extern char *CR; /* :cR=: cursor used for VI replace mode */
130 #endif
131 extern char *aend; /* end an attribute -- either UE or ME */
132 extern char ERASEKEY; /* taken from the ioctl structure */
133 #ifndef NO_COLOR
134 extern char SOcolor[];
135 extern char SEcolor[];
136 extern char UScolor[];
137 extern char UEcolor[];
138 extern char MDcolor[];
139 extern char MEcolor[];
140 extern char AScolor[];
141 extern char AEcolor[];
142 # ifndef NO_POPUP
143 extern char POPUPcolor[];
144 # endif
145 # ifndef NO_VISIBLE
146 extern char VISIBLEcolor[];
147 # endif
148 extern char normalcolor[];
149 #endif /* undef NO_COLOR */
151 /* Msdos-versions may use bios; others always termcap.
152 * Will emit some 'code has no effect' warnings in unix.
155 #if MSDOS
156 extern char o_pcbios[1]; /* BAH! */
157 #define CHECKBIOS(x,y) (*o_pcbios ? (x) : (y))
158 #define VOIDBIOS(x,y) {if (*o_pcbios) {x;} else {y;}}
159 #else
160 #define CHECKBIOS(x,y) (y)
161 #define VOIDBIOS(x,y) {y;}
162 #endif
164 #ifndef NO_COLOR
165 # define setcolor(m,a) CHECKBIOS(bioscolor(m,a), ansicolor(m,a))
166 # define fixcolor() VOIDBIOS(;, tputs(normalcolor, 1, faddch))
167 # define quitcolor() CHECKBIOS(biosquit(), ansiquit())
168 # define do_SO() VOIDBIOS((vmode=A_STANDOUT), tputs(SOcolor, 1, faddch))
169 # define do_SE() VOIDBIOS((vmode=A_NORMAL), tputs(SEcolor, 1, faddch))
170 # define do_US() VOIDBIOS((vmode=A_UNDERLINE), tputs(UScolor, 1, faddch))
171 # define do_UE() VOIDBIOS((vmode=A_NORMAL), tputs(UEcolor, 1, faddch))
172 # define do_MD() VOIDBIOS((vmode=A_BOLD), tputs(MDcolor, 1, faddch))
173 # define do_ME() VOIDBIOS((vmode=A_NORMAL), tputs(MEcolor, 1, faddch))
174 # define do_AS() VOIDBIOS((vmode=A_ALTCHARSET), tputs(AScolor, 1, faddch))
175 # define do_AE() VOIDBIOS((vmode=A_NORMAL), tputs(AEcolor, 1, faddch))
176 # define do_POPUP() VOIDBIOS((vmode=A_POPUP), tputs(POPUPcolor, 1, faddch))
177 # define do_VISIBLE() VOIDBIOS((vmode=A_VISIBLE), tputs(VISIBLEcolor, 1, faddch))
178 #else
179 # define do_SO() VOIDBIOS((vmode=A_STANDOUT), tputs(SO, 1, faddch))
180 # define do_SE() VOIDBIOS((vmode=A_NORMAL), tputs(SE, 1, faddch))
181 # define do_US() VOIDBIOS((vmode=A_UNDERLINE), tputs(US, 1, faddch))
182 # define do_UE() VOIDBIOS((vmode=A_NORMAL), tputs(UE, 1, faddch))
183 # define do_MD() VOIDBIOS((vmode=A_BOLD), tputs(MD, 1, faddch))
184 # define do_ME() VOIDBIOS((vmode=A_NORMAL), tputs(ME, 1, faddch))
185 # define do_AS() VOIDBIOS((vmode=A_ALTCHARSET), tputs(AS, 1, faddch))
186 # define do_AE() VOIDBIOS((vmode=A_NORMAL), tputs(AE, 1, faddch))
187 # define do_POPUP() VOIDBIOS((vmode=A_POPUP), tputs(SO, 1, faddch))
188 # define do_VISIBLE() VOIDBIOS((vmode=A_VISIBLE), tputs(MV, 1, faddch))
189 #endif
191 #define do_VB() VOIDBIOS(;, tputs(VB, 1, faddch))
192 #define do_UP() VOIDBIOS(v_up(), tputs(UP, 1, faddch))
193 #undef do_CM /* move */
194 #define do_CE() VOIDBIOS(v_ce(), tputs(CE, 1, faddch))
195 #define do_CD() VOIDBIOS(v_cd(), tputs(CD, 1, faddch))
196 #define do_AL() VOIDBIOS(v_al(), tputs(AL, LINES, faddch))
197 #define do_DL() VOIDBIOS(v_dl(), tputs(DL, LINES, faddch))
198 #if OSK
199 #define do_SR() VOIDBIOS(v_sr(), tputs(SR_, 1, faddch))
200 #else
201 #define do_SR() VOIDBIOS(v_sr(), tputs(SR, 1, faddch))
202 #endif
203 #define do_KS() VOIDBIOS(1, tputs(KS, 1, faddch))
204 #define do_KE() VOIDBIOS(1, tputs(KE, 1, faddch))
205 #define do_IM() VOIDBIOS(;, tputs(IM, 1, faddch))
206 #define do_IC() VOIDBIOS(;, tputs(IC, 1, faddch))
207 #define do_EI() VOIDBIOS(;, tputs(EI, 1, faddch))
208 #define do_DC() VOIDBIOS(;, tputs(DC, COLS, faddch))
209 #define do_TI() VOIDBIOS(;, (void)ttywrite(TI, (unsigned)strlen(TI)))
210 #define do_TE() VOIDBIOS(;, (void)ttywrite(TE, (unsigned)strlen(TE)))
211 #ifndef NO_CURSORSHAPE
212 # define do_CQ() VOIDBIOS(v_cs(), tputs(CQ, 1, faddch))
213 # define do_CX() VOIDBIOS(v_cs(), tputs(CX, 1, faddch))
214 # define do_CV() VOIDBIOS(v_cs(), tputs(CV, 1, faddch))
215 # define do_CI() VOIDBIOS(v_cb(), tputs(CI, 1, faddch))
216 # define do_CR() VOIDBIOS(v_cb(), tputs(CR, 1, faddch))
217 #endif
218 #ifndef NO_COLOR
219 # define do_aend() VOIDBIOS((vmode=A_NORMAL), endcolor())
220 #else
221 # define do_aend() VOIDBIOS((vmode=A_NORMAL), tputs(aend, 1, faddch))
222 #endif
224 #define has_AM CHECKBIOS(1, AM)
225 #define has_PT CHECKBIOS(0, PT)
226 #define has_VB CHECKBIOS((char *)0, VB)
227 #define has_UP CHECKBIOS((char *)1, UP)
228 #define has_SO CHECKBIOS((char)1, (*SO))
229 #define has_SE CHECKBIOS((char)1, (*SE))
230 #define has_US CHECKBIOS((char)1, (*US))
231 #define has_UE CHECKBIOS((char)1, (*UE))
232 #define has_MD CHECKBIOS((char)1, (*MD))
233 #define has_ME CHECKBIOS((char)1, (*ME))
234 #define has_AS CHECKBIOS((char)1, (*AS))
235 #define has_AE CHECKBIOS((char)1, (*AE))
236 #undef has_CM /* cursor move: don't need */
237 #define has_CB CHECKBIOS(1, 0)
238 #define has_CS CHECKBIOS(1, 0)
239 #define has_CE CHECKBIOS((char *)1, CE)
240 #define has_CD CHECKBIOS((char *)1, CD)
241 #define has_AL CHECKBIOS((char *)1, AL)
242 #define has_DL CHECKBIOS((char *)1, DL)
243 #if OSK
244 #define has_SR CHECKBIOS((char *)1, SR_)
245 #else
246 #define has_SR CHECKBIOS((char *)1, SR)
247 #endif
248 #define has_KS CHECKBIOS((char)1, (*KS))
249 #define has_KE CHECKBIOS((char)1, (*KE))
250 #define has_KU KU
251 #define has_KD KD
252 #define has_KL KL
253 #define has_KR KR
254 #define has_HM HM
255 #define has_EN EN
256 #define has_PU PU
257 #define has_PD PD
258 #define has_KI KI
259 #define has_IM CHECKBIOS((char)0, (*IM))
260 #define has_IC CHECKBIOS((char)0, (*IC))
261 #define has_EI CHECKBIOS((char)0, (*EI))
262 #define has_DC CHECKBIOS((char *)0, DC)
263 #define has_TI CHECKBIOS((char)0, (*TI))
264 #define has_TE CHECKBIOS((char)0, (*TE))
265 #ifndef NO_CURSORSHAPE
266 #define has_CQ CHECKBIOS((char *)1, CQ)
267 #endif
269 /* (pseudo)-Curses-functions */
271 #ifdef lint
272 # define _addCR VOIDBIOS(;, (stdscr[-1] == '\n' ? qaddch('\r') : (stdscr[-1] = '\n')))
273 #else
274 # if OSK
275 # define _addCR VOIDBIOS(;, (stdscr[-1] == '\n' ? qaddch('\l') : (stdscr[-1] = stdscr[-1])))
276 # else
277 # define _addCR VOIDBIOS(;, (stdscr[-1] == '\n' ? qaddch('\r') : 0))
278 # endif
279 #endif
281 #ifdef AZTEC_C
282 # define qaddch(ch) CHECKBIOS(v_put(ch), (*stdscr = (ch), *stdscr++))
283 #else
284 #define qaddch(ch) CHECKBIOS(v_put(ch), (*stdscr++ = (ch)))
285 #endif
287 #if OSK
288 #define addch(ch) if (qaddch(ch) == '\n') qaddch('\l'); else
289 #else
290 #define addch(ch) if (qaddch(ch) == '\n') qaddch('\r'); else
291 #endif
293 extern void initscr();
294 extern void endwin();
295 extern void suspend_curses();
296 extern void resume_curses();
297 extern void attrset();
298 extern void insch();
299 extern void qaddstr();
300 extern void wrefresh();
301 extern void wqrefresh();
302 #define addstr(str) {qaddstr(str); _addCR;}
303 #define move(y,x) VOIDBIOS(v_move(x,y), tputs(tgoto(CM, x, y), 1, faddch))
304 #define mvaddch(y,x,ch) {move(y,x); addch(ch);}
305 #define refresh() VOIDBIOS(;, wrefresh())
306 #define standout() do_SO()
307 #define standend() do_SE()
308 #define clrtoeol() do_CE()
309 #define clrtobot() do_CD()
310 #define insertln() do_AL()
311 #define deleteln() do_DL()
312 #define delch() do_DC()
313 #define scrollok(w,b)
314 #define raw()
315 #define echo()
316 #define cbreak()
317 #define noraw()
318 #define noecho()
319 #define nocbreak()