configure.ac: Move ncurses/terminfo checks to m4/terminfo.m4.
m4/terminfo.m4: Add checks for tigetstr and tgetstr.
misc.cc, misc.h: Add get_string_term_cap; tries both terminfo and termcap.
(We could probably get away with only termcap names, but it's nice to
have them side-by-side, since the terminfo names are more useful.)
StatusLine.cc, StatusLine.h: Add tsl/dsl cap support. Used only if
cmd:term-status is blank. Clear title in dtor, so we don't leave
it behind if the user's shell (or invoking program) doesn't know
to clear it.
CmdExec.cc: Delete the statusbar on exit, so it doesn't stick around
if we move to background. This triggers the title clear. (It also
ensures nothing gets written to the title--now the log--though I don't
think that ever happens.)
lftp.conf: Update comment reflecting cmd:term-status change.
Titles just work with Cygwin without a special case now. For some
reason, terminfo on my Linux system is lacking these caps completely,
so don't remove the existing entries. Clearing the title should make
the titles a bit more friendly for people who havn't set up their
shell prompt, etc. to set them.
The termcap/terminfo code and autoconf macros need testing.
--
Glenn Maynard
Index: configure.ac
===================================================================
RCS file: /home/lav/cvsroot/lftp/configure.ac,v
retrieving revision 1.1
diff -u -r1.1 configure.ac
--- configure.ac 2002/07/18 16:10:11 1.1
+++ configure.ac 2002/07/22 02:27:34
@@ -221,19 +221,8 @@
AC_SEARCH_LIBS(hstrerror, resolv)
fi
-AC_SUBST(READLINE_SUPPLIB)
-AC_CHECK_FUNC(tgetent,
- [READLINE_SUPPLIB=],
- [AC_CHECK_LIB(curses, tgetent,
- [READLINE_SUPPLIB=-lcurses],
- [AC_CHECK_LIB(ncurses, tgetent,
- [READLINE_SUPPLIB=-lncurses],
- [AC_CHECK_LIB(termcap, tgetent,
- [READLINE_SUPPLIB=-ltermcap],
- [AC_MSG_WARN(No termcap nor curses library found)])
- ])
- ])
- ])
+lftp_TERMINFO
+
READLINE_CHECK
AC_ARG_WITH(ssl, [ --with-ssl[=/path] use SSL [at /path]
Index: lftp.conf
===================================================================
RCS file: /home/lav/cvsroot/lftp/lftp.conf,v
retrieving revision 1.19
diff -u -r1.19 lftp.conf
--- lftp.conf 2002/07/17 08:44:34 1.19
+++ lftp.conf 2002/07/22 02:27:34
@@ -67,7 +67,9 @@
# set at-exit "bo a last"
# open last
-## Strings to set titlebars. Use cmd:set-term-status to enable this.
+## Terminal strings to set titlebars for terminals that don't
+## properly specify tsl and fsl capabilities.
+## Use cmd:set-term-status to enable this.
set cmd:term-status/*screen* "\e_\T\e\\"
set cmd:term-status/*xterm* "\e[11;0]\e]2;\T\007\e[11]"
set cmd:term-status/*rxvt* "\e[11;0]\e]2;\T\007\e[11]"
Index: src/CmdExec.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/CmdExec.cc,v
retrieving revision 1.94
diff -u -r1.94 CmdExec.cc
--- src/CmdExec.cc 2002/07/18 07:06:40 1.94
+++ src/CmdExec.cc 2002/07/22 02:27:34
@@ -1149,6 +1149,14 @@
{
FeedCmd(res_at_exit.Query(0));
FeedCmd("\n");
+
+ if(status_line)
+ {
+ /* Clear the title, and ensure we don't write anything else
+ * to it in case we're being backgrounded. */
+ Delete(status_line);
+ status_line = 0;
+ }
}
void CmdExec::EmptyCmds()
Index: src/StatusLine.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/StatusLine.cc,v
retrieving revision 1.21
diff -u -r1.21 StatusLine.cc
--- src/StatusLine.cc 2002/07/12 09:55:02 1.21
+++ src/StatusLine.cc 2002/07/22 02:27:34
@@ -68,6 +68,8 @@
StatusLine::~StatusLine()
{
+ /* Don't leave a title behind. */
+ WriteTitle("", fd);
}
void StatusLine::Clear(bool title_also)
@@ -119,6 +121,9 @@
update_delayed=true;
}
+const char *StatusLine::to_status_line = get_string_term_cap("tsl", "ts");
+const char *StatusLine::from_status_line = get_string_term_cap("fsl", "fs");
+
void StatusLine::WriteTitle(const char *s, int fd) const
{
if(!ResMgr::QueryBool("cmd:set-term-status", getenv("TERM")))
@@ -134,7 +139,17 @@
{ 'T', s },
{ 0, "" }
};
- char *disp = Subst(ResMgr::Query("cmd:term-status", getenv("TERM")), subst);
+
+ const char *status_format = ResMgr::Query("cmd:term-status", getenv("TERM"));
+
+ char *disp;
+
+ /* If we have no format, and we have both tsl and fsl, use them: */
+ if((!status_format || !*status_format) && to_status_line && from_status_line)
+ disp = xasprintf("%s%s%s", to_status_line, s, from_status_line);
+ else
+ disp = Subst(status_format, subst);
+
write(fd, disp, strlen(disp));
xfree(disp);
}
Index: src/StatusLine.h
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/StatusLine.h,v
retrieving revision 1.12
diff -u -r1.12 StatusLine.h
--- src/StatusLine.h 2002/07/12 09:55:02 1.12
+++ src/StatusLine.h 2002/07/22 02:27:34
@@ -38,6 +38,7 @@
void update(char *);
int LastWidth;
bool next_update_title_only;
+ static const char *to_status_line, *from_status_line;
protected:
~StatusLine();
Index: src/misc.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/misc.cc,v
retrieving revision 1.49
diff -u -r1.49 misc.cc
--- src/misc.cc 2002/07/10 07:58:40 1.49
+++ src/misc.cc 2002/07/22 02:27:35
@@ -785,3 +785,47 @@
*slash=0;
return ret;
}
+
+#if defined(HAVE_TERM_H)
+#include <term.h>
+#elif defined(HAVE_NCURSES_TERM_H)
+#include <ncurses/term.h>
+#endif
+
+#if defined(HAVE_CURSES_H)
+#include <curses.h>
+#elif defined(HAVE_NCURSES_CURSES_H)
+#include <ncurses/curses.h>
+#endif
+
+#if defined(HAVE_TIGETSTR)
+static bool terminfo_ok = true;
+static void init_terminfo()
+{
+ static bool initted = false;
+ if(initted) return;
+ initted = true;
+
+ if(setupterm(NULL, 1, NULL) == ERR)
+ terminfo_ok = false;
+}
+#endif
+
+const char *get_string_term_cap(const char *terminfo_cap, const char *tcap_cap)
+{
+#if defined(HAVE_TIGETSTR)
+ init_terminfo();
+ if(terminfo_ok) {
+ /* Cast to work around missing const def in some ncurses installations: */
+ const char *ret = tigetstr(const_cast<char *>(terminfo_cap));
+ if(ret && ret != (char *)-1) return ret;
+ }
+#elif defined(HAVE_TGETSTR)
+ char buf[1024], *p = buf;
+ const char *ret = tgetstr(const_cast<char *>(tcap_cap), &p);
+ if(ret && ret != (char *)-1) return buf;
+#endif
+
+ return NULL;
+}
+
Index: src/misc.h
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/misc.h,v
retrieving revision 1.30
diff -u -r1.30 misc.h
--- src/misc.h 2002/01/21 16:25:18 1.30
+++ src/misc.h 2002/07/22 02:27:35
@@ -111,4 +111,6 @@
char *dirname_alloc(const char *fn);
+const char *get_string_term_cap(const char *terminfo_cap, const char *tcap_cap=NULL);
+
#endif // MISC_H
AC_DEFUN(lftp_TERMINFO,
[
AC_CHECK_HEADERS(curses.h term.h ncurses/curses.h ncurses/term.h)
AC_SUBST(READLINE_SUPPLIB)
# Get a library with terminal caps if needed; prefer one with tigetstr.
AC_CHECK_FUNC(tigetstr,
[READLINE_SUPPLIB=],
[AC_CHECK_LIB(curses, tigetstr,
[READLINE_SUPPLIB=-lcurses],
[AC_CHECK_LIB(ncurses, tigetstr,
[READLINE_SUPPLIB=-lncurses],
[AC_CHECK_FUNC(tgetent,
[READLINE_SUPPLIB=],
[AC_CHECK_LIB(curses, tgetent,
[READLINE_SUPPLIB=-lcurses],
[AC_CHECK_LIB(ncurses, tgetent,
[READLINE_SUPPLIB=-lncurses],
[AC_CHECK_LIB(termcap, tgetent,
[READLINE_SUPPLIB=-ltermcap],
[AC_MSG_WARN(No terminfo, termcap or curses library found)])
])
])
])
])
])
])
# Check for working tigetstr and tgetstr.
OLDLIBS="$LIBS"
LIBS="$LIBS $READLINE_SUPPLIB"
AC_MSG_CHECKING([for tigetstr])
AC_TRY_LINK([
#if defined(HAVE_TERM_H)
#include <term.h>
#elif defined(HAVE_NCURSES_TERM_H)
#include <ncurses/term.h>
#endif
#if defined(HAVE_CURSES_H)
#include <curses.h>
#elif defined(HAVE_NCURSES_CURSES_H)
#include <ncurses/curses.h>
#endif],
[ tigetstr((char *) 0); ],
[ AC_DEFINE(HAVE_TIGETSTR, 1, [System has usable tigetstr])
AC_MSG_RESULT(yes) ],
[ AC_MSG_RESULT(no) ]
)
AC_MSG_CHECKING([for tgetstr])
AC_TRY_LINK([
#if defined(HAVE_TERM_H)
#include <term.h>
#elif defined(HAVE_NCURSES_TERM_H)
#include <ncurses/term.h>
#endif
#if defined(HAVE_CURSES_H)
#include <curses.h>
#elif defined(HAVE_NCURSES_CURSES_H)
#include <ncurses/curses.h>
#endif],
[ tgetstr((char *) 0, (char **) 0); ],
[ AC_DEFINE(HAVE_TGETSTR, 1, [System has usable tgetstr])
AC_MSG_RESULT(yes) ],
[ AC_MSG_RESULT(no) ]
)
LIBS="$OLDLIBS"
])