aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2009-01-30 00:24:49 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2009-01-30 00:24:49 +0000
commit882316ad6a771112e666126f00b8781c79ed8d30 (patch)
tree29db6d5f29ea9820aa0b54a428526257bfd76792
parent2bb499c8af141282401fef93c89224613df3b655 (diff)
downloadrtmux-882316ad6a771112e666126f00b8781c79ed8d30.tar.gz
rtmux-882316ad6a771112e666126f00b8781c79ed8d30.tar.bz2
rtmux-882316ad6a771112e666126f00b8781c79ed8d30.zip
Set colour of window entry in status line based on window options.
-rw-r--r--CHANGES24
-rw-r--r--TODO15
-rw-r--r--cmd-set-option.c8
-rw-r--r--cmd-set-window-option.c11
-rw-r--r--status.c56
-rw-r--r--tmux.c8
-rw-r--r--tmux.h6
7 files changed, 77 insertions, 51 deletions
diff --git a/CHANGES b/CHANGES
index aec4c67e..39bb102e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,27 @@
29 January 2009
+* Window options to set status line fg, bg and attributes for a single
+ window. Options are: window-status-fg, window-status-bg,
+ window-status-attr. Set to "default" to use the session status colours.
+
+ This allows quite neat things like:
+
+ $ cat xssh
+ #!/bin/sh
+
+ if [ ! -z "$TMUX" ]; then
+ case "$1" in
+ natalya)
+ tmux setw window-status-fg red >/dev/null
+ ;;
+ natasha)
+ tmux setw window-status-fg yellow >/dev/null
+ ;;
+ esac
+ fi
+ ssh "$@"
+ [ ! -z "$TMUX" ] && tmux setw -u window-status-fg >/dev/null
+
* Support #(command) in status-left, and status-right, which is displayed as
the first line of command's output (e.g. set -g status-right
"#(whoami)@#(hostname -s)"). Commands with )s aren't supported.
@@ -1043,7 +1065,7 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
-$Id: CHANGES,v 1.241 2009-01-29 23:35:14 tcunha Exp $
+$Id: CHANGES,v 1.242 2009-01-30 00:24:49 nicm Exp $
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
diff --git a/TODO b/TODO
index 8293ed4b..1bc95e00 100644
--- a/TODO
+++ b/TODO
@@ -77,16 +77,19 @@
and n of width 0, then translate cursor indexes on-the-fly would need to
adjust all cursor movement and also handle different width lines properly.
- support other mouse modes (highlight etc) and use it in copy mode
-
-(hopefully) for 0.7, in no particular order:
-- swap-pane-up, swap-pane-down (maybe move-pane-*)
-- move-pane (to window) (maybe break-pane?)
- command: copy-buffer -s src-session -t dst-session -a src-index -b dst-index
(copy from other session)
-- document -u flag to scroll-mode/copy-mode
+- swap-pane-up, swap-pane-down (maybe move-pane-*)
+- move-pane (to window) (maybe break-pane?)
+- $TMUX should contain socket path
+- rules to colour windows in status line based on name/title
+
+(hopefully) for 0.7, in no particular order:
- key to switch to copy mode from scroll mode
+- attach should have a flag to create session if it doesn't exist
+- document -u flag to scroll-mode/copy-mode
- document suspend-client
- document command sequences
- document find-window
- document split-window -p and -l
-- attach should have a flag to create session if it doesn't exist
+- document window-status-{fg, bg, attr}
diff --git a/cmd-set-option.c b/cmd-set-option.c
index c7940639..1dc8afb5 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-set-option.c,v 1.57 2009-01-27 20:22:33 nicm Exp $ */
+/* $Id: cmd-set-option.c,v 1.58 2009-01-30 00:24:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -125,11 +125,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
return (-1);
}
- if (options_remove(oo, entry->name) != 0) {
- ctx->error(ctx,
- "can't unset option, not set: %s", entry->name);
- return (-1);
- }
+ options_remove(oo, entry->name);
ctx->info(ctx, "unset option: %s", entry->name);
} else {
switch (entry->type) {
diff --git a/cmd-set-window-option.c b/cmd-set-window-option.c
index 08b6ebdd..c969faf6 100644
--- a/cmd-set-window-option.c
+++ b/cmd-set-window-option.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-set-window-option.c,v 1.23 2009-01-27 20:22:33 nicm Exp $ */
+/* $Id: cmd-set-window-option.c,v 1.24 2009-01-30 00:24:49 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -68,6 +68,9 @@ const struct set_option_entry set_window_option_table[NSETWINDOWOPTION] = {
{ "monitor-activity", SET_OPTION_FLAG, 0, 0, NULL },
{ "remain-on-exit", SET_OPTION_FLAG, 0, 0, NULL },
{ "utf8", SET_OPTION_FLAG, 0, 0, NULL },
+ { "window-status-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
+ { "window-status-bg", SET_OPTION_COLOUR, 0, 0, NULL },
+ { "window-status-fg", SET_OPTION_COLOUR, 0, 0, NULL },
{ "xterm-keys", SET_OPTION_FLAG, 0, 0, NULL },
};
@@ -126,11 +129,7 @@ cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx)
return (-1);
}
- if (options_remove(oo, entry->name) != 0) {
- ctx->error(ctx,
- "can't unset option, not set: %s", entry->name);
- return (-1);
- }
+ options_remove(oo, entry->name);
ctx->info(ctx, "unset option: %s", entry->name);
} else {
switch (entry->type) {
diff --git a/status.c b/status.c
index 836c2c00..7850cfd6 100644
--- a/status.c
+++ b/status.c
@@ -1,4 +1,4 @@
-/* $Id: status.c,v 1.69 2009-01-29 23:35:14 tcunha Exp $ */
+/* $Id: status.c,v 1.70 2009-01-30 00:24:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -49,9 +49,8 @@ status_redraw(struct client *c)
char *left, *right, *text, *ptr;
size_t llen, rlen, offset, xx, yy, sy;
size_t size, start, width;
- struct grid_cell gc;
+ struct grid_cell stdgc, gc;
int larrow, rarrow;
- u_char stdattr, revattr;
left = right = NULL;
@@ -68,12 +67,10 @@ status_redraw(struct client *c)
if (gettimeofday(&c->status_timer, NULL) != 0)
fatal("gettimeofday");
- memcpy(&gc, &grid_default_cell, sizeof gc);
- gc.bg = options_get_number(&s->options, "status-fg");
- gc.fg = options_get_number(&s->options, "status-bg");
- gc.attr |= options_get_number(&s->options, "status-attr");
- stdattr = gc.attr;
- revattr = gc.attr ^ GRID_ATTR_REVERSE;
+ memcpy(&stdgc, &grid_default_cell, sizeof gc);
+ stdgc.bg = options_get_number(&s->options, "status-fg");
+ stdgc.fg = options_get_number(&s->options, "status-bg");
+ stdgc.attr |= options_get_number(&s->options, "status-attr");
yy = c->sy - 1;
if (yy == 0)
@@ -168,9 +165,9 @@ draw:
screen_write_start(&ctx, NULL, &c->status);
if (llen != 0) {
screen_write_cursormove(&ctx, 0, yy);
- screen_write_puts(&ctx, &gc, "%s ", left);
+ screen_write_puts(&ctx, &stdgc, "%s ", left);
if (larrow)
- screen_write_putc(&ctx, &gc, ' ');
+ screen_write_putc(&ctx, &stdgc, ' ');
} else {
if (larrow)
screen_write_cursormove(&ctx, 1, yy);
@@ -181,6 +178,7 @@ draw:
/* Draw each character in succession. */
offset = 0;
RB_FOREACH(wl, winlinks, &s->windows) {
+ memcpy(&gc, &stdgc, sizeof gc);
text = status_print(s, wl, &gc);
if (larrow == 1 && offset < start) {
@@ -203,10 +201,9 @@ draw:
rarrow = -1;
}
- gc.attr = stdattr;
if (offset < start + width) {
if (offset >= start) {
- screen_write_putc(&ctx, &gc, ' ');
+ screen_write_putc(&ctx, &stdgc, ' ');
}
offset++;
}
@@ -216,38 +213,34 @@ draw:
/* Fill the remaining space if any. */
while (offset++ < xx)
- screen_write_putc(&ctx, &gc, ' ');
+ screen_write_putc(&ctx, &stdgc, ' ');
/* Draw the last item. */
if (rlen != 0) {
screen_write_cursormove(&ctx, c->sx - rlen - 1, yy);
- screen_write_puts(&ctx, &gc, " %s", right);
+ screen_write_puts(&ctx, &stdgc, " %s", right);
}
/* Draw the arrows. */
if (larrow != 0) {
+ memcpy(&gc, &stdgc, sizeof gc);
if (larrow == -1)
- gc.attr = revattr;
- else
- gc.attr = stdattr;
+ gc.attr ^= GRID_ATTR_REVERSE;
if (llen != 0)
screen_write_cursormove(&ctx, llen + 1, yy);
else
screen_write_cursormove(&ctx, 0, yy);
screen_write_putc(&ctx, &gc, '<');
- gc.attr = revattr;
}
if (rarrow != 0) {
+ memcpy(&gc, &stdgc, sizeof gc);
if (rarrow == -1)
- gc.attr = revattr;
- else
- gc.attr = stdattr;
+ gc.attr ^= GRID_ATTR_REVERSE;
if (rlen != 0)
screen_write_cursormove(&ctx, c->sx - rlen - 2, yy);
else
screen_write_cursormove(&ctx, c->sx - 1, yy);
screen_write_putc(&ctx, &gc, '>');
- gc.attr = stdattr;
}
goto out;
@@ -257,7 +250,7 @@ blank:
screen_write_start(&ctx, NULL, &c->status);
screen_write_cursormove(&ctx, 0, yy);
for (offset = 0; offset < c->sx; offset++)
- screen_write_putc(&ctx, &gc, ' ');
+ screen_write_putc(&ctx, &stdgc, ' ');
goto out;
@@ -266,7 +259,7 @@ off:
* Draw the real window last line. Necessary to wipe over message if
* status is off. Not sure this is the right place for this.
*/
- memcpy(&gc, &grid_default_cell, sizeof gc);
+ memcpy(&stdgc, &grid_default_cell, sizeof stdgc);
screen_write_start(&ctx, NULL, &c->status);
sy = 0;
@@ -279,7 +272,7 @@ off:
if (sy < c->sy) {
/* If the screen is too small, use blank. */
for (offset = 0; offset < c->sx; offset++)
- screen_write_putc(&ctx, &gc, ' ');
+ screen_write_putc(&ctx, &stdgc, ' ');
} else {
screen_write_copy(&ctx,
sc, 0, sc->grid->hsize + screen_size_y(sc) - 1, c->sx, 1);
@@ -438,6 +431,17 @@ char *
status_print(struct session *s, struct winlink *wl, struct grid_cell *gc)
{
char *text, flag;
+ u_char fg, bg, attr;
+
+ fg = options_get_number(&wl->window->options, "window-status-fg");
+ if (fg != 8)
+ gc->fg = fg;
+ bg = options_get_number(&wl->window->options, "window-status-bg");
+ if (bg != 8)
+ gc->bg = bg;
+ attr = options_get_number(&wl->window->options, "window-status-attr");
+ if (attr != 0)
+ gc->attr = attr;
flag = ' ';
if (wl == SLIST_FIRST(&s->lastw))
diff --git a/tmux.c b/tmux.c
index 4be9ae82..b0d15595 100644
--- a/tmux.c
+++ b/tmux.c
@@ -1,4 +1,4 @@
-/* $Id: tmux.c,v 1.103 2009-01-27 20:22:33 nicm Exp $ */
+/* $Id: tmux.c,v 1.104 2009-01-30 00:24:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -261,12 +261,16 @@ main(int argc, char **argv)
options_set_number(&global_window_options, "automatic-rename", 1);
options_set_number(&global_window_options, "mode-bg", 3);
options_set_number(&global_window_options, "mode-fg", 0);
- options_set_number(&global_window_options, "mode-attr", GRID_ATTR_REVERSE);
+ options_set_number(
+ &global_window_options, "mode-attr", GRID_ATTR_REVERSE);
options_set_number(&global_window_options, "mode-keys", MODEKEY_EMACS);
options_set_number(&global_window_options, "monitor-activity", 0);
options_set_number(&global_window_options, "utf8", 0);
options_set_number(&global_window_options, "xterm-keys", 0);
options_set_number(&global_window_options, "remain-on-exit", 0);
+ options_set_number(&global_window_options, "window-status-bg", 8);
+ options_set_number(&global_window_options, "window-status-fg", 8);
+ options_set_number(&global_window_options, "window-status-attr", 0);
if (cfg_file == NULL) {
home = getenv("HOME");
diff --git a/tmux.h b/tmux.h
index 7c4a1a93..c0124311 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.257 2009-01-29 19:26:53 nicm Exp $ */
+/* $Id: tmux.h,v 1.258 2009-01-30 00:24:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -459,8 +459,6 @@ struct options_entry {
OPTIONS_STRING,
OPTIONS_NUMBER,
OPTIONS_KEY,
- OPTIONS_COLOURS,
- OPTIONS_ATTRIBUTES
} type;
union {
char *string;
@@ -912,7 +910,7 @@ struct set_option_entry {
extern const struct set_option_entry set_option_table[];
extern const struct set_option_entry set_window_option_table[];
#define NSETOPTION 22
-#define NSETWINDOWOPTION 14
+#define NSETWINDOWOPTION 17
/* Edit keys. */
enum mode_key {