summaryrefslogtreecommitdiffstats
authortcunha <tcunha>2011-01-22 00:00:23 (GMT)
committer tcunha <tcunha>2011-01-22 00:00:23 (GMT)
commit5ab87671e3436ef3e6f41dfc366d2c9553ffdcb2 (patch) (side-by-side diff)
treeaed4b46a84c348445c5ec73adcedc18433dc2d0c
parentc221819d3aabbe5abbc12ac7bd326498e362aa64 (diff)
parent204d84e0b8990b04d6ba1db07ceda1e54edd0a8c (diff)
downloadtmux-old-5ab87671e3436ef3e6f41dfc366d2c9553ffdcb2.zip
tmux-old-5ab87671e3436ef3e6f41dfc366d2c9553ffdcb2.tar.gz
tmux-old-5ab87671e3436ef3e6f41dfc366d2c9553ffdcb2.tar.bz2
cvsimport
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--client.c9
-rw-r--r--cmd-bind-key.c8
-rw-r--r--cmd-new-session.c29
-rw-r--r--cmd-pipe-pane.c9
-rw-r--r--cmd-server-info.c7
-rw-r--r--cmd-unbind-key.c6
-rw-r--r--colour.c121
-rw-r--r--configure.ac5
-rw-r--r--input.c6
-rw-r--r--job.c9
-rw-r--r--options-table.c4
-rw-r--r--server-client.c41
-rw-r--r--server.c10
-rw-r--r--session.c20
-rw-r--r--tmux.151
-rw-r--r--tmux.c33
-rw-r--r--tmux.h13
-rw-r--r--tty.c32
-rw-r--r--window.c9
19 files changed, 285 insertions, 137 deletions
diff --git a/client.c b/client.c
index 16ea409..d11affd 100644
--- a/client.c
+++ b/client.c
@@ -1,4 +1,4 @@
-/* $Id: client.c,v 1.100 2010/10/24 19:54:41 nicm Exp $ */
+/* $Id: client.c,v 1.101 2011/01/21 23:44:13 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -54,7 +54,7 @@ client_connect(char *path, int start_server)
{
struct sockaddr_un sa;
size_t size;
- int fd, mode;
+ int fd;
memset(&sa, 0, sizeof sa);
sa.sun_family = AF_UNIX;
@@ -84,10 +84,7 @@ client_connect(char *path, int start_server)
}
}
- if ((mode = fcntl(fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
+ setblocking(fd, 0);
return (fd);
failed:
diff --git a/cmd-bind-key.c b/cmd-bind-key.c
index 6cf125d..f5d0716 100644
--- a/cmd-bind-key.c
+++ b/cmd-bind-key.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-bind-key.c,v 1.30 2011/01/07 14:45:33 tcunha Exp $ */
+/* $Id: cmd-bind-key.c,v 1.31 2011/01/22 00:00:23 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -45,7 +45,7 @@ int
cmd_bind_key_check(struct args *args)
{
if (args_has(args, 't')) {
- if (args->argc != 1)
+ if (args->argc != 2)
return (-1);
} else {
if (args->argc < 2)
@@ -99,9 +99,9 @@ cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
return (-1);
}
- cmd = mode_key_fromstring(mtab->cmdstr, args->argv[0]);
+ cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]);
if (cmd == MODEKEY_NONE) {
- ctx->error(ctx, "unknown command: %s", args->argv[0]);
+ ctx->error(ctx, "unknown command: %s", args->argv[1]);
return (-1);
}
diff --git a/cmd-new-session.c b/cmd-new-session.c
index 3844aa0..77968ec 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-new-session.c,v 1.82 2011/01/07 14:45:34 tcunha Exp $ */
+/* $Id: cmd-new-session.c,v 1.83 2011/01/21 23:55:26 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <pwd.h>
+#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
@@ -34,8 +35,9 @@ int cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_new_session_entry = {
"new-session", "new",
- "dn:s:t:", 0, 1,
- "[-d] [-n window-name] [-s session-name] [-t target-session] [command]",
+ "dn:s:t:x:y:", 0, 1,
+ "[-d] [-n window-name] [-s session-name] [-t target-session] "
+ "[-x width] [-y height] [command]",
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON,
NULL,
cmd_new_session_check,
@@ -47,6 +49,9 @@ cmd_new_session_check(struct args *args)
{
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n')))
return (-1);
+ if (!args_has(args, 'd') &&
+ (args_has(args, 'x') || args_has(args, 'y')))
+ return (-1);
return (0);
}
@@ -60,7 +65,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
struct environ env;
struct termios tio, *tiop;
struct passwd *pw;
- const char *newname, *target, *update, *cwd;
+ const char *newname, *target, *update, *cwd, *errstr;
char *overrides, *cmd, *cause;
int detached, idx;
u_int sx, sy, i;
@@ -149,6 +154,22 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
if (detached) {
sx = 80;
sy = 24;
+ if (args_has(args, 'x')) {
+ sx = strtonum(
+ args_get(args, 'x'), 1, USHRT_MAX, &errstr);
+ if (errstr != NULL) {
+ ctx->error(ctx, "width %s", errstr);
+ return (-1);
+ }
+ }
+ if (args_has(args, 'y')) {
+ sy = strtonum(
+ args_get(args, 'y'), 1, USHRT_MAX, &errstr);
+ if (errstr != NULL) {
+ ctx->error(ctx, "height %s", errstr);
+ return (-1);
+ }
+ }
} else if (ctx->cmdclient != NULL) {
sx = ctx->cmdclient->tty.sx;
sy = ctx->cmdclient->tty.sy;
diff --git a/cmd-pipe-pane.c b/cmd-pipe-pane.c
index c19a90c..2549a6e 100644
--- a/cmd-pipe-pane.c
+++ b/cmd-pipe-pane.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-pipe-pane.c,v 1.16 2011/01/07 14:45:34 tcunha Exp $ */
+/* $Id: cmd-pipe-pane.c,v 1.17 2011/01/21 23:44:13 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <[email protected]>
@@ -52,7 +52,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
struct client *c;
struct window_pane *wp;
char *command;
- int old_fd, pipe_fd[2], null_fd, mode;
+ int old_fd, pipe_fd[2], null_fd;
if ((c = cmd_find_client(ctx, NULL)) == NULL)
return (-1);
@@ -126,10 +126,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
NULL, NULL, cmd_pipe_pane_error_callback, wp);
bufferevent_enable(wp->pipe_event, EV_WRITE);
- if ((mode = fcntl(wp->pipe_fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(wp->pipe_fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
+ setblocking(wp->pipe_fd, 0);
return (0);
}
}
diff --git a/cmd-server-info.c b/cmd-server-info.c
index b919f9e..9954153 100644
--- a/cmd-server-info.c
+++ b/cmd-server-info.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-server-info.c,v 1.41 2011/01/07 14:45:34 tcunha Exp $ */
+/* $Id: cmd-server-info.c,v 1.42 2011/01/21 23:51:36 tcunha Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <[email protected]>
@@ -88,10 +88,11 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
if (c == NULL || c->session == NULL)
continue;
- ctx->print(ctx, "%2d: %s (%d, %d): %s [%ux%u %s] "
+ ctx->print(ctx,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho] "
"[flags=0x%x/0x%x, references=%u]", i, c->tty.path,
c->ibuf.fd, c->tty.fd, c->session->name,
- c->tty.sx, c->tty.sy, c->tty.termname, c->flags,
+ c->tty.sx, c->tty.sy, c->tty.termname,
+ c->tty.tio.c_cc[VERASE], c->flags,
c->tty.flags, c->references);
}
ctx->print(ctx, "%s", "");
diff --git a/cmd-unbind-key.c b/cmd-unbind-key.c
index d3c33e0..8bf0fc6 100644
--- a/cmd-unbind-key.c
+++ b/cmd-unbind-key.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-unbind-key.c,v 1.24 2011/01/07 14:45:34 tcunha Exp $ */
+/* $Id: cmd-unbind-key.c,v 1.25 2011/01/21 23:46:09 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -31,7 +31,7 @@ int cmd_unbind_key_table(struct cmd *, struct cmd_ctx *, int);
const struct cmd_entry cmd_unbind_key_entry = {
"unbind-key", "unbind",
- "acnt:", 1, 1,
+ "acnt:", 0, 1,
"[-acn] [-t key-table] key",
0,
NULL,
@@ -43,6 +43,8 @@ int
cmd_unbind_key_check(struct args *args)
{
if (args_has(args, 'a') && (args->argc != 0 || args_has(args, 't')))
+ return (-1);
+ if (!args_has(args, 'a') && args->argc != 1)
return (-1);
return (0);
}
diff --git a/colour.c b/colour.c
index db5e4f4..b10a612 100644
--- a/colour.c
+++ b/colour.c
@@ -1,4 +1,4 @@
-/* $Id: colour.c,v 1.7 2009/09/11 14:13:52 tcunha Exp $ */
+/* $Id: colour.c,v 1.8 2011/01/21 23:42:14 tcunha Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <[email protected]>
@@ -18,6 +18,8 @@
#include <sys/types.h>
+#include <ctype.h>
+#include <math.h>
#include <stdlib.h>
#include <string.h>
@@ -28,6 +30,101 @@
* of the 256 colour palette.
*/
+/* An RGB colour. */
+struct colour_rgb {
+ u_char r;
+ u_char g;
+ u_char b;
+};
+
+/* 256 colour RGB table, generated on first use. */
+struct colour_rgb *colour_rgb_256;
+
+void colour_rgb_generate256(void);
+double colour_rgb_distance(struct colour_rgb *, struct colour_rgb *);
+int colour_rgb_find(struct colour_rgb *);
+
+/* Generate 256 colour RGB table. */
+void
+colour_rgb_generate256(void)
+{
+ struct colour_rgb *rgb;
+ u_int i, r, g, b;
+
+ /*
+ * Allocate the table. The first 16 colours are often changed by users
+ * and terminals so don't include them.
+ */
+ colour_rgb_256 = xcalloc(240, sizeof *colour_rgb_256);
+
+ /* Add the colours first. */
+ r = g = b = 0;
+ for (i = 240; i > 24; i--) {
+ rgb = &colour_rgb_256[240 - i];
+
+ if (r != 0)
+ rgb->r = (r * 40) + 55;
+ if (g != 0)
+ rgb->g = (g * 40) + 55;
+ if (b != 0)
+ rgb->b = (b * 40) + 55;
+
+ b++;
+ if (b > 5) {
+ b = 0;
+ g++;
+ }
+ if (g > 5) {
+ g = 0;
+ r++;
+ }
+ }
+
+ /* Then add the greys. */
+ for (i = 24; i > 0; i--) {
+ rgb = &colour_rgb_256[240 - i];
+
+ rgb->r = 8 + (24 - i) * 10;
+ rgb->g = 8 + (24 - i) * 10;
+ rgb->b = 8 + (24 - i) * 10;
+ }
+}
+
+/* Get colour RGB distance. */
+double
+colour_rgb_distance(struct colour_rgb *rgb1, struct colour_rgb *rgb2)
+{
+ int r, g, b;
+
+ r = rgb1->r - rgb2->r;
+ g = rgb1->g - rgb2->g;
+ b = rgb1->b - rgb2->b;
+ return (sqrt(r * r + g * g + b * b));
+}
+
+/* Work out the nearest colour from the 256 colour set. */
+int
+colour_rgb_find(struct colour_rgb *rgb)
+{
+ double distance, lowest;
+ u_int colour, i;
+
+ if (colour_rgb_256 == NULL)
+ colour_rgb_generate256();
+
+ colour = 16;
+ lowest = INFINITY;
+ for (i = 0; i < 240; i++) {
+ distance = colour_rgb_distance(&colour_rgb_256[i], rgb);
+ if (distance < lowest) {
+ lowest = distance;
+ colour = 16 + i;
+ }
+ }
+ return (colour);
+}
+
+/* Set grid cell foreground colour. */
void
colour_set_fg(struct grid_cell *gc, int c)
{
@@ -36,6 +133,7 @@ colour_set_fg(struct grid_cell *gc, int c)
gc->fg = c;
}
+/* Set grid cell background colour. */
void
colour_set_bg(struct grid_cell *gc, int c)
{
@@ -44,6 +142,7 @@ colour_set_bg(struct grid_cell *gc, int c)
gc->bg = c;
}
+/* Convert colour to a string. */
const char *
colour_tostring(int c)
{
@@ -77,11 +176,25 @@ colour_tostring(int c)
return (NULL);
}
+/* Convert colour from string. */
int
colour_fromstring(const char *s)
{
- const char *errstr;
- int n;
+ const char *errstr;
+ const char *cp;
+ struct colour_rgb rgb;
+ int n;
+
+ if (*s == '#' && strlen(s) == 7) {
+ for (cp = s + 1; isxdigit((u_char) *cp); cp++)
+ ;
+ if (*cp != '\0')
+ return (-1);
+ n = sscanf(s + 1, "%2hhx%2hhx%2hhx", &rgb.r, &rgb.g, &rgb.b);
+ if (n != 3)
+ return (-1);
+ return (colour_rgb_find(&rgb) | 0x100);
+ }
if (strncasecmp(s, "colour", (sizeof "colour") - 1) == 0) {
n = strtonum(s + (sizeof "colour") - 1, 0, 255, &errstr);
@@ -111,6 +224,7 @@ colour_fromstring(const char *s)
return (-1);
}
+/* Convert 256 colour palette to 16. */
u_char
colour_256to16(u_char c)
{
@@ -136,6 +250,7 @@ colour_256to16(u_char c)
return (table[c]);
}
+/* Convert 256 colour palette to 88. */
u_char
colour_256to88(u_char c)
{
diff --git a/configure.ac b/configure.ac
index e7afeaf..001d4ca 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-# $Id: configure.ac,v 1.13 2011/01/21 20:35:20 nicm Exp $
+# $Id: configure.ac,v 1.14 2011/01/21 23:40:30 tcunha Exp $
# Miscellaneous autofoo bullshit.
AC_INIT(tmux, 1.5)
@@ -122,6 +122,9 @@ AC_SEARCH_LIBS(inet_ntoa, nsl)
AC_SEARCH_LIBS(socket, socket)
AC_CHECK_LIB(xnet, socket)
+# Look for sqrt.
+AC_SEARCH_LIBS(sqrt, m)
+
# Check for CMSG_DATA. Some platforms require _XOPEN_SOURCE_EXTENDED (for
# example see xopen_networking(7) on HP-UX).
XOPEN_DEFINES=
diff --git a/input.c b/input.c
index 2296162..5030294 100644
--- a/input.c
+++ b/input.c
@@ -1,4 +1,4 @@
-/* $Id: input.c,v 1.113 2011/01/07 14:34:45 tcunha Exp $ */
+/* $Id: input.c,v 1.114 2011/01/21 23:56:11 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -1201,10 +1201,6 @@ input_csi_dispatch(struct input_ctx *ictx)
screen_write_mousemode_on(
&ictx->ctx, MODE_MOUSE_STANDARD);
break;
- case 1001:
- screen_write_mousemode_on(
- &ictx->ctx, MODE_MOUSE_HIGHLIGHT);
- break;
case 1002:
screen_write_mousemode_on(
&ictx->ctx, MODE_MOUSE_BUTTON);
diff --git a/job.c b/job.c
index 2624215..9fd249b 100644
--- a/job.c
+++ b/job.c
@@ -1,4 +1,4 @@
-/* $Id: job.c,v 1.19 2010/10/24 00:45:57 tcunha Exp $ */
+/* $Id: job.c,v 1.20 2011/01/21 23:44:13 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <[email protected]>
@@ -136,7 +136,7 @@ job_free(struct job *job)
int
job_run(struct job *job)
{
- int nullfd, out[2], mode;
+ int nullfd, out[2];
if (job->fd != -1 || job->pid != -1)
return (0);
@@ -176,10 +176,7 @@ job_run(struct job *job)
close(out[1]);
job->fd = out[0];
- if ((mode = fcntl(job->fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(job->fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
+ setblocking(job->fd, 0);
if (job->event != NULL)
bufferevent_free(job->event);
diff --git a/options-table.c b/options-table.c
index 721456b..96ffd28 100644
--- a/options-table.c
+++ b/options-table.c
@@ -1,4 +1,4 @@
-/* $Id: options-table.c,v 1.3 2011/01/07 14:34:45 tcunha Exp $ */
+/* $Id: options-table.c,v 1.4 2011/01/21 23:54:19 tcunha Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <[email protected]>
@@ -149,7 +149,7 @@ const struct options_table_entry session_options_table[] = {
{ .name = "history-limit",
.type = OPTIONS_TABLE_NUMBER,
.minimum = 0,
- .maximum = SHRT_MAX,
+ .maximum = INT_MAX,
.default_num = 2000
},
diff --git a/server-client.c b/server-client.c
index d19ab68..a67c498 100644
--- a/server-client.c
+++ b/server-client.c
@@ -1,4 +1,4 @@
-/* $Id: server-client.c,v 1.51 2011/01/07 14:34:45 tcunha Exp $ */
+/* $Id: server-client.c,v 1.53 2011/01/21 23:56:53 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <[email protected]>
@@ -52,13 +52,9 @@ void
server_client_create(int fd)
{
struct client *c;
- int mode;
u_int i;
- if ((mode = fcntl(fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
+ setblocking(fd, 0);
c = xcalloc(1, sizeof *c);
c->references = 0;
@@ -123,16 +119,22 @@ server_client_lost(struct client *c)
if (c->flags & CLIENT_TERMINAL)
tty_free(&c->tty);
- if (c->stdin_fd != -1)
+ if (c->stdin_fd != -1) {
+ setblocking(c->stdin_fd, 1);
close(c->stdin_fd);
+ }
if (c->stdin_event != NULL)
bufferevent_free(c->stdin_event);
- if (c->stdout_fd != -1)
+ if (c->stdout_fd != -1) {
+ setblocking(c->stdout_fd, 1);
close(c->stdout_fd);
+ }
if (c->stdout_event != NULL)
bufferevent_free(c->stdout_event);
- if (c->stderr_fd != -1)
+ if (c->stderr_fd != -1) {
+ setblocking(c->stderr_fd, 1);
close(c->stderr_fd);
+ }
if (c->stderr_event != NULL)
bufferevent_free(c->stderr_event);
@@ -446,9 +448,14 @@ server_client_reset_state(struct client *c)
else
tty_cursor(&c->tty, wp->xoff + s->cx, wp->yoff + s->cy);
+ /*
+ * Any mode will do for mouse-select-pane, but set standard mode if
+ * none.
+ */
mode = s->mode;
if (TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry) != NULL &&
- options_get_number(oo, "mouse-select-pane"))
+ options_get_number(oo, "mouse-select-pane") &&
+ (mode & ALL_MOUSE_MODES) == 0)
mode |= MODE_MOUSE_STANDARD;
/*
@@ -631,6 +638,7 @@ server_client_in_callback(
return;
bufferevent_disable(c->stdin_event, EV_READ|EV_WRITE);
+ setblocking(c->stdin_fd, 1);
close(c->stdin_fd);
c->stdin_fd = -1;
@@ -646,6 +654,7 @@ server_client_out_callback(
struct client *c = data;
bufferevent_disable(c->stdout_event, EV_READ|EV_WRITE);
+ setblocking(c->stdout_fd, 1);
close(c->stdout_fd);
c->stdout_fd = -1;
}
@@ -658,6 +667,7 @@ server_client_err_callback(
struct client *c = data;
bufferevent_disable(c->stderr_event, EV_READ|EV_WRITE);
+ setblocking(c->stderr_fd, 1);
close(c->stderr_fd);
c->stderr_fd = -1;
}
@@ -671,7 +681,6 @@ server_client_msg_dispatch(struct client *c)
struct msg_identify_data identifydata;
struct msg_environ_data environdata;
ssize_t n, datalen;
- int mode;
if ((n = imsg_read(&c->ibuf)) == -1 || n == 0)
return (-1);
@@ -711,9 +720,7 @@ server_client_msg_dispatch(struct client *c)
NULL, NULL, server_client_in_callback, c);
if (c->stdin_event == NULL)
fatalx("failed to create stdin event");
-
- if ((mode = fcntl(c->stdin_fd, F_GETFL)) != -1)
- fcntl(c->stdin_fd, F_SETFL, mode|O_NONBLOCK);
+ setblocking(c->stdin_fd, 0);
server_client_msg_identify(c, &identifydata, imsg.fd);
break;
@@ -728,9 +735,8 @@ server_client_msg_dispatch(struct client *c)
NULL, NULL, server_client_out_callback, c);
if (c->stdout_event == NULL)
fatalx("failed to create stdout event");
+ setblocking(c->stdout_fd, 0);
- if ((mode = fcntl(c->stdout_fd, F_GETFL)) != -1)
- fcntl(c->stdout_fd, F_SETFL, mode|O_NONBLOCK);
break;
case MSG_STDERR:
if (datalen != 0)
@@ -743,9 +749,8 @@ server_client_msg_dispatch(struct client *c)
NULL, NULL, server_client_err_callback, c);
if (c->stderr_event == NULL)
fatalx("failed to create stderr event");
+ setblocking(c->stderr_fd, 0);
- if ((mode = fcntl(c->stderr_fd, F_GETFL)) != -1)
- fcntl(c->stderr_fd, F_SETFL, mode|O_NONBLOCK);
break;
case MSG_RESIZE:
if (datalen != 0)
diff --git a/server.c b/server.c
index 532f480..4206c6b 100644
--- a/server.c
+++ b/server.c
@@ -1,4 +1,4 @@
-/* $Id: server.c,v 1.251 2011/01/03 23:27:54 tcunha Exp $ */
+/* $Id: server.c,v 1.252 2011/01/21 23:44:13 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -73,7 +73,7 @@ server_create_socket(void)
struct sockaddr_un sa;
size_t size;
mode_t mask;
- int fd, mode;
+ int fd;
memset(&sa, 0, sizeof sa);
sa.sun_family = AF_UNIX;
@@ -94,11 +94,7 @@ server_create_socket(void)
if (listen(fd, 16) == -1)
fatal("listen failed");
-
- if ((mode = fcntl(fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
+ setblocking(fd, 0);
server_update_socket();
diff --git a/session.c b/session.c
index e212a80..7c2b991 100644
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
-/* $Id: session.c,v 1.85 2011/01/03 23:27:54 tcunha Exp $ */
+/* $Id: session.c,v 1.87 2011/01/21 23:53:01 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -180,12 +180,9 @@ session_next_session(struct session *s)
if (RB_EMPTY(&sessions) || !session_alive(s))
return (NULL);
- s2 = s;
- do {
- s2 = RB_NEXT(sessions, &sessions, s2);
- if (s2 == NULL)
- s2 = RB_MIN(sessions, &sessions);
- } while (s2 != s);
+ s2 = RB_NEXT(sessions, &sessions, s);
+ if (s2 == NULL)
+ s2 = RB_MIN(sessions, &sessions);
if (s2 == s)
return (NULL);
return (s2);
@@ -200,12 +197,9 @@ session_previous_session(struct session *s)
if (RB_EMPTY(&sessions) || !session_alive(s))
return (NULL);
- s2 = s;
- do {
- s2 = RB_PREV(sessions, &sessions, s2);
- if (s2 == NULL)
- s2 = RB_MAX(sessions, &sessions);
- } while (s2 != s);
+ s2 = RB_PREV(sessions, &sessions, s);
+ if (s2 == NULL)
+ s2 = RB_MAX(sessions, &sessions);
if (s2 == s)
return (NULL);
return (s2);
diff --git a/tmux.1 b/tmux.1
index 51e5a77..caf86a6 100644
--- a/tmux.1
+++ b/tmux.1
@@ -1,4 +1,4 @@
-.\" $Id: tmux.1,v 1.289 2011/01/13 19:59:48 nicm Exp $
+.\" $Id: tmux.1,v 1.295 2011/01/21 23:55:26 tcunha Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <[email protected]>
.\"
@@ -134,7 +134,10 @@ will report an error and exit without executing further commands.
.It Fl L Ar socket-name
.Nm
stores the server socket in a directory under
-.Pa /tmp ;
+.Pa /tmp
+(or
+.Ev TMPDIR
+if set);
the default socket is named
.Em default .
This option allows a different socket name to be specified, allowing several
@@ -592,6 +595,8 @@ Lock all clients attached to
.Op Fl n Ar window-name
.Op Fl s Ar session-name
.Op Fl t Ar target-session
+.Op Fl x Ar width
+.Op Fl y Ar height
.Op Ar shell-command
.Xc
.D1 (alias: Ic new )
@@ -605,6 +610,13 @@ is given.
and
.Ar shell-command
are the name of and shell command to execute in the initial window.
+If
+.Fl d
+is used,
+.Fl x
+and
+.Fl y
+specify the size of the initial window (80 by 24 if not given).
.Pp
If run from a terminal, any
.Xr termios 4
@@ -1632,16 +1644,19 @@ Available server options are:
Set the number of buffers; as new buffers are added to the top of the stack,
old ones are removed from the bottom if necessary to maintain this maximum
length.
-.It Ic escape-time
+.It Ic escape-time Ar time
Set the time in milliseconds for which
.Nm
waits after an escape is input to determine if it is part of a function or meta
key sequences.
The default is 500 milliseconds.
-.It Ic exit-unattached
-If enabled, the server will exit when there are no attached clients, rather
-than when there are no attached sessions.
-.It Ic quiet
+.It Xo Ic exit-unattached
+.Op Ic on | off
+.Xc
+If enabled, the server will exit when there are no attached clients.
+.It Xo Ic quiet
+.Op Ic on | off
+.Xc
Enable or disable the display of various informational messages (see also the
.Fl q
command line flag).
@@ -1709,10 +1724,14 @@ to work correctly, this
be set to
.Ql screen
or a derivative of it.
-.It Ic destroy-unattached
+.It Xo Ic destroy-unattached
+.Op Ic on | off
+.Xc
If enabled and the session is no longer attached to any clients, it is
destroyed.
-.It Ic detach-on-destroy
+.It Xo Ic detach-on-destroy
+.Op Ic on | off
+.Xc
If on (the default), the client is detached when the session it is attached to
is destroyed.
If off, the client is switched to the most recently active of the remaining
@@ -1797,8 +1816,11 @@ is one of:
.Ic colour0
to
.Ic colour255
-from the 256-colour palette, or
-.Ic default .
+from the 256-colour set,
+.Ic default ,
+or a hexadecimal RGB string such as
+.Ql #ffffff ,
+which chooses the closest match from the default 256-colour set.
.It Ic message-fg Ar colour
Set status line message foreground colour.
.It Ic message-limit Ar number
@@ -2144,8 +2166,11 @@ may use the terminal alternate screen feature, which allows the
and
.Em rmcup
.Xr terminfo 5
-capabilities to be issued to preserve the existing window content on start and
-restore it on exit.
+capabilities.
+The alternate screen feature preserves the contents of the window when an
+interactive application starts and restores it on exit, so that any output
+visible before the application starts reappears unchanged after it exits.
+The default is on.
.Pp
.It Xo Ic automatic-rename
.Op Ic on | off
diff --git a/tmux.c b/tmux.c
index e6777c1..504c726 100644
--- a/tmux.c
+++ b/tmux.c
@@ -1,4 +1,4 @@
-/* $Id: tmux.c,v 1.233 2011/01/07 14:34:45 tcunha Exp $ */
+/* $Id: tmux.c,v 1.235 2011/01/21 23:46:50 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -172,12 +172,15 @@ parseenvironment(void)
char *
makesocketpath(const char *label)
{
- char base[MAXPATHLEN], *path;
+ char base[MAXPATHLEN], *path, *s;
struct stat sb;
u_int uid;
uid = getuid();
- xsnprintf(base, MAXPATHLEN, "%s/tmux-%d", _PATH_TMP, uid);
+ if ((s = getenv("TMPDIR")) == NULL || *s == '\0')
+ xsnprintf(base, sizeof base, "%s/tmux-%u", _PATH_TMP, uid);
+ else
+ xsnprintf(base, sizeof base, "%s/tmux-%u", s, uid);
if (mkdir(base, S_IRWXU) != 0 && errno != EEXIST)
return (NULL);
@@ -197,12 +200,25 @@ makesocketpath(const char *label)
return (path);
}
+void
+setblocking(int fd, int state)
+{
+ int mode;
+
+ if ((mode = fcntl(fd, F_GETFL)) != -1) {
+ if (!state)
+ mode |= O_NONBLOCK;
+ else
+ mode &= ~O_NONBLOCK;
+ fcntl(fd, F_SETFL, mode);
+ }
+}
+
__dead void
shell_exec(const char *shell, const char *shellcmd)
{
const char *shellname, *ptr;
char *argv0;
- int mode;
ptr = strrchr(shell, '/');
if (ptr != NULL && *(ptr + 1) != '\0')
@@ -215,12 +231,9 @@ shell_exec(const char *shell, const char *shellcmd)
xasprintf(&argv0, "%s", shellname);
setenv("SHELL", shell, 1);
- if ((mode = fcntl(STDIN_FILENO, F_GETFL)) != -1)
- fcntl(STDIN_FILENO, F_SETFL, mode & ~O_NONBLOCK);
- if ((mode = fcntl(STDOUT_FILENO, F_GETFL)) != -1)
- fcntl(STDOUT_FILENO, F_SETFL, mode & ~O_NONBLOCK);
- if ((mode = fcntl(STDERR_FILENO, F_GETFL)) != -1)
- fcntl(STDERR_FILENO, F_SETFL, mode & ~O_NONBLOCK);
+ setblocking(STDIN_FILENO, 1);
+ setblocking(STDOUT_FILENO, 1);
+ setblocking(STDERR_FILENO, 1);
closefrom(STDERR_FILENO + 1);
execl(shell, argv0, "-c", shellcmd, (char *) NULL);
diff --git a/tmux.h b/tmux.h
index 4647f02..798ae6d 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.603 2011/01/07 16:55:40 tcunha Exp $ */
+/* $Id: tmux.h,v 1.605 2011/01/21 23:56:11 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -543,13 +543,11 @@ struct mode_key_table {
#define MODE_KKEYPAD 0x8 /* set = application, clear = number */
#define MODE_WRAP 0x10 /* whether lines wrap */
#define MODE_MOUSE_STANDARD 0x20
-#define MODE_MOUSE_HIGHLIGHT 0x40
-#define MODE_MOUSE_BUTTON 0x80
-#define MODE_MOUSE_ANY 0x100
-#define MODE_MOUSE_UTF8 0x200
+#define MODE_MOUSE_BUTTON 0x40
+#define MODE_MOUSE_ANY 0x80
+#define MODE_MOUSE_UTF8 0x100
-#define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD| \
- MODE_MOUSE_HIGHLIGHT|MODE_MOUSE_BUTTON|MODE_MOUSE_ANY)
+#define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON|MODE_MOUSE_ANY)
/*
* A single UTF-8 character.
@@ -1304,6 +1302,7 @@ void logfile(const char *);
const char *getshell(void);
int checkshell(const char *);
int areshell(const char *);
+void setblocking(int, int);
__dead void shell_exec(const char *, const char *);
/* cfg.c */
diff --git a/tty.c b/tty.c
index 4d113cd..4637a59 100644
--- a/tty.c
+++ b/tty.c
@@ -1,4 +1,4 @@
-/* $Id: tty.c,v 1.199 2011/01/07 14:34:45 tcunha Exp $ */
+/* $Id: tty.c,v 1.202 2011/01/21 23:56:53 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -165,15 +165,11 @@ void
tty_start_tty(struct tty *tty)
{
struct termios tio;
- int mode;
if (tty->fd == -1)
return;
- if ((mode = fcntl(tty->fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(tty->fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
+ setblocking(tty->fd, 0);
bufferevent_enable(tty->event, EV_READ|EV_WRITE);
@@ -220,7 +216,6 @@ void
tty_stop_tty(struct tty *tty)
{
struct winsize ws;
- int mode;
if (!(tty->flags & TTY_STARTED))
return;
@@ -251,8 +246,7 @@ tty_stop_tty(struct tty *tty)
tty_raw(tty, tty_term_string(tty->term, TTYC_RMCUP));
- if ((mode = fcntl(tty->fd, F_GETFL)) != -1)
- fcntl(tty->fd, F_SETFL, mode & ~O_NONBLOCK);
+ setblocking(tty->fd, 1);
}
void
@@ -407,23 +401,19 @@ tty_update_mode(struct tty *tty, int mode)
if (mode & ALL_MOUSE_MODES) {
if (mode & MODE_MOUSE_UTF8)
tty_puts(tty, "\033[?1005h");
- if (mode & MODE_MOUSE_STANDARD)
- tty_puts(tty, "\033[?1000h");
- else if (mode & MODE_MOUSE_HIGHLIGHT)
- tty_puts(tty, "\033[?1001h");
+ if (mode & MODE_MOUSE_ANY)
+ tty_puts(tty, "\033[?1003h");
else if (mode & MODE_MOUSE_BUTTON)
tty_puts(tty, "\033[?1002h");
- else if (mode & MODE_MOUSE_ANY)
- tty_puts(tty, "\033[?1003h");
+ else if (mode & MODE_MOUSE_STANDARD)
+ tty_puts(tty, "\033[?1000h");
} else {
- if (tty->mode & MODE_MOUSE_STANDARD)
- tty_puts(tty, "\033[?1000l");
- else if (tty->mode & MODE_MOUSE_HIGHLIGHT)
- tty_puts(tty, "\033[?1001l");
+ if (tty->mode & MODE_MOUSE_ANY)
+ tty_puts(tty, "\033[?1003l");
else if (tty->mode & MODE_MOUSE_BUTTON)
tty_puts(tty, "\033[?1002l");
- else if (tty->mode & MODE_MOUSE_ANY)
- tty_puts(tty, "\033[?1003l");
+ else if (tty->mode & MODE_MOUSE_STANDARD)
+ tty_puts(tty, "\033[?1000l");
if (tty->mode & MODE_MOUSE_UTF8)
tty_puts(tty, "\033[?1005l");
}
diff --git a/window.c b/window.c
index fca7057..aa7accc 100644
--- a/window.c
+++ b/window.c
@@ -1,4 +1,4 @@
-/* $Id: window.c,v 1.143 2011/01/07 16:55:40 tcunha Exp $ */
+/* $Id: window.c,v 1.144 2011/01/21 23:44:13 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -560,7 +560,6 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
const char *cwd, struct environ *env, struct termios *tio, char **cause)
{
struct winsize ws;
- int mode;
char *argv0;
const char *ptr;
struct termios tio2;
@@ -634,10 +633,8 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
fatal("execl failed");
}
- if ((mode = fcntl(wp->fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(wp->fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
+ setblocking(wp->fd, 0);
+
wp->event = bufferevent_new(wp->fd,
window_pane_read_callback, NULL, window_pane_error_callback, wp);
bufferevent_enable(wp->event, EV_READ|EV_WRITE);