Check for required term capabilities on start.

This commit is contained in:
Nicholas Marriott 2007-11-08 10:39:52 +00:00
parent 35591ecd4e
commit f92243caa0
4 changed files with 85 additions and 14 deletions

View File

@ -1,3 +1,7 @@
08 November 2007
* (nicm) Check for required terminal capabilities on start.
31 October 2007
* (nicm) Linux port.
@ -186,4 +190,4 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
$Id: CHANGES,v 1.58 2007-11-07 19:41:17 nicm Exp $
$Id: CHANGES,v 1.59 2007-11-08 10:39:52 nicm Exp $

1
TODO
View File

@ -56,7 +56,6 @@
kill session (not bound by default)
- fix most(1) problems after scrolling
- fix mutt problems with redraw (mutt's) status line when reading mail
- check for some reqd terminfo caps on startup
-- For 0.2 --------------------------------------------------------------------
- copy and paste

View File

@ -1,4 +1,4 @@
/* $Id: client.c,v 1.19 2007-10-31 14:26:26 nicm Exp $ */
/* $Id: client.c,v 1.20 2007-11-08 10:39:52 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -136,15 +136,15 @@ client_main(struct client_ctx *cctx)
char *error;
int timeout;
siginit();
if ((cctx->loc_fd = local_init(&cctx->loc_in, &cctx->loc_out)) == -1)
return (1);
logfile("client");
#ifndef NO_SETPROCTITLE
setproctitle("client");
#endif
siginit();
if ((cctx->loc_fd = local_init(&cctx->loc_in, &cctx->loc_out)) == -1)
return (1);
error = NULL;
timeout = INFTIM;
while (!sigterm) {

82
local.c
View File

@ -1,4 +1,4 @@
/* $Id: local.c,v 1.17 2007-10-31 14:26:26 nicm Exp $ */
/* $Id: local.c,v 1.18 2007-11-08 10:39:52 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -213,10 +213,32 @@ u_char local_colr;
int
local_init(struct buffer **in, struct buffer **out)
{
char *tty;
int mode;
struct termios tio;
struct local_key *lk;
char *tty;
int mode, error;
struct termios tio;
struct local_key *lk;
u_int i, j;
static const char *const reqd[] = {
"carriage_return",
"change_scroll_region",
"clear_screen",
"clr_bol",
"clr_eol",
"cursor_address",
"cursor_down",
"enter_ca_mode",
"exit_ca_mode",
"parm_dch",
"parm_delete_line",
"parm_down_cursor",
"parm_ich",
"parm_insert_line",
"parm_left_cursor",
"parm_right_cursor",
"parm_up_cursor",
"scroll_reverse",
NULL
};
if ((tty = ttyname(STDOUT_FILENO)) == NULL)
fatal("ttyname failed");
@ -227,11 +249,57 @@ local_init(struct buffer **in, struct buffer **out)
if (fcntl(local_fd, F_SETFL, mode|O_NONBLOCK) == -1)
fatal("fcntl failed");
if (setupterm(NULL, STDOUT_FILENO, &error) != OK) {
switch (error) {
case 1:
log_warnx("hardcopy terminal cannot be used");
return (-1);
case 0:
log_warnx("terminal type not found or unsuitable");
return (-1);
case -1:
log_warnx("couldn't find terminfo database");
return (-1);
}
}
for (i = 0; reqd[i] != NULL; i++) {
error = 0;
for (j = 0; strfnames[j] != NULL; j++) {
if (strcmp(strfnames[j], reqd[i]) == 0) {
if (strcodes[j] == NULL)
error = -1;
break;
}
}
if (error != -1) {
for (j = 0; numfnames[j] != NULL; j++) {
if (strcmp(numfnames[j], reqd[i]) == 0) {
if (numcodes[j] == NULL)
error = -1;
break;
}
}
}
if (error != -1) {
for (j = 0; boolfnames[j] != NULL; j++) {
if (strcmp(boolfnames[j], reqd[i]) == 0) {
if (boolcodes[j] == NULL)
error = -1;
break;
}
}
}
if (error == -1) {
log_warnx("required capability missing: %s", reqd[i]);
return (-1);
}
}
*in = local_in = buffer_create(BUFSIZ);
*out = local_out = buffer_create(BUFSIZ);
setupterm(NULL, STDOUT_FILENO, NULL);
if (tcgetattr(local_fd, &local_tio) != 0)
fatal("tcgetattr failed");
memset(&tio, 0, sizeof tio);