[BACK]Return to window-copy.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/window-copy.c between version 1.161 and 1.162

version 1.161, 2016/11/24 13:38:44 version 1.162, 2017/01/05 09:07:16
Line 49 
Line 49 
                     u_int, u_int, u_int, int);                      u_int, u_int, u_int, int);
 static int      window_copy_search_rl(struct grid *, struct grid *, u_int *,  static int      window_copy_search_rl(struct grid *, struct grid *, u_int *,
                     u_int, u_int, u_int, int);                      u_int, u_int, u_int, int);
   static int      window_copy_search_marks(struct window_pane *, struct screen *);
 static void     window_copy_move_left(struct screen *, u_int *, u_int *);  static void     window_copy_move_left(struct screen *, u_int *, u_int *);
 static void     window_copy_move_right(struct screen *, u_int *, u_int *);  static void     window_copy_move_right(struct screen *, u_int *, u_int *);
 static int      window_copy_is_lowercase(const char *);  static int      window_copy_is_lowercase(const char *);
 static void     window_copy_search_jump(struct window_pane *, struct grid *,  static void     window_copy_search_jump(struct window_pane *, struct grid *,
                     struct grid *, u_int, u_int, u_int, int, int, int);                      struct grid *, u_int, u_int, u_int, int, int, int);
 static void     window_copy_search(struct window_pane *, const char *, int,  static void     window_copy_search(struct window_pane *, int, int);
                     int);  static void     window_copy_search_up(struct window_pane *, int);
 static void     window_copy_search_up(struct window_pane *, const char *, int);  static void     window_copy_search_down(struct window_pane *, int);
 static void     window_copy_search_down(struct window_pane *, const char *,  
                     int);  
 static void     window_copy_goto_line(struct window_pane *, const char *);  static void     window_copy_goto_line(struct window_pane *, const char *);
 static void     window_copy_update_cursor(struct window_pane *, u_int, u_int);  static void     window_copy_update_cursor(struct window_pane *, u_int, u_int);
 static void     window_copy_start_selection(struct window_pane *);  static void     window_copy_start_selection(struct window_pane *);
Line 173 
Line 172 
   
         int              searchtype;          int              searchtype;
         char            *searchstr;          char            *searchstr;
           bitstr_t        *searchmark;
   
         int              jumptype;          int              jumptype;
         char             jumpchar;          char             jumpchar;
Line 185 
Line 185 
         struct screen                   *s;          struct screen                   *s;
   
         wp->modedata = data = xmalloc(sizeof *data);          wp->modedata = data = xmalloc(sizeof *data);
   
         data->oy = 0;          data->oy = 0;
         data->cx = 0;          data->cx = 0;
         data->cy = 0;          data->cy = 0;
Line 201 
Line 202 
   
         data->searchtype = WINDOW_COPY_OFF;          data->searchtype = WINDOW_COPY_OFF;
         data->searchstr = NULL;          data->searchstr = NULL;
           data->searchmark = NULL;
   
         if (wp->fd != -1)          if (wp->fd != -1)
                 bufferevent_disable(wp->event, EV_READ|EV_WRITE);                  bufferevent_disable(wp->event, EV_READ|EV_WRITE);
