dvtm

dynamic virtual terminal manager - with my changes
git clone https://pi.duncano.de/git/dvtm.git
Log | Files | Refs | README | LICENSE

commit fc397495fe907e2752ada48b0107beb5f85cc2be
parent db8d8c7ce7c3fbf9e365a29a8d96375fe27546c2
Author: Marc Andre Tanner <mat@brain-dump.org>
Date:   Mon, 18 Apr 2011 18:43:34 +0200

Change terminal attributes dynamically depending on window title

Based on a patch from Ross Mohn.

Signed-off-by: Marc Andre Tanner <mat@brain-dump.org>

Diffstat:
config.h | 7+++++++
dvtm.c | 27+++++++++++++++++++++++++++
madtty.c | 19++++++++++++++++---
madtty.h | 1+
4 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/config.h b/config.h @@ -98,6 +98,13 @@ Key keys[] = { { MOD, '?', { create, { "man dvtm", "dvtm help" } } }, }; +static const ColorRule colorrules[] = { + /* title attrs fgcolor bgcolor */ +#if 0 + { "ssh", A_NORMAL, COLOR_BLACK, 224 }, +#endif +}; + /* possible values for the mouse buttons are listed below: * * BUTTON1_PRESSED mouse button 1 down diff --git a/dvtm.c b/dvtm.c @@ -57,6 +57,13 @@ struct Client { Client *prev; }; +typedef struct { + const char *title; + unsigned attrs; + short fg; + short bg; +} ColorRule; + #define ALT(k) ((k) + (161 - 'a')) #ifndef CTRL #define CTRL(k) ((k) & 0x1F) @@ -608,6 +615,25 @@ killclient(const char *args[]) { kill(-sel->pid, SIGKILL); } +static void +applycolorrules(madtty_t *term, char *title) { + unsigned int i; + unsigned attrs = A_NORMAL; + short fg = -1, bg = -1; + const ColorRule *r; + + for (i = 0; i < countof(colorrules); i++) { + r = &colorrules[i]; + if (strstr(title, r->title)) { + attrs = r->attrs; + fg = r->fg; + bg = r->bg; + break; + } + } + madtty_set_default_colors(term, attrs, fg, bg); +} + static int title_escape_seq_handler(madtty_t *term, char *es) { Client *c; @@ -621,6 +647,7 @@ title_escape_seq_handler(madtty_t *term, char *es) { strncpy(c->title, es + 3, sizeof(c->title)); draw_border(c); debug("window title: %s\n", c->title); + applycolorrules(term, c->title); return MADTTY_HANDLER_OK; } diff --git a/madtty.c b/madtty.c @@ -104,8 +104,8 @@ struct madtty_t { /* geometry */ int rows, cols, maxcols; - unsigned curattrs, savattrs; - short curfg, curbg, savfg, savbg; + unsigned curattrs, savattrs, defattrs; + short curfg, curbg, savfg, savbg, deffg, defbg; /* scrollback buffer */ struct t_row_t *scroll_buf; @@ -1103,6 +1103,13 @@ int madtty_process(madtty_t *t) return 0; } +void madtty_set_default_colors(madtty_t *t, unsigned attrs, short fg, short bg) +{ + t->defattrs = attrs; + t->deffg = fg; + t->defbg = bg; +} + madtty_t *madtty_create(int rows, int cols, int scroll_buf_sz) { madtty_t *t; @@ -1138,7 +1145,7 @@ madtty_t *madtty_create(int rows, int cols, int scroll_buf_sz) t->curs_row = t->lines; t->curs_col = 0; t->curattrs = A_NORMAL; /* white text over black background */ - t->curfg = t->curbg = -1; + t->curfg = t->curbg = t->deffg = t->defbg = -1; /* initial scrolling area is the whole window */ t->scroll_top = t->lines; @@ -1296,6 +1303,12 @@ void madtty_draw(madtty_t *t, WINDOW *win, int srow, int scol) || row->attr[j] != row->attr[j - 1] || row->fg[j] != row->fg[j-1] || row->bg[j] != row->bg[j-1]) { + if (row->attr[j] == A_NORMAL) + row->attr[j] = t->defattrs; + if (row->fg[j] == -1) + row->fg[j] = t->deffg; + if (row->bg[j] == -1) + row->bg[j] = t->defbg; wattrset(win, (attr_t)row->attr[j] << NCURSES_ATTR_SHIFT); madtty_color_set(win, row->fg[j], row->bg[j]); } diff --git a/madtty.h b/madtty.h @@ -58,6 +58,7 @@ void madtty_init_vt100_graphics(void); void madtty_set_handler(madtty_t *, madtty_handler_t); void madtty_set_data(madtty_t *, void *); void *madtty_get_data(madtty_t *); +void madtty_set_default_colors(madtty_t *, unsigned attrs, short fg, short bg); madtty_t *madtty_create(int rows, int cols, int scroll_buf_sz); void madtty_resize(madtty_t *, int rows, int cols);