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