mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-23 00:23:08 +01:00
- New command display-message (alias display) to display a message in the
status line (bound to "i" and displays the current window and time by default). The same substitutions are applied as for status-left/right. - Add support for including the window index (#I), pane index (#P) and window name (#W) in the message, and status-left or status-right. - Bump protocol version. From Tiago Cunha, thanks!
This commit is contained in:
parent
ad006bc6b6
commit
6f5150a943
3
Makefile
3
Makefile
@ -25,7 +25,8 @@ SRCS= attributes.c buffer-poll.c buffer.c cfg.c client-fn.c \
|
||||
cmd-split-window.c cmd-start-server.c cmd-string.c cmd-if-shell.c \
|
||||
cmd-suspend-client.c cmd-swap-pane.c cmd-swap-window.c \
|
||||
cmd-switch-client.c cmd-unbind-key.c cmd-unlink-window.c \
|
||||
cmd-up-pane.c cmd.c colour.c grid-view.c grid.c input-keys.c \
|
||||
cmd-up-pane.c cmd-display-message.c cmd.c \
|
||||
colour.c grid-view.c grid.c input-keys.c \
|
||||
input.c key-bindings.c key-string.c layout-manual.c layout.c log.c \
|
||||
mode-key.c names.c options-cmd.c options.c paste.c procname.c \
|
||||
resize.c screen-redraw.c screen-write.c screen.c server-fn.c \
|
||||
|
65
cmd-display-message.c
Normal file
65
cmd-display-message.c
Normal file
@ -0,0 +1,65 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Displays a message in the status line.
|
||||
*/
|
||||
|
||||
int cmd_display_message_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_display_message_entry = {
|
||||
"display-message", "display",
|
||||
CMD_TARGET_CLIENT_USAGE " [message]",
|
||||
CMD_ARG01, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_display_message_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct client *c;
|
||||
const char *template;
|
||||
char *msg;
|
||||
|
||||
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (data->arg == NULL)
|
||||
template = "[#S] #I:#W, current pane #P - (%H:%M %d-%b-%y)";
|
||||
else
|
||||
template = data->arg;
|
||||
|
||||
msg = status_replace(c->session, template, time(NULL));
|
||||
status_message_set(c, "%s", msg);
|
||||
xfree(msg);
|
||||
|
||||
return (0);
|
||||
}
|
1
cmd.c
1
cmd.c
@ -41,6 +41,7 @@ const struct cmd_entry *cmd_table[] = {
|
||||
&cmd_copy_mode_entry,
|
||||
&cmd_delete_buffer_entry,
|
||||
&cmd_detach_client_entry,
|
||||
&cmd_display_message_entry,
|
||||
&cmd_down_pane_entry,
|
||||
&cmd_find_window_entry,
|
||||
&cmd_has_session_entry,
|
||||
|
@ -119,6 +119,7 @@ key_bindings_init(void)
|
||||
{ 'c', 0, &cmd_new_window_entry },
|
||||
{ 'd', 0, &cmd_detach_client_entry },
|
||||
{ 'f', 0, &cmd_command_prompt_entry },
|
||||
{ 'i', 0, &cmd_display_message_entry },
|
||||
{ 'l', 0, &cmd_last_window_entry },
|
||||
{ 'n', 0, &cmd_next_window_entry },
|
||||
{ 'o', 0, &cmd_down_pane_entry },
|
||||
|
21
status.c
21
status.c
@ -29,7 +29,6 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
char *status_replace(struct session *, char *, time_t);
|
||||
char *status_replace_popen(char **);
|
||||
size_t status_width(struct winlink *);
|
||||
char *status_print(struct session *, struct winlink *, struct grid_cell *);
|
||||
@ -275,7 +274,7 @@ out:
|
||||
}
|
||||
|
||||
char *
|
||||
status_replace(struct session *s, char *fmt, time_t t)
|
||||
status_replace(struct session *s, const char *fmt, time_t t)
|
||||
{
|
||||
struct winlink *wl = s->curw;
|
||||
static char out[BUFSIZ];
|
||||
@ -323,6 +322,20 @@ status_replace(struct session *s, char *fmt, time_t t)
|
||||
ptr = tmp;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
case 'I':
|
||||
if (ptr == NULL) {
|
||||
xsnprintf(tmp, sizeof tmp, "%d", wl->idx);
|
||||
ptr = tmp;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
case 'P':
|
||||
if (ptr == NULL) {
|
||||
xsnprintf(tmp, sizeof tmp, "%u",
|
||||
window_pane_index(wl->window,
|
||||
wl->window->active));
|
||||
ptr = tmp;
|
||||
}
|
||||
/* FALLTHOUGH */
|
||||
case 'S':
|
||||
if (ptr == NULL)
|
||||
ptr = s->name;
|
||||
@ -330,6 +343,10 @@ status_replace(struct session *s, char *fmt, time_t t)
|
||||
case 'T':
|
||||
if (ptr == NULL)
|
||||
ptr = wl->window->active->base.title;
|
||||
/* FALLTHROUGH */
|
||||
case 'W':
|
||||
if (ptr == NULL)
|
||||
ptr = wl->window->name;
|
||||
len = strlen(ptr);
|
||||
if ((size_t) n < len)
|
||||
len = n;
|
||||
|
12
tmux.1
12
tmux.1
@ -717,6 +717,15 @@ or the top buffer if not specified.
|
||||
.D1 (alias: Ic detach )
|
||||
Detach the current client if bound to a key, or the specified client with
|
||||
.Fl t .
|
||||
.It Xo Ic display-message
|
||||
.Op Fl t Ar target-client
|
||||
.Op Ar message
|
||||
.Xc
|
||||
.D1 (alias: Ic display )
|
||||
Display a message (see the
|
||||
.Ic status-left
|
||||
option below)
|
||||
in the status line.
|
||||
.It Xo Ic down-pane
|
||||
.Op Fl p Ar pane-index
|
||||
.Op Fl t Ar target-window
|
||||
@ -1262,8 +1271,11 @@ may contain any of the following special character pairs:
|
||||
.It Sy "Character pair" Ta Sy "Replaced with"
|
||||
.It Li "#(command)" Ta "First line of command's output"
|
||||
.It Li "#H" Ta "Hostname of local host"
|
||||
.It Li "#I" Ta "Current window index"
|
||||
.It Li "#P" Ta "Current pane index"
|
||||
.It Li "#S" Ta "Session name"
|
||||
.It Li "#T" Ta "Current window title"
|
||||
.It Li "#W" Ta "Current window name"
|
||||
.It Li "##" Ta "A literal" Ql #
|
||||
.El
|
||||
.Pp
|
||||
|
5
tmux.h
5
tmux.h
@ -19,7 +19,7 @@
|
||||
#ifndef TMUX_H
|
||||
#define TMUX_H
|
||||
|
||||
#define PROTOCOL_VERSION -13
|
||||
#define PROTOCOL_VERSION -14
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
@ -1110,6 +1110,7 @@ extern const struct cmd_entry cmd_copy_buffer_entry;
|
||||
extern const struct cmd_entry cmd_copy_mode_entry;
|
||||
extern const struct cmd_entry cmd_delete_buffer_entry;
|
||||
extern const struct cmd_entry cmd_detach_client_entry;
|
||||
extern const struct cmd_entry cmd_display_message_entry;
|
||||
extern const struct cmd_entry cmd_down_pane_entry;
|
||||
extern const struct cmd_entry cmd_find_window_entry;
|
||||
extern const struct cmd_entry cmd_has_session_entry;
|
||||
@ -1286,6 +1287,7 @@ int server_unlock(const char *);
|
||||
|
||||
/* status.c */
|
||||
int status_redraw(struct client *);
|
||||
char *status_replace(struct session *, const char *, time_t);
|
||||
void printflike2 status_message_set(struct client *, const char *, ...);
|
||||
void status_message_clear(struct client *);
|
||||
int status_message_redraw(struct client *);
|
||||
@ -1447,6 +1449,7 @@ struct window_pane *window_add_pane(struct window *, int,
|
||||
const char *, const char *, const char **, u_int, char **);
|
||||
void window_remove_pane(struct window *, struct window_pane *);
|
||||
struct window_pane *window_pane_at_index(struct window *, u_int);
|
||||
u_int window_pane_index(struct window *, struct window_pane *);
|
||||
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);
|
||||
|
15
window.c
15
window.c
@ -379,6 +379,21 @@ window_pane_at_index(struct window *w, u_int idx)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
u_int
|
||||
window_pane_index(struct window *w, struct window_pane *wp)
|
||||
{
|
||||
struct window_pane *wq;
|
||||
u_int n;
|
||||
|
||||
n = 0;
|
||||
TAILQ_FOREACH(wq, &w->panes, entry) {
|
||||
if (wp == wq)
|
||||
break;
|
||||
n++;
|
||||
}
|
||||
return (n);
|
||||
}
|
||||
|
||||
u_int
|
||||
window_count_panes(struct window *w)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user