mirror of
https://github.com/tmux/tmux.git
synced 2025-01-07 16:28:48 +00:00
Sync OpenBSD patchset 965:
Add client formats, from Ben Boeckel.
This commit is contained in:
parent
653d1e2fc8
commit
1c1797e4f2
@ -31,8 +31,8 @@ int cmd_list_clients_exec(struct cmd *, struct cmd_ctx *);
|
|||||||
|
|
||||||
const struct cmd_entry cmd_list_clients_entry = {
|
const struct cmd_entry cmd_list_clients_entry = {
|
||||||
"list-clients", "lsc",
|
"list-clients", "lsc",
|
||||||
"t:", 0, 0,
|
"F:t:", 0, 0,
|
||||||
CMD_TARGET_SESSION_USAGE,
|
"[-F format] " CMD_TARGET_SESSION_USAGE,
|
||||||
CMD_READONLY,
|
CMD_READONLY,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
@ -43,11 +43,13 @@ const struct cmd_entry cmd_list_clients_entry = {
|
|||||||
int
|
int
|
||||||
cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct args *args = self->args;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
u_int i;
|
struct format_tree *ft;
|
||||||
const char *s_utf8;
|
const char *template;
|
||||||
|
u_int i;
|
||||||
|
char *line;
|
||||||
|
|
||||||
if (args_has(args, 't')) {
|
if (args_has(args, 't')) {
|
||||||
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||||
@ -56,22 +58,32 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
} else
|
} else
|
||||||
s = NULL;
|
s = NULL;
|
||||||
|
|
||||||
|
template = args_get(args, 'F');
|
||||||
|
if (template == NULL) {
|
||||||
|
template = "#{client_tty}: #{session_name} "
|
||||||
|
"[#{client_width}x#{client_height} #{client_termname}]"
|
||||||
|
"#{?client_utf8, (utf8),}"
|
||||||
|
"#{?client_readonly, (ro),}";
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
c = ARRAY_ITEM(&clients, i);
|
c = ARRAY_ITEM(&clients, i);
|
||||||
if (c == NULL || c->session == NULL)
|
if (c == NULL || c->session == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (c->tty.flags & TTY_UTF8)
|
|
||||||
s_utf8 = " (utf8)";
|
|
||||||
else
|
|
||||||
s_utf8 = "";
|
|
||||||
|
|
||||||
if (s != NULL && s != c->session)
|
if (s != NULL && s != c->session)
|
||||||
continue;
|
continue;
|
||||||
ctx->print(ctx, "%s: %s [%ux%u %s]%s%s", c->tty.path,
|
|
||||||
c->session->name, c->tty.sx, c->tty.sy,
|
ft = format_create();
|
||||||
c->tty.termname, s_utf8,
|
format_add(ft, "line", "%u", i);
|
||||||
c->flags & CLIENT_READONLY ? " (ro)" : "");
|
format_session(ft, c->session);
|
||||||
|
format_client(ft, c);
|
||||||
|
|
||||||
|
line = format_expand(ft, template);
|
||||||
|
ctx->print(ctx, "%s", line);
|
||||||
|
xfree(line);
|
||||||
|
|
||||||
|
format_free(ft);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
|
36
format.c
36
format.c
@ -295,6 +295,42 @@ format_session(struct format_tree *ft, struct session *s)
|
|||||||
format_add(ft, "session_attached", "%d", 1);
|
format_add(ft, "session_attached", "%d", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set default format keys for a client. */
|
||||||
|
void
|
||||||
|
format_client(struct format_tree *ft, struct client *c)
|
||||||
|
{
|
||||||
|
char *tim;
|
||||||
|
time_t t;
|
||||||
|
|
||||||
|
format_add(ft, "client_cwd", "%s", c->cwd);
|
||||||
|
format_add(ft, "client_height", "%u", c->tty.sx);
|
||||||
|
format_add(ft, "client_width", "%u", c->tty.sy);
|
||||||
|
format_add(ft, "client_tty", "%s", c->tty.path);
|
||||||
|
format_add(ft, "client_termname", "%s", c->tty.termname);
|
||||||
|
|
||||||
|
t = c->creation_time.tv_sec;
|
||||||
|
format_add(ft, "client_created", "%ld", (long) t);
|
||||||
|
tim = ctime(&t);
|
||||||
|
*strchr(tim, '\n') = '\0';
|
||||||
|
format_add(ft, "client_created_string", "%s", tim);
|
||||||
|
|
||||||
|
t = c->activity_time.tv_sec;
|
||||||
|
format_add(ft, "client_activity", "%ld", (long) t);
|
||||||
|
tim = ctime(&t);
|
||||||
|
*strchr(tim, '\n') = '\0';
|
||||||
|
format_add(ft, "client_activity_string", "%s", tim);
|
||||||
|
|
||||||
|
if (c->tty.flags & TTY_UTF8)
|
||||||
|
format_add(ft, "client_utf8", "%d", 1);
|
||||||
|
else
|
||||||
|
format_add(ft, "client_utf8", "%d", 0);
|
||||||
|
|
||||||
|
if (c->flags & CLIENT_READONLY)
|
||||||
|
format_add(ft, "client_readonly", "%d", 1);
|
||||||
|
else
|
||||||
|
format_add(ft, "client_readonly", "%d", 0);
|
||||||
|
}
|
||||||
|
|
||||||
/* Set default format keys for a winlink. */
|
/* Set default format keys for a winlink. */
|
||||||
void
|
void
|
||||||
format_winlink(struct format_tree *ft, struct session *s, struct winlink *wl)
|
format_winlink(struct format_tree *ft, struct session *s, struct winlink *wl)
|
||||||
|
23
tmux.1
23
tmux.1
@ -14,7 +14,7 @@
|
|||||||
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: October 2 2011 $
|
.Dd $Mdocdate: October 23 2011 $
|
||||||
.Dt TMUX 1
|
.Dt TMUX 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -610,9 +610,16 @@ server and clients and destroy all sessions.
|
|||||||
.It Ic kill-session Op Fl t Ar target-session
|
.It Ic kill-session Op Fl t Ar target-session
|
||||||
Destroy the given session, closing any windows linked to it and no other
|
Destroy the given session, closing any windows linked to it and no other
|
||||||
sessions, and detaching all clients attached to it.
|
sessions, and detaching all clients attached to it.
|
||||||
.It Ic list-clients Op Fl t Ar target-session
|
.It Xo Ic list-clients
|
||||||
|
.Op Fl F Ar format
|
||||||
|
.Op Fl t Ar target-session
|
||||||
|
.Xc
|
||||||
.D1 (alias: Ic lsc )
|
.D1 (alias: Ic lsc )
|
||||||
List all clients attached to the server.
|
List all clients attached to the server.
|
||||||
|
For the meaning of the
|
||||||
|
.Fl F
|
||||||
|
flag, see the
|
||||||
|
.Sx FORMATS section.
|
||||||
If
|
If
|
||||||
.Ar target-session
|
.Ar target-session
|
||||||
is specified, list only clients connected to that session.
|
is specified, list only clients connected to that session.
|
||||||
@ -2564,6 +2571,7 @@ is used.
|
|||||||
.El
|
.El
|
||||||
.Sh FORMATS
|
.Sh FORMATS
|
||||||
The
|
The
|
||||||
|
.Ic list-clients ,
|
||||||
.Ic list-sessions ,
|
.Ic list-sessions ,
|
||||||
.Ic list-windows
|
.Ic list-windows
|
||||||
and
|
and
|
||||||
@ -2601,6 +2609,17 @@ if it is unattached.
|
|||||||
The following variables are available, where appropriate:
|
The following variables are available, where appropriate:
|
||||||
.Bl -column "session_created_string" "Replaced with" -offset indent
|
.Bl -column "session_created_string" "Replaced with" -offset indent
|
||||||
.It Sy "Variable name" Ta Sy "Replaced with"
|
.It Sy "Variable name" Ta Sy "Replaced with"
|
||||||
|
.It Li "client_activity" Ta "Integer time client last had activity"
|
||||||
|
.It Li "client_activity_string" Ta "String time client last had activity"
|
||||||
|
.It Li "client_created" Ta "Integer time client created"
|
||||||
|
.It Li "client_created_string" Ta "String time client created"
|
||||||
|
.It Li "client_cwd" Ta "Working directory of client"
|
||||||
|
.It Li "client_height" Ta "Height of client"
|
||||||
|
.It Li "client_readonly" Ta "1 if client is readonly"
|
||||||
|
.It Li "client_termname" Ta "Terminal name of client"
|
||||||
|
.It Li "client_tty" Ta "Pseudo terminal of client"
|
||||||
|
.It Li "client_utf8" Ta "1 if client supports utf8"
|
||||||
|
.It Li "client_width" Ta "Width of client"
|
||||||
.It Li "host" Ta "Hostname of local host"
|
.It Li "host" Ta "Hostname of local host"
|
||||||
.It Li "line" Ta "Line number in the list"
|
.It Li "line" Ta "Line number in the list"
|
||||||
.It Li "pane_active" Ta "1 if active pane"
|
.It Li "pane_active" Ta "1 if active pane"
|
||||||
|
1
tmux.h
1
tmux.h
@ -1360,6 +1360,7 @@ void format_add(
|
|||||||
const char *format_find(struct format_tree *, const char *);
|
const char *format_find(struct format_tree *, const char *);
|
||||||
char *format_expand(struct format_tree *, const char *);
|
char *format_expand(struct format_tree *, const char *);
|
||||||
void format_session(struct format_tree *, struct session *);
|
void format_session(struct format_tree *, struct session *);
|
||||||
|
void format_client(struct format_tree *, struct client *);
|
||||||
void format_winlink(
|
void format_winlink(
|
||||||
struct format_tree *, struct session *, struct winlink *);
|
struct format_tree *, struct session *, struct winlink *);
|
||||||
void format_window_pane(struct format_tree *, struct window_pane *);
|
void format_window_pane(struct format_tree *, struct window_pane *);
|
||||||
|
Loading…
Reference in New Issue
Block a user