Hi Take a look at this please.
We reflow in window_pane_resize when the alternate screen is off (saved_grid == NULL) and always when switching back from alternate screen. No need to reflow from any of the modes. 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 1 Feb 2013 11:28:38 -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: screen.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/screen.c,v retrieving revision 1.23 diff -u -p -r1.23 screen.c --- screen.c 10 Jul 2012 11:53:01 -0000 1.23 +++ screen.c 1 Feb 2013 11:28:38 -0000 @@ -120,7 +120,7 @@ screen_set_title(struct screen *s, const /* Resize screen. */ void -screen_resize(struct screen *s, u_int sx, u_int sy) +screen_resize(struct screen *s, u_int sx, u_int sy, int reflow) { if (sx < 1) sx = 1; @@ -140,6 +140,9 @@ screen_resize(struct screen *s, u_int sx if (sy != screen_size_y(s)) screen_resize_y(s, sy); + + if (reflow) + screen_reflow(s, sx); } void @@ -355,4 +358,19 @@ screen_check_selection(struct screen *s, } return (1); +} + +/* Reflow wrapped lines. */ +void +screen_reflow(struct screen *s, u_int sx) +{ + struct grid *old, *new; + + old = s->grid; + new = grid_create(old->sx, old->sy, old->hlimit); + + s->cy -= grid_reflow(new, old, sx); + s->grid = new; + + grid_destroy(old); } 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 1 Feb 2013 11:28:41 -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 *); @@ -2057,11 +2058,12 @@ void screen_reset_tabs(struct screen *) void screen_set_cursor_style(struct screen *, u_int); void screen_set_cursor_colour(struct screen *, const char *); void screen_set_title(struct screen *, const char *); -void screen_resize(struct screen *, u_int, u_int); +void screen_resize(struct screen *, u_int, u_int, int); void screen_set_selection(struct screen *, u_int, u_int, u_int, u_int, u_int, struct grid_cell *); void screen_clear_selection(struct screen *); int screen_check_selection(struct screen *, u_int, u_int); +void screen_reflow(struct screen *, u_int); /* window.c */ extern struct windows windows; Index: window-choose.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/window-choose.c,v retrieving revision 1.31 diff -u -p -r1.31 window-choose.c --- window-choose.c 24 Dec 2012 12:34:32 -0000 1.31 +++ window-choose.c 1 Feb 2013 11:28:42 -0000 @@ -203,7 +203,7 @@ window_choose_resize(struct window_pane if (data->selected > sy - 1) data->top = data->selected - (sy - 1); - screen_resize(s, sx, sy); + screen_resize(s, sx, sy, 0); window_choose_redraw_screen(wp); } Index: window-clock.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/window-clock.c,v retrieving revision 1.7 diff -u -p -r1.7 window-clock.c --- window-clock.c 10 Jul 2012 11:53:01 -0000 1.7 +++ window-clock.c 1 Feb 2013 11:28:42 -0000 @@ -79,7 +79,7 @@ window_clock_resize(struct window_pane * struct window_clock_mode_data *data = wp->modedata; struct screen *s = &data->screen; - screen_resize(s, sx, sy); + screen_resize(s, sx, sy, 0); window_clock_draw_screen(wp); } Index: window-copy.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/window-copy.c,v retrieving revision 1.86 diff -u -p -r1.86 window-copy.c --- window-copy.c 18 Jan 2013 02:16:21 -0000 1.86 +++ window-copy.c 1 Feb 2013 11:28:44 -0000 @@ -335,9 +335,9 @@ window_copy_resize(struct window_pane *w struct screen *s = &data->screen; struct screen_write_ctx ctx; - screen_resize(s, sx, sy); + screen_resize(s, sx, sy, 0); if (data->backing != &wp->base) - screen_resize(data->backing, sx, sy); + screen_resize(data->backing, sx, sy, 0); if (data->cy > sy - 1) data->cy = sy - 1; 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 1 Feb 2013 11:28:45 -0000 @@ -853,7 +853,7 @@ window_pane_resize(struct window_pane *w ws.ws_col = sx; ws.ws_row = sy; - screen_resize(&wp->base, sx, sy); + screen_resize(&wp->base, sx, sy, wp->saved_grid == NULL); if (wp->mode != NULL) wp->mode->resize(wp, sx, sy); @@ -914,7 +914,7 @@ window_pane_alternate_off(struct window_ * before copying back. */ if (sy > wp->saved_grid->sy) - screen_resize(s, sx, wp->saved_grid->sy); + screen_resize(s, sx, wp->saved_grid->sy, 1); /* Restore the grid, cursor position and cell. */ grid_duplicate_lines(s->grid, screen_hsize(s), wp->saved_grid, 0, sy); @@ -934,7 +934,7 @@ window_pane_alternate_off(struct window_ */ wp->base.grid->flags |= GRID_HISTORY; if (sy > wp->saved_grid->sy) - screen_resize(s, sx, sy); + screen_resize(s, sx, sy, 1); grid_destroy(wp->saved_grid); wp->saved_grid = NULL; On Fri, Feb 01, 2013 at 02:15:56AM -0500, Richard Woodbury wrote: > On Thu, Jan 31, 2013 at 6:55 AM, Nicholas Marriott > <[1]nicholas.marri...@gmail.com> wrote: > > Ok let's lose the option and make it the default and that means we don't > have to have resizep -F and that means no man page changes too. > > I think I would try to put the call to grid_reflow into screen_resize > but it will need an extra argument because we still won't want to do it > in alternate screen, for the calls in window-copy.c etc. > > Richard, can you do these changes? If not I will try to do them > tomorrow. > > I'm excited you want to make reflowing the new behavior for tmux. All of > these changes yield a substantially simplified patch. However, along the > way I lost your "alternate screen" tweak, and I haven't yet wired it up to > work within screen_resize(). Here's what I have so far; if you get a > chance, perhaps you could wire it up, otherwise I can hack on it more > tomorrow evening. > > References > > Visible links > 1. mailto:nicholas.marri...@gmail.com ------------------------------------------------------------------------------ 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