On Tue, Jan 29, 2013 at 7:15 AM, Nicholas Marriott
<nicholas.marri...@gmail.com> wrote:
>
> Can you send a unified diff to the mailing list please?

Sure thing.  See below.

>From df6f6960cb469bf5a5f6332697186afd1d568ab5 Mon Sep 17 00:00:00 2001
From: Richard Woodbury <rpwoo...@google.com>
Date: Sun, 27 Jan 2013 16:44:49 -0500
Subject: [PATCH] Implement reflow-pane and reflow window option.

---
 Makefile.am         |    1 +
 cmd-reflow-pane.c   |   49 ++++++++++++++++++++++++++++++++++++++++++++++++
 cmd-select-layout.c |    3 +++
 cmd.c               |    1 +
 grid.c              |   52 +++++++++++++++++++++++++++++++++++++++++++++++++++
 notify.c            |    1 +
 options-table.c     |    5 +++++
 tmux.h              |    4 ++++
 window.c            |   25 +++++++++++++++++++++++++
 9 files changed, 141 insertions(+)
 create mode 100644 cmd-reflow-pane.c

diff --git a/Makefile.am b/Makefile.am
index 672208b..25e81ad 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -101,6 +101,7 @@ dist_tmux_SOURCES = \
  cmd-new-window.c \
  cmd-paste-buffer.c \
  cmd-pipe-pane.c \
+ cmd-reflow-pane.c \
  cmd-refresh-client.c \
  cmd-rename-session.c \
  cmd-rename-window.c \
diff --git a/cmd-reflow-pane.c b/cmd-reflow-pane.c
new file mode 100644
index 0000000..377e98a
--- /dev/null
+++ b/cmd-reflow-pane.c
@@ -0,0 +1,49 @@
+/* $Id$ */
+
+/*
+ * Copyright (c) 2013 Richard Woodbury <rpwoo...@google.com>
+ *
+ * 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 "tmux.h"
+
+/*
+ * Reflow text in a pane to suit its current size.
+ */
+
+enum cmd_retval cmd_reflow_pane_exec(struct cmd *, struct cmd_ctx *);
+
+const struct cmd_entry cmd_reflow_pane_entry = {
+ "reflow-pane", "reflow",
+ "t:", 0, 0,
+ CMD_TARGET_PANE_USAGE,
+ 0,
+ NULL,
+ NULL,
+ cmd_reflow_pane_exec
+};
+
+enum cmd_retval
+cmd_reflow_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
+{
+ struct args *args = self->args;
+ struct window_pane *wp;
+
+ if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
+ return (CMD_RETURN_ERROR);
+
+ window_pane_reflow(wp);
+
+ return (CMD_RETURN_NORMAL);
+}
diff --git a/cmd-select-layout.c b/cmd-select-layout.c
index 862a2fc..9d843d0 100644
--- a/cmd-select-layout.c
+++ b/cmd-select-layout.c
@@ -107,6 +107,7 @@ cmd_select_layout_exec(struct cmd *self, struct
cmd_ctx *ctx)
  layout = layout_set_next(wl->window);
  else
  layout = layout_set_previous(wl->window);
+ window_reflow(wl->window);
  server_redraw_window(wl->window);
  ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
  return (CMD_RETURN_NORMAL);
@@ -118,6 +119,7 @@ cmd_select_layout_exec(struct cmd *self, struct
cmd_ctx *ctx)
  layout = layout_set_lookup(args->argv[0]);
  if (layout != -1) {
  layout = layout_set_select(wl->window, layout);
+ window_reflow(wl->window);
  server_redraw_window(wl->window);
  ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
  return (CMD_RETURN_NORMAL);
@@ -129,6 +131,7 @@ cmd_select_layout_exec(struct cmd *self, struct
cmd_ctx *ctx)
  ctx->error(ctx, "can't set layout: %s", layoutname);
  return (CMD_RETURN_ERROR);
  }
+ window_reflow(wl->window);
  server_redraw_window(wl->window);
  ctx->info(ctx, "arranging in: %s", layoutname);
  }
diff --git a/cmd.c b/cmd.c
index 775e121..eaf6b34 100644
--- a/cmd.c
+++ b/cmd.c
@@ -79,6 +79,7 @@ const struct cmd_entry *cmd_table[] = {
  &cmd_pipe_pane_entry,
  &cmd_previous_layout_entry,
  &cmd_previous_window_entry,
+ &cmd_reflow_pane_entry,
  &cmd_refresh_client_entry,
  &cmd_rename_session_entry,
  &cmd_rename_window_entry,
diff --git a/grid.c b/grid.c
index 71a3679..0b8e0cd 100644
--- a/grid.c
+++ b/grid.c
@@ -541,3 +541,55 @@ grid_duplicate_lines(
  dy++;
  }
 }
