From c1f62f1fdebc3bd000b81bd93dcae6f1a539f345 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 2 Nov 2017 18:27:35 +0000 Subject: Only show the first member of session groups in tree mode (-G flag disables). --- format.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'format.c') diff --git a/format.c b/format.c index aa8396d7..8c5a0698 100644 --- a/format.c +++ b/format.c @@ -572,8 +572,38 @@ format_cb_pane_tabs(struct format_tree *ft, struct format_entry *fe) evbuffer_add(buffer, ",", 1); evbuffer_add_printf(buffer, "%u", i); } - size = EVBUFFER_LENGTH(buffer); - xasprintf(&fe->value, "%.*s", size, EVBUFFER_DATA(buffer)); + if ((size = EVBUFFER_LENGTH(buffer)) != 0) + xasprintf(&fe->value, "%.*s", size, EVBUFFER_DATA(buffer)); + evbuffer_free(buffer); +} + +/* Callback for session_group_others. */ +static void +format_cb_session_group_others(struct format_tree *ft, struct format_entry *fe) +{ + struct session *s = ft->s; + struct session_group *sg; + struct session *loop; + struct evbuffer *buffer; + int size; + + if (s == NULL) + return; + sg = session_group_contains(s); + if (sg == NULL) + return; + + buffer = evbuffer_new(); + TAILQ_FOREACH(loop, &sg->sessions, gentry) { + if (loop == s) + continue; + + if (EVBUFFER_LENGTH(buffer) > 0) + evbuffer_add(buffer, ",", 1); + evbuffer_add_printf(buffer, "%s", loop->name); + } + if ((size = EVBUFFER_LENGTH(buffer)) != 0) + xasprintf(&fe->value, "%.*s", size, EVBUFFER_DATA(buffer)); evbuffer_free(buffer); } @@ -1253,8 +1283,13 @@ format_defaults_session(struct format_tree *ft, struct session *s) sg = session_group_contains(s); format_add(ft, "session_grouped", "%d", sg != NULL); - if (sg != NULL) + if (sg != NULL) { format_add(ft, "session_group", "%s", sg->name); + format_add(ft, "session_group_size", "%u", + session_group_count (sg)); + format_add_cb(ft, "session_group_others", + format_cb_session_group_others); + } format_add_tv(ft, "session_created", &s->creation_time); format_add_tv(ft, "session_last_attached", &s->last_attached_time); -- cgit From 95850e1aca6697df784d02c24a0ca997f82f90f7 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 2 Nov 2017 18:43:51 +0000 Subject: Tweak previous slightly so that current session is chosen if it is in the group rather than first. --- format.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'format.c') diff --git a/format.c b/format.c index 8c5a0698..e254eb22 100644 --- a/format.c +++ b/format.c @@ -795,8 +795,11 @@ format_find(struct format_tree *ft, const char *key, int modifiers) found = s; goto found; } - if (fe->value == NULL && fe->cb != NULL) + if (fe->value == NULL && fe->cb != NULL) { fe->cb(ft, fe); + if (fe->value == NULL) + fe->value = xstrdup(""); + } found = fe->value; goto found; } -- cgit From 17655e5ba65e37787cd9920e1a89aedf6f623957 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 2 Nov 2017 18:52:05 +0000 Subject: Format for group list of "other sessions" is a bit weird, just list all the sessions in the group. --- format.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'format.c') diff --git a/format.c b/format.c index e254eb22..1b967c93 100644 --- a/format.c +++ b/format.c @@ -577,9 +577,9 @@ format_cb_pane_tabs(struct format_tree *ft, struct format_entry *fe) evbuffer_free(buffer); } -/* Callback for session_group_others. */ +/* Callback for session_group_list. */ static void -format_cb_session_group_others(struct format_tree *ft, struct format_entry *fe) +format_cb_session_group_list(struct format_tree *ft, struct format_entry *fe) { struct session *s = ft->s; struct session_group *sg; @@ -595,9 +595,6 @@ format_cb_session_group_others(struct format_tree *ft, struct format_entry *fe) buffer = evbuffer_new(); TAILQ_FOREACH(loop, &sg->sessions, gentry) { - if (loop == s) - continue; - if (EVBUFFER_LENGTH(buffer) > 0) evbuffer_add(buffer, ",", 1); evbuffer_add_printf(buffer, "%s", loop->name); @@ -1290,8 +1287,8 @@ format_defaults_session(struct format_tree *ft, struct session *s) format_add(ft, "session_group", "%s", sg->name); format_add(ft, "session_group_size", "%u", session_group_count (sg)); - format_add_cb(ft, "session_group_others", - format_cb_session_group_others); + format_add_cb(ft, "session_group_list", + format_cb_session_group_list); } format_add_tv(ft, "session_created", &s->creation_time); -- cgit