1
0
mirror of https://github.com/tmate-io/tmate-ssh-server.git synced 2020-11-18 19:53:51 -08:00

Mark windows in yellow on status line when bell.

This commit is contained in:
Nicholas Marriott 2007-10-12 11:24:15 +00:00
parent d158938178
commit ad4a7423c0
10 changed files with 105 additions and 45 deletions

View File

@ -1,3 +1,7 @@
12 October 2007
* (nicm) Make status line mark window in yellow on bell.
04 October 2007 04 October 2007
* (nicm) -d option to attach to detach all other clients on the same session. * (nicm) -d option to attach to detach all other clients on the same session.
@ -118,5 +122,5 @@
(including mutt, emacs). No status bar yet and no key remapping or other (including mutt, emacs). No status bar yet and no key remapping or other
customisation. customisation.
$Id: CHANGES,v 1.36 2007-10-04 21:21:48 nicm Exp $ $Id: CHANGES,v 1.37 2007-10-12 11:24:14 nicm Exp $

3
TODO
View File

@ -45,8 +45,7 @@
-- For 0.1 -------------------------------------------------------------------- -- For 0.1 --------------------------------------------------------------------
- man page - man page
- sort out bell: passing through should be optional, and toolbar should change - sort out bell: passing through should be optional
window colour or something
- commands: - commands:
refresh session (similar to detach: -a for all, else if key redraw cur, refresh session (similar to detach: -a for all, else if key redraw cur,
else do nothing) else do nothing)

View File

@ -1,4 +1,4 @@
/* $Id: client-msg.c,v 1.8 2007-10-05 14:23:28 nicm Exp $ */ /* $Id: client-msg.c,v 1.9 2007-10-12 11:24:15 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -67,7 +67,6 @@ client_msg_dispatch(struct client_ctx *cctx, char **error)
return (0); return (0);
} }
} }
if (i == NCLIENTMSG)
fatalx("unexpected message"); fatalx("unexpected message");
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-new-window.c,v 1.7 2007-10-04 22:04:01 nicm Exp $ */ /* $Id: cmd-new-window.c,v 1.8 2007-10-12 11:24:15 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -112,14 +112,8 @@ cmd_new_window_exec(void *ptr, struct cmd_ctx *ctx)
if (!data->flag_detached) { if (!data->flag_detached) {
session_select(s, i); session_select(s, i);
server_redraw_session(s); server_redraw_session(s);
} else { } else
/* XXX */ server_status_session(s);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c != NULL && c->session == s)
server_redraw_status(c);
}
}
if (!(ctx->flags & CMD_KEY)) if (!(ctx->flags & CMD_KEY))
server_write_client(c, MSG_EXIT, NULL, 0); server_write_client(c, MSG_EXIT, NULL, 0);

View File

@ -1,4 +1,4 @@
/* $Id: cmd-rename-window.c,v 1.4 2007-10-04 22:04:01 nicm Exp $ */ /* $Id: cmd-rename-window.c,v 1.5 2007-10-12 11:24:15 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -97,7 +97,6 @@ cmd_rename_window_exec(void *ptr, struct cmd_ctx *ctx)
struct client *c = ctx->client; struct client *c = ctx->client;
struct session *s = ctx->session; struct session *s = ctx->session;
struct window *w; struct window *w;
u_int i;
if (data == NULL) if (data == NULL)
return; return;
@ -111,12 +110,7 @@ cmd_rename_window_exec(void *ptr, struct cmd_ctx *ctx)
xfree(w->name); xfree(w->name);
w->name = xstrdup(data->newname); w->name = xstrdup(data->newname);
/*XXX*/ server_status_session(s);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c != NULL && c->session == s)
server_redraw_status(c);
}
if (!(ctx->flags & CMD_KEY)) if (!(ctx->flags & CMD_KEY))
server_write_client(c, MSG_EXIT, NULL, 0); server_write_client(c, MSG_EXIT, NULL, 0);

View File

