screen.c revision 1.6 1 1.6 agc /* $NetBSD: screen.c,v 1.6 2003/08/07 09:28:01 agc Exp $ */
2 1.3 perry
3 1.1 cjs /*
4 1.1 cjs * Copyright (c) 1988, 1993
5 1.1 cjs * The Regents of the University of California. All rights reserved.
6 1.1 cjs *
7 1.1 cjs * Redistribution and use in source and binary forms, with or without
8 1.1 cjs * modification, are permitted provided that the following conditions
9 1.1 cjs * are met:
10 1.1 cjs * 1. Redistributions of source code must retain the above copyright
11 1.1 cjs * notice, this list of conditions and the following disclaimer.
12 1.1 cjs * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cjs * notice, this list of conditions and the following disclaimer in the
14 1.1 cjs * documentation and/or other materials provided with the distribution.
15 1.6 agc * 3. Neither the name of the University nor the names of its contributors
16 1.6 agc * may be used to endorse or promote products derived from this software
17 1.6 agc * without specific prior written permission.
18 1.6 agc *
19 1.6 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.6 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.6 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.6 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.6 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.6 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.6 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.6 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.6 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.6 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.6 agc * SUCH DAMAGE.
30 1.6 agc */
31 1.6 agc
32 1.6 agc /*
33 1.6 agc * Copyright (c) 1988 Mark Nudleman
34 1.6 agc *
35 1.6 agc * Redistribution and use in source and binary forms, with or without
36 1.6 agc * modification, are permitted provided that the following conditions
37 1.6 agc * are met:
38 1.6 agc * 1. Redistributions of source code must retain the above copyright
39 1.6 agc * notice, this list of conditions and the following disclaimer.
40 1.6 agc * 2. Redistributions in binary form must reproduce the above copyright
41 1.6 agc * notice, this list of conditions and the following disclaimer in the
42 1.6 agc * documentation and/or other materials provided with the distribution.
43 1.1 cjs * 3. All advertising materials mentioning features or use of this software
44 1.1 cjs * must display the following acknowledgement:
45 1.1 cjs * This product includes software developed by the University of
46 1.1 cjs * California, Berkeley and its contributors.
47 1.1 cjs * 4. Neither the name of the University nor the names of its contributors
48 1.1 cjs * may be used to endorse or promote products derived from this software
49 1.1 cjs * without specific prior written permission.
50 1.1 cjs *
51 1.1 cjs * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 1.1 cjs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 1.1 cjs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 1.1 cjs * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 1.1 cjs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 1.1 cjs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 1.1 cjs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 1.1 cjs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 1.1 cjs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 1.1 cjs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 1.1 cjs * SUCH DAMAGE.
62 1.1 cjs */
63 1.1 cjs
64 1.4 christos #include <sys/cdefs.h>
65 1.1 cjs #ifndef lint
66 1.4 christos #if 0
67 1.1 cjs static char sccsid[] = "@(#)screen.c 8.2 (Berkeley) 4/20/94";
68 1.4 christos #else
69 1.6 agc __RCSID("$NetBSD: screen.c,v 1.6 2003/08/07 09:28:01 agc Exp $");
70 1.4 christos #endif
71 1.1 cjs #endif /* not lint */
72 1.1 cjs
73 1.1 cjs /*
74 1.1 cjs * Routines which deal with the characteristics of the terminal.
75 1.1 cjs * Uses termcap to be as terminal-independent as possible.
76 1.1 cjs *
77 1.1 cjs * {{ Someday this should be rewritten to use curses. }}
78 1.1 cjs */
79 1.1 cjs
80 1.1 cjs #include <stdio.h>
81 1.2 cjs #include <string.h>
82 1.4 christos #include <stdlib.h>
83 1.4 christos #include <unistd.h>
84 1.4 christos
85 1.4 christos #include "less.h"
86 1.4 christos #include "extern.h"
87 1.1 cjs
88 1.1 cjs #define TERMIOS 1
89 1.1 cjs
90 1.1 cjs #if TERMIO
91 1.1 cjs #include <termio.h>
92 1.1 cjs #else
93 1.1 cjs #if TERMIOS
94 1.1 cjs #include <termios.h>
95 1.1 cjs #define TAB3 0
96 1.1 cjs #include <sys/ioctl.h>
97 1.1 cjs #else
98 1.1 cjs #include <sgtty.h>
99 1.1 cjs #endif
100 1.1 cjs #endif
101 1.4 christos #ifdef __NetBSD__
102 1.4 christos #include <termcap.h>
103 1.4 christos #endif
104 1.1 cjs
105 1.1 cjs #ifdef TIOCGWINSZ
106 1.1 cjs #include <sys/ioctl.h>
107 1.1 cjs #else
108 1.1 cjs /*
109 1.1 cjs * For the Unix PC (ATT 7300 & 3B1):
110 1.1 cjs * Since WIOCGETD is defined in sys/window.h, we can't use that to decide
111 1.1 cjs * whether to include sys/window.h. Use SIGPHONE from sys/signal.h instead.
112 1.1 cjs */
113 1.1 cjs #include <sys/signal.h>
114 1.1 cjs #ifdef SIGPHONE
115 1.1 cjs #include <sys/window.h>
116 1.1 cjs #endif
117 1.1 cjs #endif
118 1.1 cjs
119 1.1 cjs /*
120 1.1 cjs * Strings passed to tputs() to do various terminal functions.
121 1.1 cjs */
122 1.1 cjs static char
123 1.1 cjs *sc_pad, /* Pad string */
124 1.1 cjs *sc_home, /* Cursor home */
125 1.1 cjs *sc_addline, /* Add line, scroll down following lines */
126 1.1 cjs *sc_lower_left, /* Cursor to last line, first column */
127 1.1 cjs *sc_move, /* General cursor positioning */
128 1.1 cjs *sc_clear, /* Clear screen */
129 1.1 cjs *sc_eol_clear, /* Clear to end of line */
130 1.1 cjs *sc_s_in, /* Enter standout (highlighted) mode */
131 1.1 cjs *sc_s_out, /* Exit standout mode */
132 1.1 cjs *sc_u_in, /* Enter underline mode */
133 1.1 cjs *sc_u_out, /* Exit underline mode */
134 1.1 cjs *sc_b_in, /* Enter bold mode */
135 1.1 cjs *sc_b_out, /* Exit bold mode */
136 1.1 cjs *sc_backspace, /* Backspace cursor */
137 1.1 cjs *sc_init, /* Startup terminal initialization */
138 1.1 cjs *sc_deinit; /* Exit terminal de-intialization */
139 1.1 cjs
140 1.1 cjs int auto_wrap; /* Terminal does \r\n when write past margin */
141 1.1 cjs int ignaw; /* Terminal ignores \n immediately after wrap */
142 1.1 cjs /* The user's erase and line-kill chars */
143 1.1 cjs int retain_below; /* Terminal retains text below the screen */
144 1.1 cjs int erase_char, kill_char, werase_char;
145 1.1 cjs int sc_width, sc_height = -1; /* Height & width of screen */
146 1.1 cjs int sc_window = -1; /* window size for forward and backward */
147 1.1 cjs int bo_width, be_width; /* Printing width of boldface sequences */
148 1.1 cjs int ul_width, ue_width; /* Printing width of underline sequences */
149 1.1 cjs int so_width, se_width; /* Printing width of standout sequences */
150 1.1 cjs
151 1.1 cjs /*
152 1.1 cjs * These two variables are sometimes defined in,
153 1.1 cjs * and needed by, the termcap library.
154 1.1 cjs * It may be necessary on some systems to declare them extern here.
155 1.1 cjs */
156 1.1 cjs /*extern*/ short ospeed; /* Terminal output baud rate */
157 1.1 cjs /*extern*/ char PC; /* Pad character */
158 1.1 cjs
159 1.1 cjs /*
160 1.1 cjs * Change terminal to "raw mode", or restore to "normal" mode.
161 1.1 cjs * "Raw mode" means
162 1.1 cjs * 1. An outstanding read will complete on receipt of a single keystroke.
163 1.1 cjs * 2. Input is not echoed.
164 1.1 cjs * 3. On output, \n is mapped to \r\n.
165 1.1 cjs * 4. \t is NOT expanded into spaces.
166 1.1 cjs * 5. Signal-causing characters such as ctrl-C (interrupt),
167 1.1 cjs * etc. are NOT disabled.
168 1.1 cjs * It doesn't matter whether an input \n is mapped to \r, or vice versa.
169 1.1 cjs */
170 1.4 christos void
171 1.1 cjs raw_mode(on)
172 1.1 cjs int on;
173 1.1 cjs {
174 1.1 cjs #if TERMIO || TERMIOS
175 1.1 cjs
176 1.1 cjs #if TERMIO
177 1.1 cjs struct termio s;
178 1.1 cjs static struct termio save_term;
179 1.1 cjs #else
180 1.1 cjs struct termios s;
181 1.1 cjs static struct termios save_term;
182 1.1 cjs #endif
183 1.1 cjs
184 1.1 cjs if (on)
185 1.1 cjs {
186 1.1 cjs /*
187 1.1 cjs * Get terminal modes.
188 1.1 cjs */
189 1.1 cjs #if TERMIO
190 1.1 cjs (void)ioctl(2, TCGETA, &s);
191 1.1 cjs #else
192 1.1 cjs tcgetattr(2, &s);
193 1.1 cjs #endif
194 1.1 cjs
195 1.1 cjs /*
196 1.1 cjs * Save modes and set certain variables dependent on modes.
197 1.1 cjs */
198 1.1 cjs save_term = s;
199 1.1 cjs #if TERMIO
200 1.1 cjs ospeed = s.c_cflag & CBAUD;
201 1.1 cjs #else
202 1.1 cjs ospeed = cfgetospeed(&s);
203 1.1 cjs #endif
204 1.1 cjs erase_char = s.c_cc[VERASE];
205 1.1 cjs kill_char = s.c_cc[VKILL];
206 1.1 cjs werase_char = s.c_cc[VWERASE];
207 1.1 cjs
208 1.1 cjs /*
209 1.1 cjs * Set the modes to the way we want them.
210 1.1 cjs */
211 1.1 cjs s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL);
212 1.1 cjs s.c_oflag |= (OPOST|ONLCR|TAB3);
213 1.1 cjs #if TERMIO
214 1.1 cjs s.c_oflag &= ~(OCRNL|ONOCR|ONLRET);
215 1.1 cjs #endif
216 1.1 cjs s.c_cc[VMIN] = 1;
217 1.1 cjs s.c_cc[VTIME] = 0;
218 1.1 cjs } else
219 1.1 cjs {
220 1.1 cjs /*
221 1.1 cjs * Restore saved modes.
222 1.1 cjs */
223 1.1 cjs s = save_term;
224 1.1 cjs }
225 1.1 cjs #if TERMIO
226 1.1 cjs (void)ioctl(2, TCSETAW, &s);
227 1.1 cjs #else
228 1.1 cjs tcsetattr(2, TCSADRAIN, &s);
229 1.1 cjs #endif
230 1.1 cjs #else
231 1.1 cjs struct sgttyb s;
232 1.1 cjs struct ltchars l;
233 1.1 cjs static struct sgttyb save_term;
234 1.1 cjs
235 1.1 cjs if (on)
236 1.1 cjs {
237 1.1 cjs /*
238 1.1 cjs * Get terminal modes.
239 1.1 cjs */
240 1.1 cjs (void)ioctl(2, TIOCGETP, &s);
241 1.1 cjs (void)ioctl(2, TIOCGLTC, &l);
242 1.1 cjs
243 1.1 cjs /*
244 1.1 cjs * Save modes and set certain variables dependent on modes.
245 1.1 cjs */
246 1.1 cjs save_term = s;
247 1.1 cjs ospeed = s.sg_ospeed;
248 1.1 cjs erase_char = s.sg_erase;
249 1.1 cjs kill_char = s.sg_kill;
250 1.1 cjs werase_char = l.t_werasc;
251 1.1 cjs
252 1.1 cjs /*
253 1.1 cjs * Set the modes to the way we want them.
254 1.1 cjs */
255 1.1 cjs s.sg_flags |= CBREAK;
256 1.1 cjs s.sg_flags &= ~(ECHO|XTABS);
257 1.1 cjs } else
258 1.1 cjs {
259 1.1 cjs /*
260 1.1 cjs * Restore saved modes.
261 1.1 cjs */
262 1.1 cjs s = save_term;
263 1.1 cjs }
264 1.1 cjs (void)ioctl(2, TIOCSETN, &s);
265 1.1 cjs #endif
266 1.1 cjs }
267 1.1 cjs
268 1.1 cjs /*
269 1.1 cjs * Get terminal capabilities via termcap.
270 1.1 cjs */
271 1.4 christos void
272 1.1 cjs get_term()
273 1.1 cjs {
274 1.1 cjs char termbuf[2048];
275 1.1 cjs char *sp;
276 1.1 cjs char *term;
277 1.1 cjs int hard;
278 1.1 cjs #ifdef TIOCGWINSZ
279 1.1 cjs struct winsize w;
280 1.1 cjs #else
281 1.1 cjs #ifdef WIOCGETD
282 1.1 cjs struct uwdata w;
283 1.1 cjs #endif
284 1.1 cjs #endif
285 1.1 cjs static char sbuf[1024];
286 1.1 cjs
287 1.1 cjs /*
288 1.1 cjs * Find out what kind of terminal this is.
289 1.1 cjs */
290 1.1 cjs if ((term = getenv("TERM")) == NULL)
291 1.1 cjs term = "unknown";
292 1.1 cjs if (tgetent(termbuf, term) <= 0)
293 1.5 itojun (void)strlcpy(termbuf, "dumb:co#80:hc:", sizeof(termbuf));
294 1.1 cjs
295 1.1 cjs /*
296 1.1 cjs * Get size of the screen.
297 1.1 cjs */
298 1.1 cjs #ifdef TIOCGWINSZ
299 1.1 cjs if (ioctl(2, TIOCGWINSZ, &w) == 0 && w.ws_row > 0)
300 1.1 cjs sc_height = w.ws_row;
301 1.1 cjs #else
302 1.1 cjs #ifdef WIOCGETD
303 1.1 cjs if (ioctl(2, WIOCGETD, &w) == 0 && w.uw_height > 0)
304 1.1 cjs sc_height = w.uw_height/w.uw_vs;
305 1.1 cjs #endif
306 1.1 cjs #endif
307 1.1 cjs else
308 1.1 cjs sc_height = tgetnum("li");
309 1.1 cjs hard = (sc_height < 0 || tgetflag("hc"));
310 1.1 cjs if (hard) {
311 1.1 cjs /* Oh no, this is a hardcopy terminal. */
312 1.1 cjs sc_height = 24;
313 1.1 cjs }
314 1.1 cjs
315 1.1 cjs #ifdef TIOCGWINSZ
316 1.1 cjs if (ioctl(2, TIOCGWINSZ, &w) == 0 && w.ws_col > 0)
317 1.1 cjs sc_width = w.ws_col;
318 1.1 cjs else
319 1.1 cjs #ifdef WIOCGETD
320 1.1 cjs if (ioctl(2, WIOCGETD, &w) == 0 && w.uw_width > 0)
321 1.1 cjs sc_width = w.uw_width/w.uw_hs;
322 1.1 cjs else
323 1.1 cjs #endif
324 1.1 cjs #endif
325 1.1 cjs sc_width = tgetnum("co");
326 1.1 cjs if (sc_width < 0)
327 1.1 cjs sc_width = 80;
328 1.1 cjs
329 1.1 cjs auto_wrap = tgetflag("am");
330 1.1 cjs ignaw = tgetflag("xn");
331 1.1 cjs retain_below = tgetflag("db");
332 1.1 cjs
333 1.1 cjs /*
334 1.1 cjs * Assumes termcap variable "sg" is the printing width of
335 1.1 cjs * the standout sequence, the end standout sequence,
336 1.1 cjs * the underline sequence, the end underline sequence,
337 1.1 cjs * the boldface sequence, and the end boldface sequence.
338 1.1 cjs */
339 1.1 cjs if ((so_width = tgetnum("sg")) < 0)
340 1.1 cjs so_width = 0;
341 1.1 cjs be_width = bo_width = ue_width = ul_width = se_width = so_width;
342 1.1 cjs
343 1.1 cjs /*
344 1.1 cjs * Get various string-valued capabilities.
345 1.1 cjs */
346 1.1 cjs sp = sbuf;
347 1.1 cjs
348 1.1 cjs sc_pad = tgetstr("pc", &sp);
349 1.1 cjs if (sc_pad != NULL)
350 1.1 cjs PC = *sc_pad;
351 1.1 cjs
352 1.1 cjs sc_init = tgetstr("ti", &sp);
353 1.1 cjs if (sc_init == NULL)
354 1.1 cjs sc_init = "";
355 1.1 cjs
356 1.1 cjs sc_deinit= tgetstr("te", &sp);
357 1.1 cjs if (sc_deinit == NULL)
358 1.1 cjs sc_deinit = "";
359 1.1 cjs
360 1.1 cjs sc_eol_clear = tgetstr("ce", &sp);
361 1.1 cjs if (hard || sc_eol_clear == NULL || *sc_eol_clear == '\0')
362 1.1 cjs {
363 1.1 cjs sc_eol_clear = "";
364 1.1 cjs }
365 1.1 cjs
366 1.1 cjs sc_clear = tgetstr("cl", &sp);
367 1.1 cjs if (hard || sc_clear == NULL || *sc_clear == '\0')
368 1.1 cjs {
369 1.1 cjs sc_clear = "\n\n";
370 1.1 cjs }
371 1.1 cjs
372 1.1 cjs sc_move = tgetstr("cm", &sp);
373 1.1 cjs if (hard || sc_move == NULL || *sc_move == '\0')
374 1.1 cjs {
375 1.1 cjs /*
376 1.1 cjs * This is not an error here, because we don't
377 1.1 cjs * always need sc_move.
378 1.1 cjs * We need it only if we don't have home or lower-left.
379 1.1 cjs */
380 1.1 cjs sc_move = "";
381 1.1 cjs }
382 1.1 cjs
383 1.1 cjs sc_s_in = tgetstr("so", &sp);
384 1.1 cjs if (hard || sc_s_in == NULL)
385 1.1 cjs sc_s_in = "";
386 1.1 cjs
387 1.1 cjs sc_s_out = tgetstr("se", &sp);
388 1.1 cjs if (hard || sc_s_out == NULL)
389 1.1 cjs sc_s_out = "";
390 1.1 cjs
391 1.1 cjs sc_u_in = tgetstr("us", &sp);
392 1.1 cjs if (hard || sc_u_in == NULL)
393 1.1 cjs sc_u_in = sc_s_in;
394 1.1 cjs
395 1.1 cjs sc_u_out = tgetstr("ue", &sp);
396 1.1 cjs if (hard || sc_u_out == NULL)
397 1.1 cjs sc_u_out = sc_s_out;
398 1.1 cjs
399 1.1 cjs sc_b_in = tgetstr("md", &sp);
400 1.1 cjs if (hard || sc_b_in == NULL)
401 1.1 cjs {
402 1.1 cjs sc_b_in = sc_s_in;
403 1.1 cjs sc_b_out = sc_s_out;
404 1.1 cjs } else
405 1.1 cjs {
406 1.1 cjs sc_b_out = tgetstr("me", &sp);
407 1.1 cjs if (hard || sc_b_out == NULL)
408 1.1 cjs sc_b_out = "";
409 1.1 cjs }
410 1.1 cjs
411 1.1 cjs sc_home = tgetstr("ho", &sp);
412 1.1 cjs if (hard || sc_home == NULL || *sc_home == '\0')
413 1.1 cjs {
414 1.1 cjs if (*sc_move == '\0')
415 1.1 cjs {
416 1.1 cjs /*
417 1.1 cjs * This last resort for sc_home is supposed to
418 1.1 cjs * be an up-arrow suggesting moving to the
419 1.1 cjs * top of the "virtual screen". (The one in
420 1.1 cjs * your imagination as you try to use this on
421 1.1 cjs * a hard copy terminal.)
422 1.1 cjs */
423 1.1 cjs sc_home = "|\b^";
424 1.1 cjs } else
425 1.1 cjs {
426 1.1 cjs /*
427 1.1 cjs * No "home" string,
428 1.1 cjs * but we can use "move(0,0)".
429 1.1 cjs */
430 1.5 itojun (void)strlcpy(sp, tgoto(sc_move, 0, 0),
431 1.5 itojun sizeof(sbuf) - (sp - sbuf));
432 1.1 cjs sc_home = sp;
433 1.1 cjs sp += strlen(sp) + 1;
434 1.1 cjs }
435 1.1 cjs }
436 1.1 cjs
437 1.1 cjs sc_lower_left = tgetstr("ll", &sp);
438 1.1 cjs if (hard || sc_lower_left == NULL || *sc_lower_left == '\0')
439 1.1 cjs {
440 1.1 cjs if (*sc_move == '\0')
441 1.1 cjs {
442 1.1 cjs sc_lower_left = "\r";
443 1.1 cjs } else
444 1.1 cjs {
445 1.1 cjs /*
446 1.1 cjs * No "lower-left" string,
447 1.1 cjs * but we can use "move(0,last-line)".
448 1.1 cjs */
449 1.5 itojun (void)strlcpy(sp, tgoto(sc_move, 0, sc_height-1),
450 1.5 itojun sizeof(sbuf) - (sp - sbuf));
451 1.1 cjs sc_lower_left = sp;
452 1.1 cjs sp += strlen(sp) + 1;
453 1.1 cjs }
454 1.1 cjs }
455 1.1 cjs
456 1.1 cjs /*
457 1.1 cjs * To add a line at top of screen and scroll the display down,
458 1.1 cjs * we use "al" (add line) or "sr" (scroll reverse).
459 1.1 cjs */
460 1.1 cjs if ((sc_addline = tgetstr("al", &sp)) == NULL ||
461 1.1 cjs *sc_addline == '\0')
462 1.1 cjs sc_addline = tgetstr("sr", &sp);
463 1.1 cjs
464 1.1 cjs if (hard || sc_addline == NULL || *sc_addline == '\0')
465 1.1 cjs {
466 1.1 cjs sc_addline = "";
467 1.1 cjs /* Force repaint on any backward movement */
468 1.1 cjs back_scroll = 0;
469 1.1 cjs }
470 1.1 cjs
471 1.1 cjs if (tgetflag("bs"))
472 1.1 cjs sc_backspace = "\b";
473 1.1 cjs else
474 1.1 cjs {
475 1.1 cjs sc_backspace = tgetstr("bc", &sp);
476 1.1 cjs if (sc_backspace == NULL || *sc_backspace == '\0')
477 1.1 cjs sc_backspace = "\b";
478 1.1 cjs }
479 1.1 cjs }
480 1.1 cjs
481 1.1 cjs
482 1.1 cjs /*
483 1.1 cjs * Below are the functions which perform all the
484 1.1 cjs * terminal-specific screen manipulation.
485 1.1 cjs */
486 1.1 cjs
487 1.1 cjs /*
488 1.1 cjs * Initialize terminal
489 1.1 cjs */
490 1.4 christos void
491 1.1 cjs init()
492 1.1 cjs {
493 1.1 cjs tputs(sc_init, sc_height, putchr);
494 1.1 cjs }
495 1.1 cjs
496 1.1 cjs /*
497 1.1 cjs * Deinitialize terminal
498 1.1 cjs */
499 1.4 christos void
500 1.1 cjs deinit()
501 1.1 cjs {
502 1.1 cjs tputs(sc_deinit, sc_height, putchr);
503 1.1 cjs }
504 1.1 cjs
505 1.1 cjs /*
506 1.1 cjs * Home cursor (move to upper left corner of screen).
507 1.1 cjs */
508 1.4 christos void
509 1.1 cjs home()
510 1.1 cjs {
511 1.1 cjs tputs(sc_home, 1, putchr);
512 1.1 cjs }
513 1.1 cjs
514 1.1 cjs /*
515 1.1 cjs * Add a blank line (called with cursor at home).
516 1.1 cjs * Should scroll the display down.
517 1.1 cjs */
518 1.4 christos void
519 1.1 cjs add_line()
520 1.1 cjs {
521 1.1 cjs tputs(sc_addline, sc_height, putchr);
522 1.1 cjs }
523 1.1 cjs
524 1.1 cjs int short_file; /* if file less than a screen */
525 1.4 christos void
526 1.1 cjs lower_left()
527 1.1 cjs {
528 1.1 cjs if (short_file) {
529 1.1 cjs putchr('\r');
530 1.1 cjs flush();
531 1.1 cjs }
532 1.1 cjs else
533 1.1 cjs tputs(sc_lower_left, 1, putchr);
534 1.1 cjs }
535 1.1 cjs
536 1.1 cjs /*
537 1.1 cjs * Ring the terminal bell.
538 1.1 cjs */
539 1.4 christos void
540 1.1 cjs bell()
541 1.1 cjs {
542 1.1 cjs putchr('\7');
543 1.1 cjs }
544 1.1 cjs
545 1.1 cjs /*
546 1.1 cjs * Clear the screen.
547 1.1 cjs */
548 1.4 christos void
549 1.1 cjs clear()
550 1.1 cjs {
551 1.1 cjs tputs(sc_clear, sc_height, putchr);
552 1.1 cjs }
553 1.1 cjs
554 1.1 cjs /*
555 1.1 cjs * Clear from the cursor to the end of the cursor's line.
556 1.1 cjs * {{ This must not move the cursor. }}
557 1.1 cjs */
558 1.4 christos void
559 1.1 cjs clear_eol()
560 1.1 cjs {
561 1.1 cjs tputs(sc_eol_clear, 1, putchr);
562 1.1 cjs }
563 1.1 cjs
564 1.1 cjs /*
565 1.1 cjs * Begin "standout" (bold, underline, or whatever).
566 1.1 cjs */
567 1.4 christos void
568 1.1 cjs so_enter()
569 1.1 cjs {
570 1.1 cjs tputs(sc_s_in, 1, putchr);
571 1.1 cjs }
572 1.1 cjs
573 1.1 cjs /*
574 1.1 cjs * End "standout".
575 1.1 cjs */
576 1.4 christos void
577 1.1 cjs so_exit()
578 1.1 cjs {
579 1.1 cjs tputs(sc_s_out, 1, putchr);
580 1.1 cjs }
581 1.1 cjs
582 1.1 cjs /*
583 1.1 cjs * Begin "underline" (hopefully real underlining,
584 1.1 cjs * otherwise whatever the terminal provides).
585 1.1 cjs */
586 1.4 christos void
587 1.1 cjs ul_enter()
588 1.1 cjs {
589 1.1 cjs tputs(sc_u_in, 1, putchr);
590 1.1 cjs }
591 1.1 cjs
592 1.1 cjs /*
593 1.1 cjs * End "underline".
594 1.1 cjs */
595 1.4 christos void
596 1.1 cjs ul_exit()
597 1.1 cjs {
598 1.1 cjs tputs(sc_u_out, 1, putchr);
599 1.1 cjs }
600 1.1 cjs
601 1.1 cjs /*
602 1.1 cjs * Begin "bold"
603 1.1 cjs */
604 1.4 christos void
605 1.1 cjs bo_enter()
606 1.1 cjs {
607 1.1 cjs tputs(sc_b_in, 1, putchr);
608 1.1 cjs }
609 1.1 cjs
610 1.1 cjs /*
611 1.1 cjs * End "bold".
612 1.1 cjs */
613 1.4 christos void
614 1.1 cjs bo_exit()
615 1.1 cjs {
616 1.1 cjs tputs(sc_b_out, 1, putchr);
617 1.1 cjs }
618 1.1 cjs
619 1.1 cjs /*
620 1.1 cjs * Erase the character to the left of the cursor
621 1.1 cjs * and move the cursor left.
622 1.1 cjs */
623 1.4 christos void
624 1.1 cjs backspace()
625 1.1 cjs {
626 1.1 cjs /*
627 1.1 cjs * Try to erase the previous character by overstriking with a space.
628 1.1 cjs */
629 1.1 cjs tputs(sc_backspace, 1, putchr);
630 1.1 cjs putchr(' ');
631 1.1 cjs tputs(sc_backspace, 1, putchr);
632 1.1 cjs }
633 1.1 cjs
634 1.1 cjs /*
635 1.1 cjs * Output a plain backspace, without erasing the previous char.
636 1.1 cjs */
637 1.4 christos void
638 1.1 cjs putbs()
639 1.1 cjs {
640 1.1 cjs tputs(sc_backspace, 1, putchr);
641 1.1 cjs }
642