Hi Here is a tweaked version with some trivial style nitpicking and one change to not reflow when the application has issued smcup (alternate screen).
I'm a bit torn about the need for an option - I'm not a huge fan of this behaviour but I don't think I actually care enough to need an option to turn it off. Thomas, what do you think? The only other issue I have now is that notify_window_layout_changed is not really the right place for a call to window_reflow. Why not in window_pane_resize and window_pane_alternate_off, or even in screen_resize (with a extra flag argument for when it isn't wanted)? This will also need man page changes but let's settle whether we want to make it mandatory or not first. Cheers Index: cmd-resize-pane.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/cmd-resize-pane.c,v retrieving revision 1.12 diff -u -p -r1.12 cmd-resize-pane.c --- cmd-resize-pane.c 17 Jan 2013 00:11:22 -0000 1.12 +++ cmd-resize-pane.c 31 Jan 2013 11:08:48 -0000 @@ -31,8 +31,8 @@ enum cmd_retval cmd_resize_pane_exec(st const struct cmd_entry cmd_resize_pane_entry = { "resize-pane", "resizep", - "DLRt:U", 0, 1, - "[-DLRU] " CMD_TARGET_PANE_USAGE " [adjustment]", + "DFLRt:U", 0, 1, + "[-DFLRU] " CMD_TARGET_PANE_USAGE " [adjustment]", 0, cmd_resize_pane_key_binding, NULL, @@ -111,6 +111,10 @@ cmd_resize_pane_exec(struct cmd *self, s layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust); else if (args_has(self->args, 'D')) layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust); + + if (args_has(self->args, 'F')) + window_pane_reflow(wp); + server_redraw_window(wl->window); return (CMD_RETURN_NORMAL); Index: cmd-select-layout.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/cmd-select-layout.c,v retrieving revision 1.18 diff -u -p -r1.18 cmd-select-layout.c --- cmd-select-layout.c 30 Jan 2013 17:00:17 -0000 1.18 +++ cmd-select-layout.c 31 Jan 2013 11:08:48 -0000 @@ -105,6 +105,7 @@ cmd_select_layout_exec(struct cmd *self, 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); @@ -116,6 +117,7 @@ cmd_select_layout_exec(struct cmd *self, 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); @@ -127,6 +129,7 @@ cmd_select_layout_exec(struct cmd *self, 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); } Index: grid.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/grid.c,v retrieving revision 1.21 diff -u -p -r1.21 grid.c --- grid.c 18 Jan 2013 02:16:21 -0000 1.21 +++ grid.c 31 Jan 2013 11:08:51 -0000 @@ -460,3 +460,44 @@ 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) +{ + u_int px, py, line, cell; + int previous_wrapped; + struct grid_line *gl; + + px = py = 0; + previous_wrapped = 1; + for (line = 0; line < src->sy + src->hsize; line++) { + gl = src->linedata + line; + if (!previous_wrapped) { + px = 0; + py++; + if (py >= dst->hsize + dst->sy) + grid_scroll_history(dst); + } + for (cell = 0; cell < gl->cellsize; cell++) { + if (px == sx) { + dst->linedata[py].flags |= GRID_LINE_WRAPPED; + px = 0; + py++; + if (py >= dst->hsize + dst->sy) + grid_scroll_history(dst); + } + grid_set_cell(dst, px, py, gl->celldata + cell); + px++; + } + previous_wrapped = gl->flags & GRID_LINE_WRAPPED; + } + py++; /* account for final line, which never wraps */ + + if (py > src->sy) + return (0); + return (src->sy - py); +} Index: notify.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/notify.c,v retrieving revision 1.5 diff -u -p -r1.5 notify.c --- notify.c 25 Sep 2012 07:41:22 -0000 1.5 +++ notify.c 31 Jan 2013 11:08:51 -0000 @@ -155,6 +155,7 @@ notify_input(struct window_pane *wp, str void notify_window_layout_changed(struct window *w) { + window_reflow(w); notify_add(NOTIFY_WINDOW_LAYOUT_CHANGED, NULL, NULL, w); notify_drain(); } Index: options-table.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/options-table.c,v retrieving revision 1.32 diff -u -p -r1.32 options-table.c --- options-table.c 17 Jan 2013 00:11:22 -0000 1.32 +++ options-table.c 31 Jan 2013 11:08:55 -0000 @@ -596,6 +596,11 @@ const struct options_table_entry window_ .default_num = 0 }, + { .name = "reflow", + .type = OPTIONS_TABLE_FLAG, + .default_num = 0 + }, + { .name = "remain-on-exit", .type = OPTIONS_TABLE_FLAG, .default_num = 0 Index: tmux.h =================================================================== RCS file: /cvs/src/usr.bin/tmux/tmux.h,v retrieving revision 1.373 diff -u -p -r1.373 tmux.h --- tmux.h 18 Jan 2013 02:16:21 -0000 1.373 +++ tmux.h 31 Jan 2013 11:09:01 -0000 @@ -1964,6 +1964,7 @@ void grid_move_cells(struct grid *, u_i 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-cell.c */ u_int grid_cell_width(const struct grid_cell *); @@ -2138,6 +2139,8 @@ void window_set_name(struct window *, 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 *); Index: window.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/window.c,v retrieving revision 1.88 diff -u -p -r1.88 window.c --- window.c 17 Jan 2013 00:11:22 -0000 1.88 +++ window.c 31 Jan 2013 11:09:01 -0000 @@ -1203,3 +1203,33 @@ window_mode_attrs(struct grid_cell *gc, 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 *old, *new; + + if (wp->saved_grid != NULL) + return; + + old = wp->base.grid; + new = grid_create(old->sx, old->sy, old->hlimit); + + wp->screen->cy -= grid_reflow(new, old, wp->sx); + wp->base.grid = new; + + grid_destroy(old); +} On Wed, Jan 30, 2013 at 04:59:34PM -0500, Richard Woodbury wrote: > On Wed, Jan 30, 2013 at 11:14 AM, Thomas Adam <[1]tho...@xteddy.org> > wrote: > > I've pushed changes to tmux.git which means you'll need to rework your > patch slightly since GRID_FLAG_UTF8 is no longer used by anything. > > You're probably OK to just call grid_cell_{get,set}() without checking > first; but I've not looked. > > Oh, well, I guess I didn't really need to debug that problem after all. *I > have rebased to HEAD and reverted my commit to fix the UTF-8 issue, and > the code seems to run just fine. > Nicholas wrote: > > I think we should make this a flag to resize-pane (I suggest -R or -L) > rather than a new command. Could you do that? > > Those flags are taken. *I have chosen -F, as in reFlow. So now, just > "resize-pane -F" simply reflows the pane without any other adjustments. > Incidentally, the man page entry for resize-pane doesn't seem to reflect > reality: -U isn't a real default. This serves my purposes nicely, as it > turns out. Let me know if you want me to rewrite the man page entry for > resize-pane (perhaps as a separate patch/thread). > Taking out reflow-pane reduces the size of the patch significantly, which > is good. > > I'm not sure we need the GRID_DEBUG now if you are happy it works? > > Gone. > > In any case these declarations need to go before the GRID_DEBUG lines or > it will fail when built with gcc2. Same in several places below.* > > I'm going to add -Wdeclaration-after-statement to CFLAGS I think... > > I see. *If you need to build on a compiler that can't handle that, then > having that warning sounds like an excellent idea. *I have also pulled up > "struct grid_line *gl" in that same function so as to be more consistent > (even though it is at the top of a block, so should be OK). > Fresh complete patch rebased on c4c98df4f25a5681fcc8da3394cf4adf39f56893 > attached. > > References > > Visible links > 1. mailto:tho...@xteddy.org ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_d2d_jan _______________________________________________ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users