2
/* This is the upper layer of the splitvt terminal driver.
3
It contains the termcap stuff and the output routines that
4
actually write to the terminal.
13
/* This is a long list of termcap capabilities that can be used by splitvt */
21
static capability capabilities[] = {
23
{ "cs", NULL, 0 }, /* Scrolling regions: VITAL! */
25
{ "cm", NULL, 1 }, /* Cursor move to coordinates */
27
{ "sc", NULL, 0 }, /* Save cursor position */
29
{ "rc", NULL, 0 }, /* Restore cursor position */
31
{ "sr", NULL, 1 }, /* Reverse scroll 1 line */
33
{ "sf", "\n", 1 }, /* Forward scroll 1 line */
35
{ "UP", NULL, 0 }, /* Move cursor up n lines */
37
{ "up", NULL, 0 }, /* Move cursor up 1 line */
39
{ "DO", NULL, 0 }, /* Move cursor down n lines */
41
{ "do", NULL, 0 }, /* Move cursor down 1 line */
43
{ "RI", NULL, 0 }, /* Move cursor right n characters */
45
{ "nd", NULL, 0 }, /* Move cursor right 1 character */
47
{ "LE", NULL, 0 }, /* Move cursor left n characters */
49
{ "le", "\b", 0 }, /* Move cursor left 1 character */
51
{ "cr", "\r", 1 }, /* Carriage return */
53
{ "DC", NULL, 0 }, /* Delete n characters */
55
{ "dc", NULL, 0 }, /* Delete character */
57
{ "DL", NULL, 0 }, /* Delete n lines */
59
{ "dl", NULL, 0 }, /* Delete line */
61
{ "ce", NULL, 1 }, /* Clear to end of line */
63
{ "so", NULL, 0 }, /* Start standout text mode */
65
{ "se", NULL, 0 }, /* End standout text mode */
67
{ "us", NULL, 0 }, /* Start underline text mode */
69
{ "ue", NULL, 0 }, /* End underline text mode */
71
{ "md", NULL, 0 }, /* Start bold text mode */
73
{ "mb", NULL, 0 }, /* Start blinking text mode */
75
{ "mr", NULL, 0 }, /* Start reverse text mode */
77
{ "mh", NULL, 0 }, /* Start dim text mode */
79
{ "me", NULL, 0 }, /* Clear all text attributes */
81
{ "ZF", NULL, 0 }, /* Set wide (132 column) mode */
83
{ "IC", NULL, 0 }, /* Insert character */
87
#ifdef TERMCAP /* Termcap versions of the screen update routines */
89
/* areas and variables used to get termcap information */
92
extern char *tgetstr();
94
static char termcap_entry[2048]; /* termcap entry for the terminal */
95
static char termcap_area[2048]; /* Static buffer for capabilities */
96
static char *tp=termcap_area; /* Used in tgetent() calls */
97
static char *terminal_type; /* type of terminal */
99
char *termcap_init(termtype)
102
static char errmesg[BUFSIZ];
106
/* Determine the terminal type and get the termcap entry */
107
if ( tgetent(termcap_entry, termtype) < 1 ) {
109
"Can't find termcap entry for terminal type \"%s\"", terminal_type);
113
/* Make sure this terminal has all the required capabilities */
114
for ( i=0; capabilities[i].name; ++i ) {
115
if ( (value=tgetstr(capabilities[i].name, &tp)) == NULL ) {
116
if ( !capabilities[i].value &&
117
capabilities[i].required ) {
119
"Your terminal lacks the %s termcap capability.",
120
capabilities[i].name);
124
capabilities[i].value=value;
128
void outc(c) int c; { putchar(c); }
130
void vt_rows_cols(termtype, rows, cols)
136
if ( (*rows=tgetnum("li")) <= 0 )
140
if ( (*cols=tgetnum("co")) <= 0 )
147
if ( on && capabilities[md].value )
148
tputs(capabilities[md].value, 1, outc);
150
printf("\033[%sm", (on ? "1" : "22"));
152
void vt_underline(on)
155
if ( capabilities[on ? us : ue].value )
156
tputs(capabilities[on ? us : ue].value, 1, outc);
158
printf("\033[%sm", on ? "4" : "24");
163
if ( on && capabilities[mb].value )
164
tputs(capabilities[mb].value, 1, outc);
166
printf("\033[%sm", on ? "5" : "25");
171
if ( on && capabilities[mr].value )
172
tputs(capabilities[mr].value, 1, outc);
174
printf("\033[%sm", on ? "7" : "27");
178
if ( capabilities[me].value )
179
tputs(capabilities[me].value, 1, outc);
186
if ( on && capabilities[ZF].value )
187
tputs(capabilities[ZF].value, 1, outc);
189
printf("\033[?3%c", on ? 'h' : 'l');
193
if ( capabilities[sc].value )
194
tputs(capabilities[sc].value, 1, outc);
200
if ( capabilities[rc].value )
201
tputs(capabilities[rc].value, 1, outc);
206
char *termcap_init(termtype)
211
void vt_rows_cols(termtype, rows, cols)
217
if ( strcmp("vt100-w", termtype) == 0 )
218
{ /* vt100-wide terminal (132 columns) */
229
printf("\033[%sm", (on ? "1" : "22"));
231
void vt_underline(on)
234
printf("\033[%sm", on ? "4" : "24");
239
printf("\033[%sm", on ? "5" : "25");
244
printf("\033[%sm", on ? "7" : "27");
253
printf("\033[?3%c", on ? 'h' : 'l');
264
/* vt100 compatible versions of the screen update routines */
265
char *vt_initterm(terminal_type, rows, cols)
270
extern char *getenv();
271
static char *termtype=NULL, *error=NULL;
273
if ( (termtype=getenv("TERM")) == NULL )
274
return("Terminal type must be set to vt100");
276
if ( strncmp(termtype, "vt10x", 4) != 0 &&
277
/* A vt10x emulation detector --> */ ! vttest() )
278
return("Terminal type must be set to vt100");
280
if ( strlen(termtype) > 256 )
281
return("Terminal type too long");
283
/* Get extra (possibly) capabilities from termcap */
284
if ( (error=termcap_init(termtype)) != NULL )
287
vt_rows_cols(termtype, rows, cols);
289
strcpy(terminal_type, termtype);
296
void vt_goto(row, col)
299
printf("\033[%d;%dH", row, col);
304
printf("\033[%dA", numrows);
306
void vt_down(numrows)
309
printf("\033[%dB", numrows);
311
void vt_right(numcols)
314
printf("\033[%dC", numcols);
316
void vt_left(numcols)
319
printf("\033[%dD", numcols);
345
void vt_delunder(num)
348
printf("\033[%dP", num);
353
printf("\033[%dM", num);
358
printf("\033[%dL", num);
360
void vt_setattr(textattr)
367
if ( textattr&UNDERLINE )
369
if ( textattr&BLINK )
371
if ( textattr&REVERSE )
377
printf("\033[%dm", color+30);
382
printf("\033[%dm", color+40);
384
void vt_altcharset(charset, type)
390
printf("\033%cA", (charset == G0 ? '(' : ')'));
393
printf("\033%cB", (charset == G0 ? '(' : ')'));
396
printf("\033%c0", (charset == G0 ? '(' : ')'));
401
void vt_setscroll(upper, lower)
404
if ( !upper && !lower ) {
407
printf("\033[%d;%dr", upper, lower);
414
void vt_keystate(application)
417
/* Set and reset the numeric keypad and arrowkeys */
419
printf("\033=\033[?1h");
421
printf("\033>\033[?1l");
423
void vt_insertchar(numcols)
425
printf("\033[%d@", numcols);