summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES6
-rw-r--r--TODO1
-rw-r--r--client.c10
-rw-r--r--local.c82
4 files changed, 85 insertions, 14 deletions
diff --git a/CHANGES b/CHANGES
index d5d0fee3..7795f188 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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 $
diff --git a/TODO b/TODO
index 24193c27..8b2604c5 100644
--- a/TODO
+++ b/TODO
@@ -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
diff --git a/client.c b/client.c
index 708de7fd..b3bc3251 100644
--- a/client.c
+++ b/client.c
@@ -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) {
diff --git a/local.c b/local.c
index c7c2e90d..62abab55 100644
--- a/local.c
+++ b/local.c
@@ -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);