@ -1,4 +1,4 @@
/* $Id: server-fn.c,v 1.19 2007-10-04 19:22:26 nicm Exp $ */ /* $Id: server-fn.c,v 1.20 2007-10-12 11:24:15 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -123,7 +123,7 @@ server_write_window(
} }
void void
server_redraw_status(struct client *c) server_status_client(struct client *c)
{ {
struct hdr hdr; struct hdr hdr;
size_t size; size_t size;
@ -192,7 +192,7 @@ server_redraw_client(struct client *c)
} else } else
buffer_reverse_add(c->out, sizeof hdr); buffer_reverse_add(c->out, sizeof hdr);
server_redraw_status(c); server_status_client(c);
} }
void void
@ -208,6 +208,19 @@ server_redraw_session(struct session *s)
} }
} }
void
server_status_session(struct session *s)
{
struct client *c;
u_int i;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c != NULL && c->session == s)
server_status_client(c);
}
}
void void
server_clear_window(struct window *w) server_clear_window(struct window *w)
{ {
@ -234,6 +247,21 @@ server_redraw_window(struct window *w)
} }
} }
void
server_status_window(struct window *w)
{
struct client *c;
u_int i;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c == NULL || c->session == NULL)
continue;
if (session_has(c->session, w))
server_status_client(c);
}
}
void void
server_write_message(struct client *c, const char *fmt, ...) server_write_message(struct client *c, const char *fmt, ...)
{ {

View File

@ -1,4 +1,4 @@
/* $Id: server.c,v 1.26 2007-10-04 21:21:48 nicm Exp $ */ /* $Id: server.c,v 1.27 2007-10-12 11:24:15 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -322,10 +322,9 @@ server_lost_client(struct client *c)
void void
server_handle_window(struct window *w) server_handle_window(struct window *w)
{ {
struct client *c;
struct session *s;
struct buffer *b; struct buffer *b;
u_int i, j; struct session *s;
u_int i;
b = buffer_create(BUFSIZ); b = buffer_create(BUFSIZ);
window_data(w, b); window_data(w, b);
@ -338,16 +337,12 @@ server_handle_window(struct window *w)
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
s = ARRAY_ITEM(&sessions, i); s = ARRAY_ITEM(&sessions, i);
if (s == NULL || !session_has(s, w)) if (s != NULL)
continue; session_addbell(s, w);
}
for (j = 0; j < ARRAY_LENGTH(&clients); j++) { server_write_window(w, MSG_DATA, "\007", 1);
c = ARRAY_ITEM(&clients, j); server_status_window(w);
if (c == NULL || c->session != s)
continue;
server_write_client(c, MSG_DATA, "\007", 1);
}
}
w->flags &= ~WINDOW_BELL; w->flags &= ~WINDOW_BELL;
} }

View File

@ -1,4 +1,4 @@
/* $Id: session.c,v 1.21 2007-10-03 23:32:26 nicm Exp $ */ /* $Id: session.c,v 1.22 2007-10-12 11:24:15 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,6 +27,36 @@
/* Global session list. */ /* Global session list. */
struct sessions sessions; struct sessions sessions;
void
session_cancelbell(struct session *s, struct window *w)
{
u_int i;
if (window_index(&s->bells, w, &i) == 0)
window_remove(&s->bells, w);
}
void
session_addbell(struct session *s, struct window *w)
{
u_int i;
/* Never bell in the current window. */
if (w == s->window || !session_has(s, w))
return;
if (window_index(&s->bells, w, &i) != 0)
window_add(&s->bells, w);
}
int
session_hasbell(struct session *s, struct window *w)
{
u_int i;
return (window_index(&s->bells, w, &i) == 0);
}
/* Find session by name. */ /* Find session by name. */
struct session * struct session *
session_find(const char *name) session_find(const char *name)
@ -54,6 +84,7 @@ session_create(const char *name, const char *cmd, u_int sx, u_int sy)
s->tim = time(NULL); s->tim = time(NULL);
s->window = s->last = NULL; s->window = s->last = NULL;
ARRAY_INIT(&s->windows); ARRAY_INIT(&s->windows);
ARRAY_INIT(&s->bells);
s->sx = sx; s->sx = sx;
s->sy = sy; s->sy = sy;
@ -186,6 +217,7 @@ session_next(struct session *s)
return (0); return (0);
s->last = s->window; s->last = s->window;
s->window = w; s->window = w;
session_cancelbell(s, w);
return (0); return (0);
} }
@ -208,6 +240,7 @@ session_previous(struct session *s)
return (0); return (0);
s->last = s->window; s->last = s->window;
s->window = w; s->window = w;
session_cancelbell(s, w);
return (0); return (0);
} }
@ -224,6 +257,7 @@ session_select(struct session *s, u_int i)
return (0); return (0);
s->last = s->window; s->last = s->window;
s->window = w; s->window = w;
session_cancelbell(s, w);
return (0); return (0);
} }
@ -241,5 +275,6 @@ session_last(struct session *s)
s->last = s->window; s->last = s->window;
s->window = w; s->window = w;
session_cancelbell(s, w);
return (0); return (0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: status.c,v 1.3 2007-10-04 19:03:52 nicm Exp $ */ /* $Id: status.c,v 1.4 2007-10-12 11:24:15 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -42,8 +42,13 @@ status_write(struct client *c)
w = ARRAY_ITEM(&c->session->windows, i); w = ARRAY_ITEM(&c->session->windows, i);
if (w == NULL) if (w == NULL)
continue; continue;
if (session_hasbell(c->session, w))
input_store_two(b, CODE_ATTRIBUTES, ATTR_REVERSE, 0x30);
status_print(b, &size, status_print(b, &size,
"%u:%s%s ", i, w->name, w == c->session->window ? "*" : ""); "%u:%s%s", i, w->name, w == c->session->window ? "*" : "");
if (session_hasbell(c->session, w))
input_store_two(b, CODE_ATTRIBUTES, ATTR_REVERSE, 0x20);
status_print(b, &size, " ");
if (size == 0) if (size == 0)
break; break;
} }

11
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.53 2007-10-10 19:45:20 nicm Exp $ */ /* $Id: tmux.h,v 1.54 2007-10-12 11:24:15 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -410,6 +410,8 @@ struct session {
struct window *last; struct window *last;
struct windows windows; struct windows windows;
struct windows bells; /* windows with bells */
#define SESSION_UNATTACHED 0x1 /* not attached to any clients */ #define SESSION_UNATTACHED 0x1 /* not attached to any clients */
int flags; int flags;
}; };
@ -567,10 +569,12 @@ void server_write_session(
struct session *, enum hdrtype, const void *, size_t); struct session *, enum hdrtype, const void *, size_t);
void server_write_window( void server_write_window(
struct window *, enum hdrtype, const void *, size_t); struct window *, enum hdrtype, const void *, size_t);
void server_redraw_status(struct client *); void server_status_client(struct client *);
void server_clear_client(struct client *); void server_clear_client(struct client *);
void server_redraw_client(struct client *); void server_redraw_client(struct client *);
void server_status_session(struct session *);
void server_redraw_session(struct session *); void server_redraw_session(struct session *);
void server_status_window(struct window *);
void server_clear_window(struct window *); void server_clear_window(struct window *);
void server_redraw_window(struct window *); void server_redraw_window(struct window *);
void server_write_message(struct client *, const char *, ...); void server_write_message(struct client *, const char *, ...);
@ -647,6 +651,9 @@ void window_data(struct window *, struct buffer *);
/* session.c */ /* session.c */
extern struct sessions sessions; extern struct sessions sessions;
void session_cancelbell(struct session *, struct window *);
void session_addbell(struct session *, struct window *);
int session_hasbell(struct session *, struct window *);
struct session *session_find(const char *); struct session *session_find(const char *);
struct session *session_create(const char *, const char *, u_int, u_int); struct session *session_create(const char *, const char *, u_int, u_int);
void session_destroy(struct session *); void session_destroy(struct session *);