+
+/*
+ * Reflow lines from src grid into dst grid based on width sx.
+ * Returns number of lines fewer in the visible area, or zero.
+ */
+u_int
+grid_reflow(struct grid *dst, const struct grid *src, u_int sx)
+{
+ GRID_DEBUG(src, "(src) sx=%u", sx);
+ GRID_DEBUG(dst, "(dst)");
+
+ u_int px = 0;
+ u_int py = 0;
+ u_int prev_line_wrapped = 1;
+
+ for (u_int line = 0; line < src->sy + src->hsize; line++) {
+ GRID_DEBUG(src, "Working line %u", line);
+ struct grid_line *gl = src->linedata + line;
+ if (!prev_line_wrapped) {
+ GRID_DEBUG(src, "(src) Last line didn't wrap.");
+ px = 0;
+ py++;
+ if (py >= dst->hsize + dst->sy) {
+ GRID_DEBUG(dst, "(dst) Having to scroll (py=%u).", py);
+ grid_scroll_history(dst);
+ }
+ }
+ for (u_int cell = 0; cell < gl->cellsize; cell++) {
+ if (px == sx) {
+ GRID_DEBUG(src, "(src) Width %u exceeded, wrapping.", sx);
+ dst->linedata[py].flags |= GRID_LINE_WRAPPED;
+ px = 0;
+ py++;
+ if (py >= dst->hsize + dst->sy) {
+ GRID_DEBUG(dst, "(dst) Having to scroll (py=%u).", py);
+ grid_scroll_history(dst);
+ }
+ }
+ grid_set_cell(dst, px, py, gl->celldata + cell);
+ px++;
+ }
+ prev_line_wrapped = gl->flags & GRID_LINE_WRAPPED;
+ }
+
+ /* Account for final line, which never wraps. */
+ py++;
+
+ if (py > src->sy)
+ return 0;
+ else
+ return src->sy - py;
+}
diff --git a/notify.c b/notify.c
index bd5c7d8..6d75d7b 100644
--- a/notify.c
+++ b/notify.c
@@ -154,6 +154,7 @@ notify_input(struct window_pane *wp, struct evbuffer *input)
 void
 notify_window_layout_changed(struct window *w)
 {
+ window_reflow(w);
  notify_add(NOTIFY_WINDOW_LAYOUT_CHANGED, NULL, NULL, w);
  notify_drain();
 }
diff --git a/options-table.c b/options-table.c
index 83ec97f..e1c6644 100644
--- a/options-table.c
+++ b/options-table.c
@@ -595,6 +595,11 @@ const struct options_table_entry window_options_table[] = {
   .default_num = 0
  },

+ { .name = "reflow",
+  .type = OPTIONS_TABLE_FLAG,
+  .default_num = 0
+ },
+
  { .name = "remain-on-exit",
   .type = OPTIONS_TABLE_FLAG,
   .default_num = 0
diff --git a/tmux.h b/tmux.h
index fa8f602..c6f4965 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1785,6 +1785,7 @@ extern const struct cmd_entry cmd_paste_buffer_entry;
 extern const struct cmd_entry cmd_pipe_pane_entry;
 extern const struct cmd_entry cmd_previous_layout_entry;
 extern const struct cmd_entry cmd_previous_window_entry;
+extern const struct cmd_entry cmd_reflow_pane_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;
@@ -1979,6 +1980,7 @@ void grid_move_cells(struct grid *, u_int,
u_int, u_int, u_int);
 char *grid_string_cells(struct grid *, u_int, u_int, u_int);
 void grid_duplicate_lines(
      struct grid *, u_int, struct grid *, u_int, u_int);
+u_int grid_reflow(struct grid *, const struct grid *, u_int);

 /* grid-utf8.c */
 size_t grid_utf8_size(const struct grid_utf8 *);
@@ -2159,6 +2161,8 @@ void window_set_name(struct window *, const char *);
 void window_remove_ref(struct window *);
 void winlink_clear_flags(struct winlink *);
 void window_mode_attrs(struct grid_cell *, struct options *);
+void window_reflow(struct window *);
+void window_pane_reflow(struct window_pane *);

 /* layout.c */
 u_int layout_count_cells(struct layout_cell *);
diff --git a/window.c b/window.c
index 9d0390a..b5a1ebe 100644
--- a/window.c
+++ b/window.c
@@ -1213,3 +1213,28 @@ window_mode_attrs(struct grid_cell *gc, struct
options *oo)
  colour_set_bg(gc, options_get_number(oo, "mode-bg"));
  gc->attr |= options_get_number(oo, "mode-attr");
 }
+
+/* Reflow all panes in a window, if the window option is set. */
+void
+window_reflow(struct window *w)
+{
+ struct window_pane *wp;
+
+ if (options_get_number(&w->options, "reflow")) {
+ TAILQ_FOREACH(wp, &w->panes, entry) {
+ window_pane_reflow(wp);
+ }
+ }
+}
+
+/* Reflow window pane. */
+void
+window_pane_reflow(struct window_pane *wp)
+{
+ struct grid *gd = wp->base.grid;
+ struct grid *new_grid = grid_create(gd->sx, gd->sy, gd->hlimit);
+
+ wp->screen->cy -= grid_reflow(new_grid, gd, wp->sx);
+ wp->base.grid = new_grid;
+ grid_destroy(gd);
+}
--
1.7.9.5

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to