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