diff --git a/src/winio.c b/src/winio.c index 0506c132..2942685a 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1979,6 +1979,16 @@ int buffer_number(openfilestruct *buffer) } #endif +/* Set the terminal emulator's titlebar. */ +static void set_terminal_titlebar(size_t prefixlen, const char *prefix, char *path) +{ + printf("\033]0;nano: "); + if (prefixlen > 0) + printf("%s ", prefix); + printf("%s\007", path); + fflush(stdout); +} + /* If path is NULL, we're in normal editing mode, so display the current * version of nano, the current filename, and whether the current file * has been modified on the title bar. If path isn't NULL, we're either @@ -2100,12 +2110,15 @@ void titlebar(const char *path) if (pathlen + pluglen + statelen <= COLS) { caption = display_string(path, 0, pathlen, FALSE, FALSE); waddstr(topwin, caption); + set_terminal_titlebar(prefixlen, prefix, caption); free(caption); } else if (5 + statelen <= COLS) { waddstr(topwin, "..."); caption = display_string(path, 3 + pathlen - COLS + statelen, COLS - statelen, FALSE, FALSE); waddstr(topwin, caption); + caption = display_string(path, 0, pathlen, FALSE, FALSE); + set_terminal_titlebar(prefixlen, prefix, caption); free(caption); }