Line 261 
Line 263 
         if (wp->fd != -1)          if (wp->fd != -1)
                 bufferevent_enable(wp->event, EV_READ|EV_WRITE);                  bufferevent_enable(wp->event, EV_READ|EV_WRITE);
   
           free(data->searchmark);
         free(data->searchstr);          free(data->searchstr);
   
         if (data->backing != &wp->base) {          if (data->backing != &wp->base) {
Line 333 
Line 336 
 {  {
         struct window_copy_mode_data    *data = wp->modedata;          struct window_copy_mode_data    *data = wp->modedata;
         struct screen                   *s = &data->screen;          struct screen                   *s = &data->screen;
         u_int                            n, ox, oy;          u_int                            n, ox, oy, px, py;
   
         oy = screen_hsize(data->backing) + data->cy - data->oy;          oy = screen_hsize(data->backing) + data->cy - data->oy;
         ox = window_copy_find_length(wp, oy);          ox = window_copy_find_length(wp, oy);
Line 361 
Line 364 
                 data->oy += n;                  data->oy += n;
   
         if (!data->screen.sel.flag || !data->rectflag) {          if (!data->screen.sel.flag || !data->rectflag) {
                 u_int py = screen_hsize(data->backing) + data->cy - data->oy;                  py = screen_hsize(data->backing) + data->cy - data->oy;
                 u_int px = window_copy_find_length(wp, py);                  px = window_copy_find_length(wp, py);
                 if ((data->cx >= data->lastsx && data->cx != px) || data->cx > px)                  if ((data->cx >= data->lastsx && data->cx != px) ||
                       data->cx > px)
                         window_copy_cursor_end_of_line(wp);                          window_copy_cursor_end_of_line(wp);
         }          }
   
Line 481 
Line 485 
         window_copy_write_lines(wp, &ctx, 0, screen_size_y(s) - 1);          window_copy_write_lines(wp, &ctx, 0, screen_size_y(s) - 1);
         screen_write_stop(&ctx);          screen_write_stop(&ctx);
   
           if (data->searchmark != NULL)
                   window_copy_search_marks(wp, NULL);
   
         window_copy_redraw_screen(wp);          window_copy_redraw_screen(wp);
 }  }
   
Line 498 
Line 505 
 {  {
         struct window_copy_mode_data    *data = wp->modedata;          struct window_copy_mode_data    *data = wp->modedata;
         struct screen                   *sn = &data->screen;          struct screen                   *sn = &data->screen;
         const char                      *command, *argument, *ws, *ss;          const char                      *command, *argument, *ws;
         u_int                            np = wp->modeprefix;          u_int                            np = wp->modeprefix;
           int                              cancel = 0;
   
         if (args->argc == 0)          if (args->argc == 0)
                 return;                  return;
Line 520 
Line 528 
                                 window_copy_append_selection(wp, NULL);                                  window_copy_append_selection(wp, NULL);
                         window_copy_clear_selection(wp);                          window_copy_clear_selection(wp);
                         window_copy_redraw_screen(wp);                          window_copy_redraw_screen(wp);
                         window_pane_reset_mode(wp);                          cancel = 1;
                 }                  }
                 if (strcmp(command, "back-to-indentation") == 0)                  if (strcmp(command, "back-to-indentation") == 0)
                         window_copy_cursor_back_to_indentation(wp);                          window_copy_cursor_back_to_indentation(wp);
Line 542 
Line 550 
                         window_copy_redraw_screen(wp);                          window_copy_redraw_screen(wp);
                 }                  }
                 if (strcmp(command, "cancel") == 0)                  if (strcmp(command, "cancel") == 0)
                         window_pane_reset_mode(wp);                          cancel = 1;
                 if (strcmp(command, "clear-selection") == 0) {                  if (strcmp(command, "clear-selection") == 0) {
                         window_copy_clear_selection(wp);                          window_copy_clear_selection(wp);
                         window_copy_redraw_screen(wp);                          window_copy_redraw_screen(wp);
Line 556 
Line 564 
   
                         if (s != NULL) {                          if (s != NULL) {
                                 window_copy_copy_selection(wp, NULL);                                  window_copy_copy_selection(wp, NULL);
                                 window_pane_reset_mode(wp);                                  cancel = 1;
                         }                          }
                 }                  }
                 if (strcmp(command, "copy-line") == 0) {                  if (strcmp(command, "copy-line") == 0) {
Line 569 
Line 577 
   
                         if (s != NULL) {                          if (s != NULL) {
                                 window_copy_copy_selection(wp, NULL);                                  window_copy_copy_selection(wp, NULL);
                                 window_pane_reset_mode(wp);                                  cancel = 1;
                         }                          }
                 }                  }
                 if (strcmp(command, "copy-selection") == 0) {                  if (strcmp(command, "copy-selection") == 0) {
Line 583 
Line 591 
                                 window_copy_copy_selection(wp, NULL);                                  window_copy_copy_selection(wp, NULL);
                         window_copy_clear_selection(wp);                          window_copy_clear_selection(wp);
                         window_copy_redraw_screen(wp);                          window_copy_redraw_screen(wp);
                         window_pane_reset_mode(wp);                          cancel = 1;
                 }                  }
                 if (strcmp(command, "cursor-down") == 0) {                  if (strcmp(command, "cursor-down") == 0) {
                         for (; np != 0; np--)                          for (; np != 0; np--)
Line 726 
Line 734 
                         for (; np != 0; np--)                          for (; np != 0; np--)
                                 window_copy_cursor_down(wp, 1);                                  window_copy_cursor_down(wp, 1);
                         if (data->scroll_exit && data->oy == 0)                          if (data->scroll_exit && data->oy == 0)
                                 window_pane_reset_mode(wp);                                  cancel = 1;
                 }                  }
                 if (strcmp(command, "scroll-up") == 0) {                  if (strcmp(command, "scroll-up") == 0) {
                         for (; np != 0; np--)                          for (; np != 0; np--)
                                 window_copy_cursor_up(wp, 1);                                  window_copy_cursor_up(wp, 1);
                 }                  }
                 if (strcmp(command, "search-again") == 0) {                  if (strcmp(command, "search-again") == 0) {
                         ss = data->searchstr;  
                         if (data->searchtype == WINDOW_COPY_SEARCHUP) {                          if (data->searchtype == WINDOW_COPY_SEARCHUP) {
                                 for (; np != 0; np--)                                  for (; np != 0; np--)
                                         window_copy_search_up(wp, ss, 1);                                          window_copy_search_up(wp, 1);
                         } else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) {                          } else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) {
                                 for (; np != 0; np--)                                  for (; np != 0; np--)
                                         window_copy_search_down(wp, ss, 1);                                          window_copy_search_down(wp, 1);
                         }                          }
                 }                  }
                 if (strcmp(command, "search-reverse") == 0) {                  if (strcmp(command, "search-reverse") == 0) {
                         ss = data->searchstr;  
                         if (data->searchtype == WINDOW_COPY_SEARCHUP) {                          if (data->searchtype == WINDOW_COPY_SEARCHUP) {
                                 for (; np != 0; np--)                                  for (; np != 0; np--)
                                         window_copy_search_down(wp, ss, 1);                                          window_copy_search_down(wp, 1);
                         } else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) {                          } else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) {
                                 for (; np != 0; np--)                                  for (; np != 0; np--)
                                         window_copy_search_up(wp, ss, 1);                                          window_copy_search_up(wp, 1);
                         }                          }
                 }                  }
                 if (strcmp(command, "select-line") == 0) {                  if (strcmp(command, "select-line") == 0) {
Line 788 
Line 794 
                 if (strcmp(command, "copy-pipe-and-cancel") == 0) {                  if (strcmp(command, "copy-pipe-and-cancel") == 0) {
                         if (s != NULL) {                          if (s != NULL) {
                                 window_copy_copy_pipe(wp, s, NULL, argument);                                  window_copy_copy_pipe(wp, s, NULL, argument);
                                 window_pane_reset_mode(wp);                                  cancel = 1;
                         }                          }
                 }                  }
                 if (strcmp(command, "goto-line") == 0)                  if (strcmp(command, "goto-line") == 0)
Line 821 
Line 827 
                         data->searchtype = WINDOW_COPY_SEARCHUP;                          data->searchtype = WINDOW_COPY_SEARCHUP;
                         data->searchstr = xstrdup(argument);                          data->searchstr = xstrdup(argument);
                         for (; np != 0; np--)                          for (; np != 0; np--)
                                 window_copy_search_up(wp, data->searchstr, 1);                                  window_copy_search_up(wp, 1);
                 }                  }
                 if (strcmp(command, "search-forward") == 0) {                  if (strcmp(command, "search-forward") == 0) {
                         data->searchtype = WINDOW_COPY_SEARCHDOWN;                          data->searchtype = WINDOW_COPY_SEARCHDOWN;
                         data->searchstr = xstrdup(argument);                          data->searchstr = xstrdup(argument);
                         for (; np != 0; np--)                          for (; np != 0; np--)
                                 window_copy_search_down(wp, data->searchstr, 1);                                  window_copy_search_down(wp, 1);
                 }                  }
         }          }
   
           if (strncmp(command, "search-", 7) != 0 && data->searchmark != NULL) {
                   free(data->searchmark);
                   data->searchmark = NULL;
                   window_copy_redraw_screen(wp);
           }
   
           if (cancel)
                   window_pane_reset_mode(wp);
         wp->modeprefix = 1;          wp->modeprefix = 1;
 }  }
   
