Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added pane titles to tmux. (Working proof of concept, but can still b…

…e improved.)
  • Loading branch information...
commit dfab5e957c7e52af87b5473bd0899093b3abb074 1 parent 4b0ed56
@jonathanslenders authored
View
57 cmd-rename-pane.c
@@ -0,0 +1,57 @@
+/* $Id$ */
+
+/*
+ * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
+ *
+ * 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 <stdlib.h>
+
+#include "tmux.h"
+
+/*
+ * Rename a window.
+ */
+
+enum cmd_retval cmd_rename_pane_exec(struct cmd *, struct cmd_q *);
+
+const struct cmd_entry cmd_rename_pane_entry = {
+ "rename-pane", "renamep",
+ "t:", 1, 1,
+ CMD_TARGET_WINDOW_USAGE " new-name",
+ 0,
+ NULL,
+ NULL,
+ cmd_rename_pane_exec
+};
+
+
+enum cmd_retval
+cmd_rename_pane_exec(struct cmd *self, struct cmd_q *cmdq)
+{
+ struct args *args = self->args;
+ struct window_pane *wp;
+ struct winlink *wl;
+
+ if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
+ return (CMD_RETURN_ERROR);
+
+ pane_set_name(wp, args->argv[0]);
+
+ server_redraw_window(wl->window);
+
+ return (CMD_RETURN_NORMAL);
+}
View
1  cmd.c
@@ -82,6 +82,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_refresh_client_entry,
&cmd_rename_session_entry,
&cmd_rename_window_entry,
+ &cmd_rename_pane_entry,
&cmd_resize_pane_entry,
&cmd_respawn_pane_entry,
&cmd_respawn_window_entry,
View
37 layout.c
@@ -163,6 +163,30 @@ layout_fix_offsets(struct layout_cell *lc)
}
}
+/* Returns 1 if we need to reserve space for the pane title bar.
+ This is the case for the most upper panes ony. */
+int
+need_title_space(struct layout_cell *lc)
+{
+ struct layout_cell * first_lc;
+
+ if (lc->parent) {
+ if (lc->parent->type == LAYOUT_LEFTRIGHT)
+ return need_title_space(lc->parent);
+ else if (lc->parent->type == LAYOUT_TOPBOTTOM)
+ {
+ first_lc = TAILQ_FIRST(&(lc->parent->cells));
+ if (lc == first_lc)
+ return need_title_space(lc->parent);
+ else
+ return 0;
+ }
+ }
+ else
+ // The most parent pane always needs to have title space.
+ return 1;
+}
+
/* Update pane offsets and sizes based on their cells. */
void
layout_fix_panes(struct window *w, u_int wsx, u_int wsy)
@@ -170,13 +194,21 @@ layout_fix_panes(struct window *w, u_int wsx, u_int wsy)
struct window_pane *wp;
struct layout_cell *lc;
u_int sx, sy;
+ int i = 0;
+ int show_pane_title;
TAILQ_FOREACH(wp, &w->panes, entry) {
if ((lc = wp->layout_cell) == NULL)
continue;
+
+ show_pane_title = need_title_space(lc);
+
wp->xoff = lc->xoff;
wp->yoff = lc->yoff;
+ if (show_pane_title)
+ wp->yoff += 1;
+
/*
* Layout cells are limited by the smallest size of other cells
* within the same row or column; if this isn't the case
@@ -214,7 +246,12 @@ layout_fix_panes(struct window *w, u_int wsx, u_int wsy)
sy = lc->sy;
}
+ if (show_pane_title)
+ sy -= 1;
+
window_pane_resize(wp, sx, sy);
+
+ i += 1;
}
}
View
84 screen-redraw.c
@@ -27,7 +27,8 @@ int screen_redraw_cell_border(struct client *, u_int, u_int);
int screen_redraw_check_cell(struct client *, u_int, u_int,
struct window_pane **);
int screen_redraw_check_active(u_int, u_int, int, struct window *,
- struct window_pane *);
+ struct window_pane *);
+char * strip_title(char *title, int length);
void screen_redraw_draw_number(struct client *, struct window_pane *);
@@ -45,7 +46,9 @@ void screen_redraw_draw_number(struct client *, struct window_pane *);
#define CELL_JOIN 11
#define CELL_OUTSIDE 12
-#define CELL_BORDERS " xqlkmjwvtun~"
+/* #define CELL_BORDERS " xqlkmjwvtun~" */
+#define CELL_BORDERS " xqlkmjwqtun~" /* XXX: Not correct. I changed one symbol to
+ get the upper border correct with pane titles. */
/* Check if cell is on the border of a particular pane. */
int
@@ -214,6 +217,47 @@ screen_redraw_check_active(u_int px, u_int py, int type, struct window *w,
return (type);
}
+/* Copy string in new string, limited by length or first newline. */
+char *
+strip_title(char *title, int length)
+{
+ char *result;
+ int pos;
+
+ result = xmalloc(length + 1);
+
+ /* We take one character padding, left and right */
+ length -= 1;
+ pos = 0;
+ result[pos] = ' ';
+ pos ++;
+
+ while (*title && pos < length) {
+ /* Convert newlines to spaces */
+ if (*title == '\n' || *title == '\r')
+ result[pos] = ' ';
+ else
+ result[pos] = *title;
+
+ pos ++;
+ title ++;
+ }
+
+ /* dots if the string has been trimmed */
+ if (pos == length && pos > 3) {
+ result[pos-1] = '.';
+ result[pos-2] = '.';
+ result[pos-3] = '.';
+ }
+
+ /* Trailing padding */
+ result[pos] = ' ';
+
+ result[pos+1] = NULL;
+
+ return result;
+}
+
/* Redraw entire screen. */
void
screen_redraw_screen(struct client *c, int status_only, int borders_only)
@@ -222,9 +266,10 @@ screen_redraw_screen(struct client *c, int status_only, int borders_only)
struct options *oo = &c->session->options;
struct tty *tty = &c->tty;
struct window_pane *wp;
- struct grid_cell active_gc, other_gc;
+ struct grid_cell active_gc, other_gc, active_title_gc, other_title_gc;
u_int i, j, type, top;
int status, spos, fg, bg;
+ char *stripped_title;
/* Suspended clients should not be updated. */
if (c->flags & CLIENT_SUSPENDED)
@@ -253,15 +298,21 @@ screen_redraw_screen(struct client *c, int status_only, int borders_only)
/* Set up pane border attributes. */
memcpy(&other_gc, &grid_marker_cell, sizeof other_gc);
memcpy(&active_gc, &grid_marker_cell, sizeof active_gc);
+ memcpy(&other_title_gc, &grid_marker_cell, sizeof other_title_gc);
+ memcpy(&active_title_gc, &grid_marker_cell, sizeof active_title_gc);
active_gc.attr = other_gc.attr = GRID_ATTR_CHARSET;
fg = options_get_number(oo, "pane-border-fg");
colour_set_fg(&other_gc, fg);
+ colour_set_bg(&other_title_gc, fg); /* TODO: maybe we better create some new settings for the pane title colours. */
bg = options_get_number(oo, "pane-border-bg");
colour_set_bg(&other_gc, bg);
+ colour_set_fg(&other_title_gc, bg);
fg = options_get_number(oo, "pane-active-border-fg");
colour_set_fg(&active_gc, fg);
+ colour_set_bg(&active_title_gc, fg);
bg = options_get_number(oo, "pane-active-border-bg");
colour_set_bg(&active_gc, bg);
+ colour_set_fg(&active_title_gc, bg);
/* Draw background and borders. */
for (j = 0; j < tty->sy - status; j++) {
@@ -302,6 +353,33 @@ screen_redraw_screen(struct client *c, int status_only, int borders_only)
tty_draw_line(
tty, wp->screen, i, wp->xoff, top + wp->yoff);
}
+
+ /* Pane title */
+ tty_cursor(tty, wp->xoff + 2, top + wp->yoff - 1);
+
+ if (wp == w->active)
+ //tty_attributes(tty, &active_gc);
+ tty_attributes(tty, &active_title_gc);
+ else
+ //tty_attributes(tty, &other_gc);
+ tty_attributes(tty, &other_title_gc);
+
+ if (wp->name) {
+ stripped_title = strip_title(wp->name, wp->sx - 4);
+ tty_puts(tty, stripped_title);
+ free(stripped_title);
+ }
+ else {
+ char* proc_name = osdep_get_name(wp->fd, tty);
+ stripped_title = strip_title(proc_name, wp->sx - 4);
+ //tty_puts(tty, " (Untitled) ");
+ tty_puts(tty, stripped_title);
+ free(stripped_title);
+ free(proc_name);
+ }
+
+ tty_cursor(tty, 0, 0);
+
if (c->flags & CLIENT_IDENTIFY)
screen_redraw_draw_number(c, wp);
}
View
3  tmux.h
@@ -942,6 +942,7 @@ struct window_pane {
char *cmd;
char *shell;
char *cwd;
+ char *name;
pid_t pid;
char tty[TTY_NAME_MAX];
@@ -1807,6 +1808,7 @@ extern const struct cmd_entry cmd_previous_window_entry;
extern const struct cmd_entry cmd_refresh_client_entry;
extern const struct cmd_entry cmd_rename_session_entry;
extern const struct cmd_entry cmd_rename_window_entry;
+extern const struct cmd_entry cmd_rename_pane_entry;
extern const struct cmd_entry cmd_resize_pane_entry;
extern const struct cmd_entry cmd_respawn_pane_entry;
extern const struct cmd_entry cmd_respawn_window_entry;
@@ -2179,6 +2181,7 @@ struct window_pane *window_pane_find_down(struct window_pane *);
struct window_pane *window_pane_find_left(struct window_pane *);
struct window_pane *window_pane_find_right(struct window_pane *);
void window_set_name(struct window *, const char *);
+void pane_set_name(struct window_pane *, const char *);
void window_remove_ref(struct window *);
void winlink_clear_flags(struct winlink *);
void window_mode_attrs(struct grid_cell *, struct options *);
View
9 window.c
@@ -377,6 +377,14 @@ window_set_name(struct window *w, const char *new_name)
}
void
+pane_set_name(struct window_pane *wp, const char *new_name)
+{
+ free(wp->name);
+ wp->name = xstrdup(new_name);
+ // notify_pane_renamed(wp);
+}
+
+void
window_resize(struct window *w, u_int sx, u_int sy)
{
w->sx = sx;
@@ -673,6 +681,7 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
wp->cmd = NULL;
wp->shell = NULL;
wp->cwd = NULL;
+ wp->name = NULL;
wp->fd = -1;
wp->event = NULL;
Please sign in to comment.
Something went wrong with that request. Please try again.