git.y1.nz

mtm

Ncurses-based terminal multiplexer
download: https://git.y1.nz/archives/mtm.tar.gz
Files | Log | Refs

commit a612ec0290360b3287b45f6be55b627bc708949e
parent 0a088df02dba24ac5e8f8013ffdecf69664febdb
Author: Rob King <jking@deadpixi.com>
Date:   Wed, 11 Apr 2018 11:05:45 -0500

Set the window title in the only guaranteed-to-work way.

ncurses does not have a way to set the title on a terminal
supporting the XT capability (e.g. xterm). We can inject
stuff into ncurses's output stream with (e.g.) putp, but
it doesn't always work because of partially-constructed
command sequences and delays in flushing and so on. The only
completely "correct" way to do it is to drop out of ncurses
temporarily, set the title, and drop back in. It's ugly, but it
works.

Diffstat:
Mmtm.c16++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/mtm.c b/mtm.c @@ -72,6 +72,7 @@ static int commandkey = CTL(COMMAND_KEY), nfds = 1; /* stdin */ static fd_set fds; static char iobuf[BUFSIZ + 1]; static bool dostatus = false; +static wchar_t title[MAXTITLE + 1]; static void setupevents(NODE *n); static void reshape(NODE *n, int y, int x, int h, int w); @@ -485,12 +486,14 @@ freenode(NODE *n, bool recurse) /* Free a node. */ } static void -updatetitle(void) /* update the current title */ +updatetitle(void) /* update the current title - XXX this is remarkbly inefficient */ { - if (dostatus){ - char title[MAXTITLE + 1] = {0}; - snprintf(title, MAXTITLE, "\033]0;%ls\a", focused->title); - putp(title); + if (dostatus && wcsncmp(title, focused->title, MAXTITLE) != 0){ + endwin(); + printf("\033]0;%ls\007", focused->title); + fflush(stdout); + refresh(); + wcsncpy(title, focused->title, MAXTITLE); } } @@ -678,9 +681,6 @@ reshape(NODE *n, int y, int x, int h, int w) /* Reshape a node. */ else reshapechildren(n); - if (n == root) - updatetitle(); - draw(n); wnoutrefresh(n->win); }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.