summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2009-08-16 18:59:12 +0000
committerTiago Cunha <tcunha@gmx.com>2009-08-16 18:59:12 +0000
commitf415d43c3b5cb6f519b171949a6a3eeaacbf6540 (patch)
treef591d6ce7494850f85da15e78c4d0b03525465cb
parent8f9858ba2f2fa410b8e0c20a7763517b6610fcb0 (diff)
Sync OpenBSD patchset 254:
When creating a new session from the command-line where there is an external terminal, copy the termios(4) special characters and use them for new windows created in the new session. Suggested by Theo.
-rw-r--r--cmd-new-session.c27
-rw-r--r--cmd-respawn-window.c4
-rw-r--r--cmd-split-window.c4
-rw-r--r--session.c10
-rw-r--r--tmux.18
-rw-r--r--tmux.h15
-rw-r--r--window.c13
7 files changed, 57 insertions, 24 deletions
diff --git a/cmd-new-session.c b/cmd-new-session.c
index 181d9bb8..9fe267f7 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-new-session.c,v 1.51 2009-08-09 17:48:55 tcunha Exp $ */
+/* $Id: cmd-new-session.c,v 1.52 2009-08-16 18:59:12 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,6 +18,12 @@
#include <sys/types.h>
+#include <string.h>
+#include <termios.h>
+
+#define TTYDEFCHARS
+#include <sys/ttydefaults.h>
+
#include "tmux.h"
/*
@@ -109,6 +115,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
struct cmd_new_session_data *data = self->data;
struct session *s;
struct environ env;
+ struct termios tio;
const char *update;
char *overrides, *cmd, *cwd, *cause;
int detached;
@@ -192,8 +199,24 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
if (ctx->cmdclient != NULL)
environ_update(update, &ctx->cmdclient->environ, &env);
+ /*
+ * Fill in the termios settings used for new windows in this session;
+ * if there is a command client, use the control characters from it.
+ */
+ if (ctx->cmdclient != NULL && ctx->cmdclient->tty.fd != -1) {
+ if (tcgetattr(ctx->cmdclient->tty.fd, &tio) != 0)
+ fatal("tcgetattr failed");
+ } else
+ memcpy(tio.c_cc, ttydefchars, sizeof tio.c_cc);
+ tio.c_iflag = TTYDEF_IFLAG;
+ tio.c_oflag = TTYDEF_OFLAG;
+ tio.c_lflag = TTYDEF_LFLAG;
+ tio.c_cflag = TTYDEF_CFLAG;
+ tio.c_ispeed = TTYDEF_SPEED;
+ tio.c_ospeed = TTYDEF_SPEED;
+
/* Create the new session. */
- s = session_create(data->newname, cmd, cwd, &env, sx, sy, &cause);
+ s = session_create(data->newname, cmd, cwd, &env, &tio, sx, sy, &cause);
if (s == NULL) {
ctx->error(ctx, "create session failed: %s", cause);
xfree(cause);
diff --git a/cmd-respawn-window.c b/cmd-respawn-window.c
index c5888c51..849d40b7 100644
--- a/cmd-respawn-window.c
+++ b/cmd-respawn-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-respawn-window.c,v 1.19 2009-08-09 17:48:55 tcunha Exp $ */
+/* $Id: cmd-respawn-window.c,v 1.20 2009-08-16 18:59:12 tcunha Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -75,7 +75,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
window_destroy_panes(w);
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
window_pane_resize(wp, w->sx, w->sy);
- if (window_pane_spawn(wp, data->arg, NULL, &env, &cause) != 0) {
+ if (window_pane_spawn(wp, data->arg, NULL, &env, &s->tio, &cause) != 0) {
ctx->error(ctx, "respawn window failed: %s", cause);
xfree(cause);
environ_free(&env);
diff --git a/cmd-split-window.c b/cmd-split-window.c
index 07b1f56d..e1697796 100644
--- a/cmd-split-window.c
+++ b/cmd-split-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-split-window.c,v 1.22 2009-08-09 17:48:55 tcunha Exp $ */
+/* $Id: cmd-split-window.c,v 1.23 2009-08-16 18:59:12 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -184,7 +184,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
type = LAYOUT_LEFTRIGHT;
wp = window_add_pane(w, hlimit);
- if (window_pane_spawn(wp, cmd, cwd, &env, &cause) != 0)
+ if (window_pane_spawn(wp, cmd, cwd, &env, &s->tio, &cause) != 0)
goto error;
if (layout_split_pane(w->active, type, size, wp) != 0) {
cause = xstrdup("pane too small");
diff --git a/session.c b/session.c
index 7b9bf26a..b27c94b8 100644
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
-/* $Id: session.c,v 1.60 2009-08-09 17:48:55 tcunha Exp $ */
+/* $Id: session.c,v 1.61 2009-08-16 18:59:12 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -113,7 +113,7 @@ session_find(const char *name)
/* Create a new session. */
struct session *
session_create(const char *name, const char *cmd, const char *cwd,
- struct environ *env, u_int sx, u_int sy, char **cause)
+ struct environ *env, struct termios *tio, u_int sx, u_int sy, char **cause)
{
struct session *s;
u_int i;
@@ -131,6 +131,7 @@ session_create(const char *name, const char *cmd, const char *cwd,
environ_init(&s->environ);
if (env != NULL)
environ_copy(env, &s->environ);
+ memcpy(&s->tio, tio, sizeof s->tio);
s->sx = sx;
s->sy = sy;
@@ -200,7 +201,7 @@ session_index(struct session *s, u_int *i)
/* Create a new window on a session. */
struct winlink *
-session_new(struct session *s,
+session_new(struct session *s,
const char *name, const char *cmd, const char *cwd, int idx, char **cause)
{
struct window *w;
@@ -213,7 +214,8 @@ session_new(struct session *s,
server_fill_environ(s, &env);
hlimit = options_get_number(&s->options, "history-limit");
- w = window_create(name, cmd, cwd, &env, s->sx, s->sy, hlimit, cause);
+ w = window_create(
+ name, cmd, cwd, &env, &s->tio, s->sx, s->sy, hlimit, cause);
if (w == NULL) {
environ_free(&env);
return (NULL);
diff --git a/tmux.1 b/tmux.1
index f58dfc5e..150d08d9 100644
--- a/tmux.1
+++ b/tmux.1
@@ -1,4 +1,4 @@
-.\" $Id: tmux.1,v 1.149 2009-08-10 21:39:15 tcunha Exp $
+.\" $Id: tmux.1,v 1.150 2009-08-16 18:59:12 tcunha Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: August 10 2009 $
+.Dd $Mdocdate: August 13 2009 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -398,6 +398,10 @@ is given.
and
.Ar command
are the name of and command to execute in the initial window.
+.Pp
+If run from a terminal, any
+.Xr termios 4
+special characters are saved and used for new windows in the new session.
.It Ic refresh-client Op Fl t Ar target-client
.D1 (alias: Ic refresh )
Refresh the current client if bound to a key, or a single client if one is given
diff --git a/tmux.h b/tmux.h
index 1e827225..2c021642 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.415 2009-08-14 21:30:24 tcunha Exp $ */
+/* $Id: tmux.h,v 1.416 2009-08-16 18:59:12 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -801,6 +801,8 @@ struct session {
#define SESSION_UNATTACHED 0x1 /* not attached to any clients */
int flags;
+ struct termios tio;
+
struct environ environ;
};
ARRAY_DECL(sessions, struct session *);
@@ -1572,7 +1574,8 @@ void winlink_stack_remove(struct winlink_stack *, struct winlink *);
int window_index(struct window *, u_int *);
struct window *window_create1(u_int, u_int);
struct window *window_create(const char *, const char *, const char *,
- struct environ *, u_int, u_int, u_int, char **);
+ struct environ *, struct termios *, u_int, u_int, u_int,
+ char **);
void window_destroy(struct window *);
void window_set_active_pane(struct window *, struct window_pane *);
struct window_pane *window_add_pane(struct window *, u_int);
@@ -1584,8 +1587,8 @@ u_int window_count_panes(struct window *);
void window_destroy_panes(struct window *);
struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int);
void window_pane_destroy(struct window_pane *);
-int window_pane_spawn(struct window_pane *,
- const char *, const char *, struct environ *, char **);
+int window_pane_spawn(struct window_pane *, const char *,
+ const char *, struct environ *, struct termios *, char **);
void window_pane_resize(struct window_pane *, u_int, u_int);
int window_pane_set_mode(
struct window_pane *, const struct window_mode *);
@@ -1664,8 +1667,8 @@ void session_alert_cancel(struct session *, struct winlink *);
int session_alert_has(struct session *, struct winlink *, int);
int session_alert_has_window(struct session *, struct window *, int);
struct session *session_find(const char *);
-struct session *session_create(const char *, const char *,
- const char *, struct environ *, u_int, u_int, char **);
+struct session *session_create(const char *, const char *, const char *,
+ struct environ *, struct termios *, u_int, u_int, char **);
void session_destroy(struct session *);
int session_index(struct session *, u_int *);
struct winlink *session_new(struct session *,
diff --git a/window.c b/window.c
index 5343479f..77713035 100644
--- a/window.c
+++ b/window.c
@@ -1,4 +1,4 @@
-/* $Id: window.c,v 1.102 2009-08-14 21:28:00 tcunha Exp $ */
+/* $Id: window.c,v 1.103 2009-08-16 18:59:12 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -267,7 +267,8 @@ window_create1(u_int sx, u_int sy)
struct window *
window_create(const char *name, const char *cmd, const char *cwd,
- struct environ *env, u_int sx, u_int sy, u_int hlimit, char **cause)
+ struct environ *env, struct termios *tio, u_int sx, u_int sy, u_int hlimit,
+ char **cause)
{
struct window *w;
struct window_pane *wp;
@@ -275,7 +276,7 @@ window_create(const char *name, const char *cmd, const char *cwd,
w = window_create1(sx, sy);
wp = window_add_pane(w, hlimit);
layout_init(w);
- if (window_pane_spawn(wp, cmd, cwd, env, cause) != 0) {
+ if (window_pane_spawn(wp, cmd, cwd, env, tio, cause) != 0) {
window_destroy(w);
return (NULL);
}
@@ -468,8 +469,8 @@ window_pane_destroy(struct window_pane *wp)
}
int
-window_pane_spawn(struct window_pane *wp,
- const char *cmd, const char *cwd, struct environ *env, char **cause)
+window_pane_spawn(struct window_pane *wp, const char *cmd,
+ const char *cwd, struct environ *env, struct termios *tio, char **cause)
{
struct winsize ws;
int mode;
@@ -503,7 +504,7 @@ window_pane_spawn(struct window_pane *wp,
tv.tv_usec = NAME_INTERVAL * 1000L;
timeradd(&wp->window->name_timer, &tv, &wp->window->name_timer);
- switch (wp->pid = forkpty(&wp->fd, wp->tty, NULL, &ws)) {
+ switch (wp->pid = forkpty(&wp->fd, wp->tty, tio, &ws)) {
case -1:
wp->fd = -1;
xasprintf(cause, "%s: %s", cmd, strerror(errno));