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