Line 1016 
Line 1030 
  * as well.   * as well.
  */   */
 static void  static void
 window_copy_search(struct window_pane *wp, const char *searchstr, int direction,  window_copy_search(struct window_pane *wp, int direction, int moveflag)
     int moveflag)  
 {  {
         struct window_copy_mode_data    *data = wp->modedata;          struct window_copy_mode_data    *data = wp->modedata;
         struct screen                   *s = data->backing, ss;          struct screen                   *s = data->backing, ss;
Line 1029 
Line 1042 
         fx = data->cx;          fx = data->cx;
         fy = screen_hsize(data->backing) - data->oy + data->cy;          fy = screen_hsize(data->backing) - data->oy + data->cy;
   
         screen_init(&ss, screen_write_strlen("%s", searchstr), 1, 0);          screen_init(&ss, screen_write_strlen("%s", data->searchstr), 1, 0);
         screen_write_start(&ctx, NULL, &ss);          screen_write_start(&ctx, NULL, &ss);
         screen_write_nputs(&ctx, -1, &grid_default_cell, "%s", searchstr);          screen_write_nputs(&ctx, -1, &grid_default_cell, "%s", data->searchstr);
         screen_write_stop(&ctx);          screen_write_stop(&ctx);
   
         if (moveflag) {          if (moveflag) {
Line 1043 
Line 1056 
         window_copy_clear_selection(wp);          window_copy_clear_selection(wp);
   
         wrapflag = options_get_number(wp->window->options, "wrap-search");          wrapflag = options_get_number(wp->window->options, "wrap-search");
         cis = window_copy_is_lowercase(searchstr);          cis = window_copy_is_lowercase(data->searchstr);
   
         if (direction)          if (direction)
                 endline = gd->hsize + gd->sy - 1;                  endline = gd->hsize + gd->sy - 1;
         else          else
                 endline = 0;                  endline = 0;
         window_copy_search_jump(wp, gd, ss.grid, fx, fy, endline, cis, wrapflag,          window_copy_search_jump(wp, gd, ss.grid, fx, fy, endline, cis,
             direction);              wrapflag, direction);
   
           if (window_copy_search_marks(wp, &ss))
                   window_copy_redraw_screen(wp);
   
         screen_free(&ss);          screen_free(&ss);
 }  }
   
   static int
   window_copy_search_marks(struct window_pane *wp, struct screen *ssp)
   {
           struct window_copy_mode_data    *data = wp->modedata;
           struct screen                   *s = data->backing, ss;
           struct screen_write_ctx          ctx;
           struct grid                     *gd = s->grid;
           int                              found, cis;
           u_int                            px, py, b, nfound = 0, width;
   
           if (ssp == NULL) {
                   width = screen_write_strlen("%s", data->searchstr);
                   screen_init(&ss, width, 1, 0);
                   screen_write_start(&ctx, NULL, &ss);
                   screen_write_nputs(&ctx, -1, &grid_default_cell, "%s",
                       data->searchstr);
                   screen_write_stop(&ctx);
                   ssp = &ss;
           } else
                   width = screen_size_x(ssp);
   
           cis = window_copy_is_lowercase(data->searchstr);
   
           free(data->searchmark);
           data->searchmark = bit_alloc((gd->hsize + gd->sy) * gd->sx);
   
           for (py = 0; py < gd->hsize + gd->sy; py++) {
                   px = 0;
                   for (;;) {
                           found = window_copy_search_lr(gd, ssp->grid, &px, py,
                               px, gd->sx, cis);
                           if (!found)
                                   break;
                           nfound++;
   
                           b = (py * gd->sx) + px;
                           bit_nset(data->searchmark, b, b + width - 1);
   
                           px++;
                   }
           }
   
           if (ssp == &ss)
                   screen_free(&ss);
           return (nfound);
   }
   
 static void  static void
 window_copy_search_up(struct window_pane *wp, const char *searchstr,  window_copy_search_up(struct window_pane *wp, int moveflag)
     int moveflag)  
 {  {
         window_copy_search(wp, searchstr, 0, moveflag);          window_copy_search(wp, 0, moveflag);
 }  }
   
 static void  static void
 window_copy_search_down(struct window_pane *wp, const char *searchstr,  window_copy_search_down(struct window_pane *wp, int moveflag)
     int moveflag)  
 {  {
         window_copy_search(wp, searchstr, 1, moveflag);          window_copy_search(wp, 1, moveflag);
 }  }
   
 static void  static void
Line 1094 
Line 1155 
         struct options                  *oo = wp->window->options;          struct options                  *oo = wp->window->options;
         struct grid_cell                 gc;          struct grid_cell                 gc;
         char                             hdr[512];          char                             hdr[512];
         size_t                           xoff = 0, size = 0;          size_t                           size = 0;
   
         style_apply(&gc, oo, "mode-style");          style_apply(&gc, oo, "mode-style");
   
Line 1109 
Line 1170 
                 size = 0;                  size = 0;
   
         if (size < screen_size_x(s)) {          if (size < screen_size_x(s)) {
                 screen_write_cursormove(ctx, xoff, py);                  screen_write_cursormove(ctx, 0, py);
                 screen_write_copy(ctx, data->backing, xoff,                  screen_write_copy(ctx, data->backing, 0,
                     (screen_hsize(data->backing) - data->oy) + py,                      (screen_hsize(data->backing) - data->oy) + py,
                     screen_size_x(s) - size, 1);                      screen_size_x(s) - size, 1, data->searchmark, &gc);
         }          }
   
         if (py == data->cy && data->cx == screen_size_x(s)) {          if (py == data->cy && data->cx == screen_size_x(s)) {

Legend:
Removed from v.1.161  
changed lines
  Added in v.1.162