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