aboutsummaryrefslogtreecommitdiff
path: root/format.c
diff options
context:
space:
mode:
Diffstat (limited to 'format.c')
-rw-r--r--format.c104
1 files changed, 90 insertions, 14 deletions
diff --git a/format.c b/format.c
index 5f57c72e..d70b7678 100644
--- a/format.c
+++ b/format.c
@@ -32,8 +32,9 @@
* string.
*/
-int format_replace(struct format_tree *,
- const char *, size_t, char **, size_t *, size_t *);
+int format_replace(struct format_tree *, const char *, size_t, char **,
+ size_t *, size_t *);
+void format_window_pane_tabs(struct format_tree *, struct window_pane *);
/* Format key-value replacement entry. */
RB_GENERATE(format_tree, format_entry, entry, format_cmp);
@@ -251,10 +252,11 @@ format_expand(struct format_tree *ft, const char *fmt)
continue;
}
}
- while (len - off < 2) {
+ while (len - off < 3) {
buf = xrealloc(buf, 2, len);
len *= 2;
}
+ buf[off++] = '#';
buf[off++] = ch;
continue;
}
@@ -278,6 +280,7 @@ format_session(struct format_tree *ft, struct session *s)
format_add(ft, "session_windows", "%u", winlink_count(&s->windows));
format_add(ft, "session_width", "%u", s->sx);
format_add(ft, "session_height", "%u", s->sy);
+ format_add(ft, "session_id", "$%u", s->id);
sg = session_group_find(s);
format_add(ft, "session_grouped", "%d", sg != NULL);
@@ -300,8 +303,9 @@ format_session(struct format_tree *ft, struct session *s)
void
format_client(struct format_tree *ft, struct client *c)
{
- char *tim;
- time_t t;
+ char *tim;
+ time_t t;
+ struct session *s;
format_add(ft, "client_cwd", "%s", c->cwd);
format_add(ft, "client_height", "%u", c->tty.sy);
@@ -321,6 +325,8 @@ format_client(struct format_tree *ft, struct client *c)
*strchr(tim, '\n') = '\0';
format_add(ft, "client_activity_string", "%s", tim);
+ format_add(ft, "client_prefix", "%d", !!(c->flags & CLIENT_PREFIX));
+
if (c->tty.flags & TTY_UTF8)
format_add(ft, "client_utf8", "%d", 1);
else
@@ -330,6 +336,13 @@ format_client(struct format_tree *ft, struct client *c)
format_add(ft, "client_readonly", "%d", 1);
else
format_add(ft, "client_readonly", "%d", 0);
+
+ s = c->session;
+ if (s != NULL)
+ format_add(ft, "client_session", "%s", s->name);
+ s = c->last_session;
+ if (s != NULL && session_alive(s))
+ format_add(ft, "client_last_session", "%s", s->name);
}
/* Set default format keys for a winlink. */
@@ -356,6 +369,28 @@ format_winlink(struct format_tree *ft, struct session *s, struct winlink *wl)
free(layout);
}
+/* Add window pane tabs. */
+void
+format_window_pane_tabs(struct format_tree *ft, struct window_pane *wp)
+{
+ struct evbuffer *buffer;
+ u_int i;
+
+ buffer = evbuffer_new();
+ for (i = 0; i < wp->base.grid->sx; i++) {
+ if (!bit_test(wp->base.tabs, i))
+ continue;
+
+ if (EVBUFFER_LENGTH(buffer) > 0)
+ evbuffer_add(buffer, ",", 1);
+ evbuffer_add_printf(buffer, "%d", i);
+ }
+
+ format_add(ft, "pane_tabs", "%.*s", (int) EVBUFFER_LENGTH(buffer),
+ EVBUFFER_DATA(buffer));
+ evbuffer_free(buffer);
+}
+
/* Set default format keys for a window pane. */
void
format_window_pane(struct format_tree *ft, struct window_pane *wp)
@@ -363,9 +398,9 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp)
struct grid *gd = wp->base.grid;
struct grid_line *gl;
unsigned long long size;
- u_int i;
- u_int idx;
+ u_int i, idx;
const char *cwd;
+ char *cmd;
size = 0;
for (i = 0; i < gd->hsize; i++) {
@@ -373,31 +408,72 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp)
size += gl->cellsize * sizeof *gl->celldata;
}
size += gd->hsize * sizeof *gd->linedata;
+ format_add(ft, "history_size", "%u", gd->hsize);
+ format_add(ft, "history_limit", "%u", gd->hlimit);
+ format_add(ft, "history_bytes", "%llu", size);
if (window_pane_index(wp, &idx) != 0)
fatalx("index not found");
+ format_add(ft, "pane_index", "%u", idx);
format_add(ft, "pane_width", "%u", wp->sx);
format_add(ft, "pane_height", "%u", wp->sy);
format_add(ft, "pane_title", "%s", wp->base.title);
- format_add(ft, "pane_index", "%u", idx);
- format_add(ft, "history_size", "%u", gd->hsize);
- format_add(ft, "history_limit", "%u", gd->hlimit);
- format_add(ft, "history_bytes", "%llu", size);
format_add(ft, "pane_id", "%%%u", wp->id);
format_add(ft, "pane_active", "%d", wp == wp->window->active);
format_add(ft, "pane_dead", "%d", wp->fd == -1);
+
+ format_add(ft, "pane_in_mode", "%d", wp->screen != &wp->base);
+
+ if (wp->tty != NULL)
+ format_add(ft, "pane_tty", "%s", wp->tty);
+ format_add(ft, "pane_pid", "%ld", (long) wp->pid);
if (wp->cmd != NULL)
format_add(ft, "pane_start_command", "%s", wp->cmd);
if (wp->cwd != NULL)
format_add(ft, "pane_start_path", "%s", wp->cwd);
if ((cwd = osdep_get_cwd(wp->fd)) != NULL)
format_add(ft, "pane_current_path", "%s", cwd);
- format_add(ft, "pane_pid", "%ld", (long) wp->pid);
- if (wp->tty != NULL)
- format_add(ft, "pane_tty", "%s", wp->tty);
+ if ((cmd = get_proc_name(wp->fd, wp->tty)) != NULL) {
+ format_add(ft, "pane_current_command", "%s", cmd);
+ free(cmd);
+ }
+
+ format_add(ft, "cursor_x", "%d", wp->base.cx);
+ format_add(ft, "cursor_y", "%d", wp->base.cy);
+ format_add(ft, "scroll_region_upper", "%d", wp->base.rupper);
+ format_add(ft, "scroll_region_lower", "%d", wp->base.rlower);
+ format_add(ft, "saved_cursor_x", "%d", wp->ictx.old_cx);
+ format_add(ft, "saved_cursor_y", "%d", wp->ictx.old_cy);
+
+ format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0);
+ format_add(ft, "alternate_saved_x", "%d", wp->saved_cx);
+ format_add(ft, "alternate_saved_y", "%d", wp->saved_cy);
+
+ format_add(ft, "cursor_flag", "%d",
+ !!(wp->base.mode & MODE_CURSOR));
+ format_add(ft, "insert_flag", "%d",
+ !!(wp->base.mode & MODE_INSERT));
+ format_add(ft, "keypad_cursor_flag", "%d",
+ !!(wp->base.mode & MODE_KCURSOR));
+ format_add(ft, "keypad_flag", "%d",
+ !!(wp->base.mode & MODE_KKEYPAD));
+ format_add(ft, "wrap_flag", "%d",
+ !!(wp->base.mode & MODE_WRAP));
+
+ format_add(ft, "mouse_standard_flag", "%d",
+ !!(wp->base.mode & MODE_MOUSE_STANDARD));
+ format_add(ft, "mouse_button_flag", "%d",
+ !!(wp->base.mode & MODE_MOUSE_BUTTON));
+ format_add(ft, "mouse_any_flag", "%d",
+ !!(wp->base.mode & MODE_MOUSE_ANY));
+ format_add(ft, "mouse_utf8_flag", "%d",
+ !!(wp->base.mode & MODE_MOUSE_UTF8));
+
+ format_window_pane_tabs(ft, wp);
}
+/* Set default format keys for paste buffer. */
void
format_paste_buffer(struct format_tree *ft, struct paste_buffer *pb)
{