2009-10-25 11:42:08 +01:00
|
|
|
/* $Id: tty-term.c,v 1.33 2009-10-25 10:42:08 tcunha Exp $ */
|
2009-01-10 00:57:42 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2009-07-14 08:47:12 +02:00
|
|
|
#include <curses.h>
|
2009-08-09 17:26:24 +02:00
|
|
|
#include <fnmatch.h>
|
|
|
|
#include <stdlib.h>
|
2009-01-10 00:57:42 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <term.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2009-08-09 17:26:24 +02:00
|
|
|
void tty_term_override(struct tty_term *, const char *);
|
2009-01-10 00:57:42 +01:00
|
|
|
char *tty_term_strip(const char *);
|
|
|
|
|
2009-01-10 02:30:38 +01:00
|
|
|
struct tty_terms tty_terms = SLIST_HEAD_INITIALIZER(tty_terms);
|
2009-01-10 00:57:42 +01:00
|
|
|
|
2009-01-10 02:30:38 +01:00
|
|
|
struct tty_term_code_entry tty_term_codes[NTTYCODE] = {
|
2009-01-10 00:57:42 +01:00
|
|
|
{ TTYC_AX, TTYCODE_FLAG, "AX" },
|
|
|
|
{ TTYC_ACSC, TTYCODE_STRING, "acsc" },
|
|
|
|
{ TTYC_BEL, TTYCODE_STRING, "bel" },
|
|
|
|
{ TTYC_BLINK, TTYCODE_STRING, "blink" },
|
|
|
|
{ TTYC_BOLD, TTYCODE_STRING, "bold" },
|
|
|
|
{ TTYC_CIVIS, TTYCODE_STRING, "civis" },
|
|
|
|
{ TTYC_CLEAR, TTYCODE_STRING, "clear" },
|
|
|
|
{ TTYC_CNORM, TTYCODE_STRING, "cnorm" },
|
|
|
|
{ TTYC_COLORS, TTYCODE_NUMBER, "colors" },
|
|
|
|
{ TTYC_CSR, TTYCODE_STRING, "csr" },
|
2009-10-15 03:33:21 +02:00
|
|
|
{ TTYC_CUB, TTYCODE_STRING, "cub" },
|
|
|
|
{ TTYC_CUB1, TTYCODE_STRING, "cub1" },
|
2009-01-10 00:57:42 +01:00
|
|
|
{ TTYC_CUD, TTYCODE_STRING, "cud" },
|
|
|
|
{ TTYC_CUD1, TTYCODE_STRING, "cud1" },
|
2009-10-15 03:33:21 +02:00
|
|
|
{ TTYC_CUF, TTYCODE_STRING, "cuf" },
|
|
|
|
{ TTYC_CUF1, TTYCODE_STRING, "cuf1" },
|
2009-01-10 00:57:42 +01:00
|
|
|
{ TTYC_CUP, TTYCODE_STRING, "cup" },
|
2009-10-15 03:33:21 +02:00
|
|
|
{ TTYC_CUU, TTYCODE_STRING, "cuu" },
|
|
|
|
{ TTYC_CUU1, TTYCODE_STRING, "cuu1" },
|
2009-01-10 00:57:42 +01:00
|
|
|
{ TTYC_DCH, TTYCODE_STRING, "dch" },
|
2009-01-10 02:30:38 +01:00
|
|
|
{ TTYC_DCH1, TTYCODE_STRING, "dch1" },
|
2009-01-10 00:57:42 +01:00
|
|
|
{ TTYC_DIM, TTYCODE_STRING, "dim" },
|
|
|
|
{ TTYC_DL, TTYCODE_STRING, "dl" },
|
|
|
|
{ TTYC_DL1, TTYCODE_STRING, "dl1" },
|
|
|
|
{ TTYC_EL, TTYCODE_STRING, "el" },
|
|
|
|
{ TTYC_EL1, TTYCODE_STRING, "el1" },
|
|
|
|
{ TTYC_ENACS, TTYCODE_STRING, "enacs" },
|
2009-10-15 03:33:21 +02:00
|
|
|
{ TTYC_HOME, TTYCODE_STRING, "home" },
|
|
|
|
{ TTYC_HPA, TTYCODE_STRING, "hpa" },
|
2009-01-10 00:57:42 +01:00
|
|
|
{ TTYC_ICH, TTYCODE_STRING, "ich" },
|
|
|
|
{ TTYC_ICH1, TTYCODE_STRING, "ich1" },
|
|
|
|
{ TTYC_IL, TTYCODE_STRING, "il" },
|
|
|
|
{ TTYC_IL1, TTYCODE_STRING, "il1" },
|
|
|
|
{ TTYC_INVIS, TTYCODE_STRING, "invis" },
|
|
|
|
{ TTYC_IS1, TTYCODE_STRING, "is1" },
|
|
|
|
{ TTYC_IS2, TTYCODE_STRING, "is2" },
|
|
|
|
{ TTYC_IS3, TTYCODE_STRING, "is3" },
|
2009-01-10 19:28:09 +01:00
|
|
|
{ TTYC_KCBT, TTYCODE_STRING, "kcbt" },
|
2009-01-10 00:57:42 +01:00
|
|
|
{ TTYC_KCUB1, TTYCODE_STRING, "kcub1" },
|
|
|
|
{ TTYC_KCUD1, TTYCODE_STRING, "kcud1" },
|
|
|
|
{ TTYC_KCUF1, TTYCODE_STRING, "kcuf1" },
|
|
|
|
{ TTYC_KCUU1, TTYCODE_STRING, "kcuu1" },
|
|
|
|
{ TTYC_KDCH1, TTYCODE_STRING, "kdch1" },
|
|
|
|
{ TTYC_KEND, TTYCODE_STRING, "kend" },
|
|
|
|
{ TTYC_KF1, TTYCODE_STRING, "kf1" },
|
|
|
|
{ TTYC_KF10, TTYCODE_STRING, "kf10" },
|
|
|
|
{ TTYC_KF11, TTYCODE_STRING, "kf11" },
|
|
|
|
{ TTYC_KF12, TTYCODE_STRING, "kf12" },
|
2009-03-02 19:05:40 +01:00
|
|
|
{ TTYC_KF13, TTYCODE_STRING, "kf13" },
|
|
|
|
{ TTYC_KF14, TTYCODE_STRING, "kf14" },
|
|
|
|
{ TTYC_KF15, TTYCODE_STRING, "kf15" },
|
|
|
|
{ TTYC_KF16, TTYCODE_STRING, "kf16" },
|
|
|
|
{ TTYC_KF17, TTYCODE_STRING, "kf17" },
|
|
|
|
{ TTYC_KF18, TTYCODE_STRING, "kf18" },
|
|
|
|
{ TTYC_KF19, TTYCODE_STRING, "kf19" },
|
2009-01-10 00:57:42 +01:00
|
|
|
{ TTYC_KF2, TTYCODE_STRING, "kf2" },
|
2009-10-15 03:33:21 +02:00
|
|
|
{ TTYC_KF20, TTYCODE_STRING, "kf20" },
|
2009-01-10 00:57:42 +01:00
|
|
|
{ TTYC_KF3, TTYCODE_STRING, "kf3" },
|
|
|
|
{ TTYC_KF4, TTYCODE_STRING, "kf4" },
|
|
|
|
{ TTYC_KF5, TTYCODE_STRING, "kf5" },
|
|
|
|
{ TTYC_KF6, TTYCODE_STRING, "kf6" },
|
|
|
|
{ TTYC_KF7, TTYCODE_STRING, "kf7" },
|
|
|
|
{ TTYC_KF8, TTYCODE_STRING, "kf8" },
|
|
|
|
{ TTYC_KF9, TTYCODE_STRING, "kf9" },
|
|
|
|
{ TTYC_KHOME, TTYCODE_STRING, "khome" },
|
|
|
|
{ TTYC_KICH1, TTYCODE_STRING, "kich1" },
|
|
|
|
{ TTYC_KMOUS, TTYCODE_STRING, "kmous" },
|
|
|
|
{ TTYC_KNP, TTYCODE_STRING, "knp" },
|
|
|
|
{ TTYC_KPP, TTYCODE_STRING, "kpp" },
|
|
|
|
{ TTYC_OP, TTYCODE_STRING, "op" },
|
|
|
|
{ TTYC_REV, TTYCODE_STRING, "rev" },
|
|
|
|
{ TTYC_RI, TTYCODE_STRING, "ri" },
|
|
|
|
{ TTYC_RMACS, TTYCODE_STRING, "rmacs" },
|
|
|
|
{ TTYC_RMCUP, TTYCODE_STRING, "rmcup" },
|
2009-01-10 23:28:40 +01:00
|
|
|
{ TTYC_RMIR, TTYCODE_STRING, "rmir" },
|
2009-01-10 00:57:42 +01:00
|
|
|
{ TTYC_RMKX, TTYCODE_STRING, "rmkx" },
|
|
|
|
{ TTYC_SETAB, TTYCODE_STRING, "setab" },
|
|
|
|
{ TTYC_SETAF, TTYCODE_STRING, "setaf" },
|
|
|
|
{ TTYC_SGR0, TTYCODE_STRING, "sgr0" },
|
|
|
|
{ TTYC_SMACS, TTYCODE_STRING, "smacs" },
|
|
|
|
{ TTYC_SMCUP, TTYCODE_STRING, "smcup" },
|
2009-01-10 23:28:40 +01:00
|
|
|
{ TTYC_SMIR, TTYCODE_STRING, "smir" },
|
2009-01-10 00:57:42 +01:00
|
|
|
{ TTYC_SMKX, TTYCODE_STRING, "smkx" },
|
|
|
|
{ TTYC_SMSO, TTYCODE_STRING, "smso" },
|
|
|
|
{ TTYC_SMUL, TTYCODE_STRING, "smul" },
|
2009-10-15 03:33:21 +02:00
|
|
|
{ TTYC_VPA, TTYCODE_STRING, "vpa" },
|
2009-04-23 23:09:17 +02:00
|
|
|
{ TTYC_XENL, TTYCODE_FLAG, "xenl" },
|
2009-01-10 00:57:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
char *
|
|
|
|
tty_term_strip(const char *s)
|
|
|
|
{
|
|
|
|
const char *ptr;
|
|
|
|
static char buf[BUFSIZ];
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
/* Ignore strings with no padding. */
|
|
|
|
if (strchr(s, '$') == NULL)
|
|
|
|
return (xstrdup(s));
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
for (ptr = s; *ptr != '\0'; ptr++) {
|
|
|
|
if (*ptr == '$' && *(ptr + 1) == '<') {
|
|
|
|
while (*ptr != '\0' && *ptr != '>')
|
|
|
|
ptr++;
|
|
|
|
if (*ptr == '>')
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[len++] = *ptr;
|
|
|
|
if (len == (sizeof buf) - 1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf[len] = '\0';
|
|
|
|
|
|
|
|
return (xstrdup(buf));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-09 17:26:24 +02:00
|
|
|
tty_term_override(struct tty_term *term, const char *overrides)
|
2009-01-10 00:57:42 +01:00
|
|
|
{
|
2009-08-09 17:26:24 +02:00
|
|
|
struct tty_term_code_entry *ent;
|
|
|
|
struct tty_code *code;
|
|
|
|
char *termnext, *termstr, *entnext, *entstr;
|
|
|
|
char *s, *ptr, *val;
|
|
|
|
const char *errstr;
|
|
|
|
u_int i;
|
|
|
|
int n, removeflag;
|
|
|
|
|
|
|
|
s = xstrdup(overrides);
|
|
|
|
|
|
|
|
termnext = s;
|
|
|
|
while ((termstr = strsep(&termnext, ",")) != NULL) {
|
|
|
|
entnext = termstr;
|
|
|
|
|
|
|
|
entstr = strsep(&entnext, ":");
|
|
|
|
if (entstr == NULL || entnext == NULL)
|
|
|
|
continue;
|
|
|
|
if (fnmatch(entstr, term->name, 0) != 0)
|
|
|
|
continue;
|
|
|
|
while ((entstr = strsep(&entnext, ":")) != NULL) {
|
|
|
|
if (*entstr == '\0')
|
|
|
|
continue;
|
2009-01-10 02:30:38 +01:00
|
|
|
|
2009-08-09 17:26:24 +02:00
|
|
|
val = NULL;
|
|
|
|
removeflag = 0;
|
|
|
|
if ((ptr = strchr(entstr, '=')) != NULL) {
|
|
|
|
*ptr++ = '\0';
|
|
|
|
val = xstrdup(ptr);
|
2009-08-23 13:50:39 +02:00
|
|
|
if (strunvis(val, ptr) == -1) {
|
2009-08-09 17:26:24 +02:00
|
|
|
xfree(val);
|
|
|
|
val = xstrdup(ptr);
|
|
|
|
}
|
|
|
|
} else if (entstr[strlen(entstr) - 1] == '@') {
|
|
|
|
entstr[strlen(entstr) - 1] = '\0';
|
|
|
|
removeflag = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < NTTYCODE; i++) {
|
|
|
|
ent = &tty_term_codes[i];
|
|
|
|
if (strcmp(entstr, ent->name) != 0)
|
|
|
|
continue;
|
|
|
|
code = &term->codes[ent->code];
|
|
|
|
|
|
|
|
if (removeflag) {
|
|
|
|
code->type = TTYCODE_NONE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (ent->type) {
|
|
|
|
case TTYCODE_NONE:
|
|
|
|
break;
|
|
|
|
case TTYCODE_STRING:
|
2009-08-09 17:57:13 +02:00
|
|
|
if (code->type == TTYCODE_STRING)
|
|
|
|
xfree(code->value.string);
|
2009-08-09 17:26:24 +02:00
|
|
|
code->value.string = xstrdup(val);
|
|
|
|
code->type = ent->type;
|
|
|
|
break;
|
|
|
|
case TTYCODE_NUMBER:
|
|
|
|
n = strtonum(val, 0, INT_MAX, &errstr);
|
|
|
|
if (errstr != NULL)
|
|
|
|
break;
|
|
|
|
code->value.number = n;
|
|
|
|
code->type = ent->type;
|
|
|
|
break;
|
|
|
|
case TTYCODE_FLAG:
|
|
|
|
code->value.flag = 1;
|
|
|
|
code->type = ent->type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val != NULL)
|
|
|
|
xfree(val);
|
2009-01-10 02:30:38 +01:00
|
|
|
}
|
2009-01-10 02:51:22 +01:00
|
|
|
}
|
2009-08-09 17:26:24 +02:00
|
|
|
|
|
|
|
xfree(s);
|
2009-01-10 00:57:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct tty_term *
|
2009-08-09 17:26:24 +02:00
|
|
|
tty_term_find(char *name, int fd, const char *overrides, char **cause)
|
2009-01-10 00:57:42 +01:00
|
|
|
{
|
|
|
|
struct tty_term *term;
|
|
|
|
struct tty_term_code_entry *ent;
|
|
|
|
struct tty_code *code;
|
|
|
|
u_int i;
|
|
|
|
int n, error;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
SLIST_FOREACH(term, &tty_terms, entry) {
|
|
|
|
if (strcmp(term->name, name) == 0) {
|
|
|
|
term->references++;
|
|
|
|
return (term);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log_debug("new term: %s", name);
|
|
|
|
term = xmalloc(sizeof *term);
|
|
|
|
term->name = xstrdup(name);
|
|
|
|
term->references = 1;
|
2009-01-10 02:30:38 +01:00
|
|
|
term->flags = 0;
|
2009-08-09 18:52:06 +02:00
|
|
|
memset(&term->codes, 0, sizeof term->codes);
|
2009-01-10 00:57:42 +01:00
|
|
|
SLIST_INSERT_HEAD(&tty_terms, term, entry);
|
|
|
|
|
2009-07-14 08:47:12 +02:00
|
|
|
/* Set up curses terminal. */
|
2009-01-10 00:57:42 +01:00
|
|
|
if (setupterm(name, fd, &error) != OK) {
|
|
|
|
switch (error) {
|
|
|
|
case 1:
|
2009-08-09 14:06:25 +02:00
|
|
|
xasprintf(cause, "can't use hardcopy terminal: %s", name);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
xasprintf(cause, "missing or unsuitable terminal: %s", name);
|
2009-01-10 00:57:42 +01:00
|
|
|
break;
|
2009-08-09 14:06:25 +02:00
|
|
|
case -1:
|
2009-01-10 00:57:42 +01:00
|
|
|
xasprintf(cause, "can't find terminfo database");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
xasprintf(cause, "unknown error");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in codes. */
|
2009-01-10 02:30:38 +01:00
|
|
|
for (i = 0; i < NTTYCODE; i++) {
|
2009-01-10 00:57:42 +01:00
|
|
|
ent = &tty_term_codes[i];
|
2009-01-10 02:51:22 +01:00
|
|
|
|
2009-01-10 00:57:42 +01:00
|
|
|
code = &term->codes[ent->code];
|
|
|
|
code->type = TTYCODE_NONE;
|
|
|
|
switch (ent->type) {
|
|
|
|
case TTYCODE_NONE:
|
|
|
|
break;
|
|
|
|
case TTYCODE_STRING:
|
2009-05-15 14:57:36 +02:00
|
|
|
s = tigetstr((char *) ent->name);
|
2009-01-10 00:57:42 +01:00
|
|
|
if (s == NULL || s == (char *) -1)
|
|
|
|
break;
|
|
|
|
code->type = TTYCODE_STRING;
|
|
|
|
code->value.string = tty_term_strip(s);
|
|
|
|
break;
|
|
|
|
case TTYCODE_NUMBER:
|
2009-05-15 14:57:36 +02:00
|
|
|
n = tigetnum((char *) ent->name);
|
2009-01-10 00:57:42 +01:00
|
|
|
if (n == -1 || n == -2)
|
|
|
|
break;
|
|
|
|
code->type = TTYCODE_NUMBER;
|
|
|
|
code->value.number = n;
|
|
|
|
break;
|
|
|
|
case TTYCODE_FLAG:
|
2009-05-15 14:57:36 +02:00
|
|
|
n = tigetflag((char *) ent->name);
|
2009-01-10 00:57:42 +01:00
|
|
|
if (n == -1)
|
|
|
|
break;
|
|
|
|
code->type = TTYCODE_FLAG;
|
|
|
|
code->value.number = n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-08-09 17:26:24 +02:00
|
|
|
tty_term_override(term, overrides);
|
2009-01-10 00:57:42 +01:00
|
|
|
|
2009-07-14 08:47:12 +02:00
|
|
|
/* Delete curses data. */
|
2009-01-10 00:57:42 +01:00
|
|
|
del_curterm(cur_term);
|
|
|
|
|
|
|
|
/* These are always required. */
|
|
|
|
if (!tty_term_has(term, TTYC_CLEAR)) {
|
|
|
|
xasprintf(cause, "terminal does not support clear");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (!tty_term_has(term, TTYC_RI)) {
|
|
|
|
xasprintf(cause, "terminal does not support ri");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (!tty_term_has(term, TTYC_CUP)) {
|
|
|
|
xasprintf(cause, "terminal does not support cup");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These can be emulated so one of the two is required. */
|
|
|
|
if (!tty_term_has(term, TTYC_CUD1) && !tty_term_has(term, TTYC_CUD)) {
|
|
|
|
xasprintf(cause, "terminal does not support cud1 or cud");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (!tty_term_has(term, TTYC_IL1) && !tty_term_has(term, TTYC_IL)) {
|
|
|
|
xasprintf(cause, "terminal does not support il1 or il");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (!tty_term_has(term, TTYC_DL1) && !tty_term_has(term, TTYC_DL)) {
|
|
|
|
xasprintf(cause, "terminal does not support dl1 or dl");
|
|
|
|
goto error;
|
|
|
|
}
|
2009-05-04 19:58:27 +02:00
|
|
|
if (!tty_term_has(term, TTYC_ICH1) &&
|
2009-01-10 23:28:40 +01:00
|
|
|
!tty_term_has(term, TTYC_ICH) && (!tty_term_has(term, TTYC_SMIR) ||
|
|
|
|
!tty_term_has(term, TTYC_RMIR))) {
|
2009-05-04 19:58:27 +02:00
|
|
|
xasprintf(cause,
|
2009-01-10 23:28:40 +01:00
|
|
|
"terminal does not support ich1 or ich or smir and rmir");
|
2009-01-10 00:57:42 +01:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Figure out if terminal support default colours. AX is a screen
|
|
|
|
* extension which indicates this. Also check if op (orig_pair) uses
|
|
|
|
* the default colours - if it does, this is a good indication the
|
|
|
|
* terminal supports them.
|
|
|
|
*/
|
|
|
|
if (tty_term_flag(term, TTYC_AX))
|
|
|
|
term->flags |= TERM_HASDEFAULTS;
|
|
|
|
if (strcmp(tty_term_string(term, TTYC_OP), "\033[39;49m") == 0)
|
|
|
|
term->flags |= TERM_HASDEFAULTS;
|
|
|
|
|
2009-10-25 11:42:08 +01:00
|
|
|
/* Figure out if we have 256 or 88 colours. */
|
2009-01-10 00:57:42 +01:00
|
|
|
if (tty_term_number(term, TTYC_COLORS) == 256)
|
|
|
|
term->flags |= TERM_256COLOURS;
|
2009-03-07 11:29:06 +01:00
|
|
|
if (tty_term_number(term, TTYC_COLORS) == 88)
|
|
|
|
term->flags |= TERM_88COLOURS;
|
2009-01-10 00:57:42 +01:00
|
|
|
|
2009-04-23 23:09:17 +02:00
|
|
|
/*
|
|
|
|
* Terminals without xenl (eat newline glitch) wrap at at $COLUMNS - 1
|
|
|
|
* rather than $COLUMNS (the cursor can never be beyond $COLUMNS - 1).
|
|
|
|
*
|
|
|
|
* This is irritating, most notably because it is impossible to write
|
|
|
|
* to the very bottom-right of the screen without scrolling.
|
|
|
|
*
|
|
|
|
* Flag the terminal here and apply some workarounds in other places to
|
|
|
|
* do the best possible.
|
|
|
|
*/
|
|
|
|
if (!tty_term_flag(term, TTYC_XENL))
|
|
|
|
term->flags |= TERM_EARLYWRAP;
|
|
|
|
|
2009-01-10 00:57:42 +01:00
|
|
|
return (term);
|
|
|
|
|
|
|
|
error:
|
|
|
|
tty_term_free(term);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_term_free(struct tty_term *term)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
if (--term->references != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SLIST_REMOVE(&tty_terms, term, tty_term, entry);
|
|
|
|
|
|
|
|
for (i = 0; i < NTTYCODE; i++) {
|
|
|
|
if (term->codes[i].type == TTYCODE_STRING)
|
|
|
|
xfree(term->codes[i].value.string);
|
|
|
|
}
|
|
|
|
xfree(term->name);
|
|
|
|
xfree(term);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tty_term_has(struct tty_term *term, enum tty_code_code code)
|
|
|
|
{
|
|
|
|
return (term->codes[code].type != TTYCODE_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
tty_term_string(struct tty_term *term, enum tty_code_code code)
|
|
|
|
{
|
|
|
|
if (!tty_term_has(term, code))
|
|
|
|
return ("");
|
|
|
|
if (term->codes[code].type != TTYCODE_STRING)
|
|
|
|
log_fatalx("not a string: %d", code);
|
|
|
|
return (term->codes[code].value.string);
|
|
|
|
}
|
|
|
|
|
2009-07-14 08:47:12 +02:00
|
|
|
/* No vtparm. Fucking curses. */
|
2009-01-10 00:57:42 +01:00
|
|
|
const char *
|
|
|
|
tty_term_string1(struct tty_term *term, enum tty_code_code code, int a)
|
|
|
|
{
|
2009-09-22 21:20:08 +02:00
|
|
|
return (tparm((char *) tty_term_string(term, code), a, 0, 0, 0, 0, 0, 0, 0, 0));
|
2009-01-10 00:57:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
tty_term_string2(struct tty_term *term, enum tty_code_code code, int a, int b)
|
|
|
|
{
|
2009-09-22 21:20:08 +02:00
|
|
|
return (tparm((char *) tty_term_string(term, code), a, b, 0, 0, 0, 0, 0, 0, 0));
|
2009-01-10 00:57:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tty_term_number(struct tty_term *term, enum tty_code_code code)
|
|
|
|
{
|
|
|
|
if (!tty_term_has(term, code))
|
|
|
|
return (0);
|
|
|
|
if (term->codes[code].type != TTYCODE_NUMBER)
|
|
|
|
log_fatalx("not a number: %d", code);
|
|
|
|
return (term->codes[code].value.number);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tty_term_flag(struct tty_term *term, enum tty_code_code code)
|
|
|
|
{
|
|
|
|
if (!tty_term_has(term, code))
|
|
|
|
return (0);
|
|
|
|
if (term->codes[code].type != TTYCODE_FLAG)
|
|
|
|
log_fatalx("not a flag: %d", code);
|
|
|
|
return (term->codes[code].value.flag);
|
|
|
|
}
|