00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "misc.h"
00022
00023 #ifdef HAVE_NCURSES_H
00024 # include <ncurses.h>
00025 #else // HAVE_NCURSES_H
00026 # ifdef HAVE_CURSES_H
00027 # include <curses.h>
00028 # else
00029 # error "Neither curses.h nor ncurses.h available"
00030 # endif // HAVE_CURSES_H
00031 #endif // HAVE_NCURSES_H
00032 #include "curswa.h"
00033
00034 #ifdef HAVE_STDIO_H
00035 #include <stdio.h>
00036 #else
00037 # error "Sorry, stdio.h needed"
00038 #endif
00039
00040 #ifdef HAVE_STRING_H
00041 #include <string.h>
00042 #endif
00043 #ifdef HAVE_STRINGS_H
00044 #include <strings.h>
00045 #endif
00046
00047
00048 #if defined(HAVE_TERMINALTITLE) && defined(HAVE_TERMNAME)
00049 #define CANSETTITLE
00050 #endif
00051
00057 static const char* xterms[] = {
00058 "xterm",
00059 "dtterm",
00060 NULL
00061 };
00062
00071 inline static int mystrcmp(const char* s1, const char* s2) {
00072 #ifdef HAVE_STRNCASECMP
00073 return strncasecmp(s1, s2, (strlen(s1)<strlen(s2) ? strlen(s1) : strlen(s2)) );
00074 #elif HAVE_STRNCMP
00075 return strncmp(s1, s2, (strlen(s1)<strlen(s2) ? strlen(s1) : strlen(s2)) );
00076 #elif HAVE_STRCMP
00077 return strcmp(s1, s2);
00078 #else
00079 # error "Sorry, strncasecmp, strncmp, or strcmp needed"
00080 #endif
00081 }
00082
00083
00084
00095 #ifdef HAVE_TERMNAME
00096 bool isXTerm() {
00097 const char** tmp = xterms;
00098 char* tn = termname();
00099 while (*tmp != NULL) {
00100 if (mystrcmp(tn,*tmp) == 0) return true;
00101 tmp++;
00102 }
00103 return false;
00104 }
00105 #else
00106 bool isXTerm() { return false; }
00107 #endif // HAVE_TERMNAME
00108
00115 #ifdef CANSETTITLE
00116 void setTerminalTitle (const std::string& title) {
00117 if (isXTerm()) {
00118 fprintf(stdout, "%c]0;%s%c", '\033', title.c_str(), '\007');
00119 fflush(stdout);
00120 }
00121 }
00122 #else // CANSETTITLE
00123 void setTerminalTitle (const std::string& title) {}
00124 #endif // CANSETTITLE