[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.283 and 1.284

version 1.283, 2020/05/16 15:34:08 version 1.284, 2020/05/16 15:38:14
Line 258 
Line 258 
         int              searchregex;          int              searchregex;
         char            *searchstr;          char            *searchstr;
         u_char          *searchmark;          u_char          *searchmark;
         u_int            searchcount;          int              searchcount;
           int              searchmore;
         int              searchthis;          int              searchthis;
         int              searchx;          int              searchx;
         int              searchy;          int              searchy;
Line 266 
Line 267 
         u_char           searchgen;          u_char           searchgen;
   
         int              timeout;       /* search has timed out */          int              timeout;       /* search has timed out */
 #define WINDOW_COPY_SEARCH_TIMEOUT 10  #define WINDOW_COPY_SEARCH_TIMEOUT 10000
   #define WINDOW_COPY_SEARCH_ALL_TIMEOUT 200
   
         int              jumptype;          int              jumptype;
         char             jumpchar;          char             jumpchar;
Line 2847 
Line 2849 
         return (found);          return (found);
 }  }
   
   static uint64_t
   window_copy_get_time(void)
   {
           struct timeval  tv;
   
           gettimeofday(&tv, NULL);
           return ((tv.tv_sec * 1000ULL) + (tv.tv_usec / 1000ULL));
   }
   
 static int  static int
 window_copy_search_marks(struct window_mode_entry *wme, struct screen *ssp,  window_copy_search_marks(struct window_mode_entry *wme, struct screen *ssp,
     int regex)      int regex)
Line 2856 
Line 2867 
         struct screen_write_ctx          ctx;          struct screen_write_ctx          ctx;
         struct grid                     *gd = s->grid;          struct grid                     *gd = s->grid;
         const struct grid_line          *gl;          const struct grid_line          *gl;
         int                              found, cis, which = -1;          int                              found, cis, which = -1, stopped = 0;
         int                              cflags = REG_EXTENDED;          int                              cflags = REG_EXTENDED;
         u_int                            px, py, i, b, nfound = 0, width;          u_int                            px, py, i, b, nfound = 0, width;
         u_int                            ssize = 1;          u_int                            ssize = 1, start, end;
         char                            *sbuf;          char                            *sbuf;
         regex_t                          reg;          regex_t                          reg;
         time_t                           tstart, t;          uint64_t                         stop = 0, tstart, t;
   
         if (ssp == NULL) {          if (ssp == NULL) {
                 width = screen_write_strlen("%s", data->searchstr);                  width = screen_write_strlen("%s", data->searchstr);
Line 2877 
Line 2888 
   
         cis = window_copy_is_lowercase(data->searchstr);          cis = window_copy_is_lowercase(data->searchstr);
   
         free(data->searchmark);  
         data->searchmark = xcalloc(gd->hsize + gd->sy, gd->sx);  
         data->searchgen = 1;  
   
         if (regex) {          if (regex) {
                 sbuf = xmalloc(ssize);                  sbuf = xmalloc(ssize);
                 sbuf[0] = '\0';                  sbuf[0] = '\0';
Line 2893 
Line 2900 
                         return (0);                          return (0);
                 }                  }
         }          }
         time(&tstart);          tstart = window_copy_get_time();
         for (py = gd->hsize - data->oy; py > 0; py--) {  
                 gl = grid_peek_line(gd, py - 1);          start = 0;
                 if (~gl->flags & GRID_LINE_WRAPPED)          end = gd->hsize + gd->sy;
                         break;          stop = window_copy_get_time() + WINDOW_COPY_SEARCH_ALL_TIMEOUT;
         }  
         for (; py < gd->hsize - data->oy + gd->sy; py++) {  again:
           free(data->searchmark);
           data->searchmark = xcalloc(gd->hsize + gd->sy, gd->sx);
           data->searchgen = 1;
   
           for (py = start; py < end; py++) {
                 px = 0;                  px = 0;
                 for (;;) {                  for (;;) {
                         if (regex) {                          if (regex) {
Line 2930 
Line 2942 
                         px++;                          px++;
                 }                  }
   
                 time(&t);                  t = window_copy_get_time();
                 if (t - tstart > WINDOW_COPY_SEARCH_TIMEOUT) {                  if (t - tstart > WINDOW_COPY_SEARCH_TIMEOUT) {
                         data->timeout = 1;                          data->timeout = 1;
                         break;                          break;
                 }                  }
                   if (stop != 0 && t > stop) {
                           stopped = 1;
                           break;
                   }
         }          }
         if (regex) {  
                 free(sbuf);  
                 regfree(&reg);  
         }  
         if (data->timeout) {          if (data->timeout) {
                 window_copy_clear_marks(wme);                  window_copy_clear_marks(wme);
                 return (1);                  goto out;
         }          }
   
         if (which != -1)          if (stopped && stop != 0) {
                 data->searchthis = 1 + nfound - which;                  /* Try again but just the visible context. */
         else                  for (start = gd->hsize - data->oy; start > 0; start--) {
                           gl = grid_peek_line(gd, start - 1);
                           if (~gl->flags & GRID_LINE_WRAPPED)
                                   break;
                   }
                   end = gd->hsize - data->oy + gd->sy;
                   stop = 0;
                   goto again;
           }
   
           if (stopped) {
                 data->searchthis = -1;                  data->searchthis = -1;
         data->searchcount = nfound;                  if (nfound > 1000)
                           data->searchcount = 1000;
                   else if (nfound > 100)
                           data->searchcount = 100;
                   else if (nfound > 10)
                           data->searchcount = 10;
                   else
                           data->searchcount = -1;
                   data->searchmore = 1;
           } else {
                   if (which != -1)
                           data->searchthis = 1 + nfound - which;
                   else
                           data->searchthis = -1;
                   data->searchcount = nfound;
                   data->searchmore = 0;
           }
   
   out:
         if (ssp == &ss)          if (ssp == &ss)
                 screen_free(&ss);                  screen_free(&ss);
           if (regex) {
                   free(sbuf);
                   regfree(&reg);
           }
         return (1);          return (1);
 }  }
   
