From 11d445b6720d78d4fe847affb1d26ee0a552ea0f Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Mon, 13 Aug 2018 22:54:02 -0400 Subject: Add termTitle --- chat.h | 2 ++ term.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/chat.h b/chat.h index 7e9f220..d6dfdf7 100644 --- a/chat.h +++ b/chat.h @@ -109,6 +109,8 @@ enum TermEvent { TERM_PASTE_START, TERM_PASTE_END, }; +void termInit(void); +void termTitle(const char *title); void termMode(enum TermMode mode, bool set); enum TermEvent termEvent(char ch); diff --git a/term.c b/term.c index c603d32..1266328 100644 --- a/term.c +++ b/term.c @@ -17,11 +17,25 @@ #include #include #include +#include #include "chat.h" #define PAIR(a, b) (((short)(a) << 8) | ((short)(b) & 0xFF)) +static bool xterm; + +void termInit(void) { + char *term = getenv("TERM"); + xterm = term && !strncmp(term, "xterm", 5); +} + +void termTitle(const char *title) { + if (!xterm) return; + printf("\33]0;%s\33\\", title); + fflush(stdout); +} + static void privateMode(const char *mode, bool set) { printf("\33[?%s%c", mode, (set ? 'h' : 'l')); fflush(stdout); -- cgit 1.4.1-2-gfad0