Line 3057 
Line 3100 
     const struct grid_cell *cgc)      const struct grid_cell *cgc)
 {  {
         struct window_copy_mode_data    *data = wme->data;          struct window_copy_mode_data    *data = wme->data;
         u_int                            mark, at, start, end, cy;          u_int                            mark, start, end, cy, cursor, current;
         u_int                            sx = screen_size_x(data->backing);          u_int                            sx = screen_size_x(data->backing);
   
         if (data->searchmark == NULL)          if (data->searchmark == NULL)
                 return;                  return;
         mark = data->searchmark[(fy * sx) + fx];  
           current = (fy * sx) + fx;
   
           mark = data->searchmark[current];
         if (mark == 0)          if (mark == 0)
                 return;                  return;
   
         cy = screen_hsize(data->backing) - data->oy + data->cy;          cy = screen_hsize(data->backing) - data->oy + data->cy;
         at = (cy * sx) + data->cx;          cursor = (cy * sx) + data->cx;
         if (data->searchmark[at] == mark) {          if (data->searchmark[cursor] == mark) {
                 window_copy_match_start_end(data, at, &start, &end);                  window_copy_match_start_end(data, cursor, &start, &end);
                 if (at >= start && at <= end) {                  if (current >= start && current <= end) {
                         gc->attr = cgc->attr;                          gc->attr = cgc->attr;
                         gc->fg = cgc->fg;                          gc->fg = cgc->fg;
                         gc->bg = cgc->bg;                          gc->bg = cgc->bg;
                           return;
                 }                  }
                 return;  
         }          }
   
         gc->attr = mgc->attr;          gc->attr = mgc->attr;
Line 3133 
Line 3179 
                                     "[%u/%u]", data->oy, hsize);                                      "[%u/%u]", data->oy, hsize);
                         }                          }
                 } else {                  } else {
                         if (data->searchthis == -1) {                          if (data->searchcount == -1) {
                                 size = xsnprintf(hdr, sizeof hdr,                                  size = xsnprintf(hdr, sizeof hdr,
                                     "(%u results) [%d/%u]", data->searchcount,                                      "[%u/%u]", data->oy, hsize);
                                     data->oy, hsize);                          } else if (data->searchthis == -1) {
                                   size = xsnprintf(hdr, sizeof hdr,
                                       "(%d%s results) [%u/%u]", data->searchcount,
                                       data->searchmore ? "+" : "", data->oy, hsize);
                         } else {                          } else {
                                 size = xsnprintf(hdr, sizeof hdr,                                  size = xsnprintf(hdr, sizeof hdr,
                                     "(%u/%u results) [%d/%u]", data->searchthis,                                      "(%d/%d results) [%u/%u]", data->searchthis,
                                     data->searchcount, data->oy, hsize);                                      data->searchcount, data->oy, hsize);
                         }                          }
                 }                  }

Legend:
Removed from v.1.283  
changed lines
  Added in v.1.284