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

Diff for /src/usr.bin/tmux/mode-tree.c between version 1.51 and 1.52

version 1.51, 2020/07/27 08:03:10 version 1.52, 2021/04/12 06:50:25
Line 46 
Line 46 
         mode_tree_search_cb       searchcb;          mode_tree_search_cb       searchcb;
         mode_tree_menu_cb         menucb;          mode_tree_menu_cb         menucb;
         mode_tree_height_cb       heightcb;          mode_tree_height_cb       heightcb;
           mode_tree_key_cb          keycb;
   
         struct mode_tree_list     children;          struct mode_tree_list     children;
         struct mode_tree_list     saved;          struct mode_tree_list     saved;
Line 74 
Line 75 
         void                            *itemdata;          void                            *itemdata;
         u_int                            line;          u_int                            line;
   
           key_code                         key;
           const char                      *keystr;
           size_t                           keylen;
   
         uint64_t                         tag;          uint64_t                         tag;
         const char                      *name;          const char                      *name;
         const char                      *text;          const char                      *text;
Line 135 
Line 140 
   
         free((void *)mti->name);          free((void *)mti->name);
         free((void *)mti->text);          free((void *)mti->text);
           free((void *)mti->keystr);
   
         free(mti);          free(mti);
 }  }
Line 193 
Line 199 
                         flat = 0;                          flat = 0;
                 if (mti->expanded)                  if (mti->expanded)
                         mode_tree_build_lines(mtd, &mti->children, depth + 1);                          mode_tree_build_lines(mtd, &mti->children, depth + 1);
   
                   if (mtd->keycb != NULL) {
                           mti->key = mtd->keycb(mtd->modedata, mti->itemdata,
                               mti->line);
                           if (mti->key == KEYC_UNKNOWN)
                                   mti->key = KEYC_NONE;
                   } else if (mti->line < 10)
                           mti->key = '0' + mti->line;
                   else if (mti->line < 36)
                           mti->key = KEYC_META|('a' + mti->line - 10);
                   else
                           mti->key = KEYC_NONE;
                   if (mti->key != KEYC_NONE) {
                           mti->keystr = xstrdup(key_string_lookup_key(mti->key,
                               0));
                           mti->keylen = strlen(mti->keystr);
                   } else {
                           mti->keystr = NULL;
                           mti->keylen = 0;
                   }
         }          }
         TAILQ_FOREACH(mti, mtl, entry) {          TAILQ_FOREACH(mti, mtl, entry) {
                 for (i = 0; i < mtd->line_size; i++) {                  for (i = 0; i < mtd->line_size; i++) {
Line 363 
Line 389 
 mode_tree_start(struct window_pane *wp, struct args *args,  mode_tree_start(struct window_pane *wp, struct args *args,
     mode_tree_build_cb buildcb, mode_tree_draw_cb drawcb,      mode_tree_build_cb buildcb, mode_tree_draw_cb drawcb,
     mode_tree_search_cb searchcb, mode_tree_menu_cb menucb,      mode_tree_search_cb searchcb, mode_tree_menu_cb menucb,
     mode_tree_height_cb heightcb, void *modedata,      mode_tree_height_cb heightcb, mode_tree_key_cb keycb, void *modedata,
     const struct menu_item *menu, const char **sort_list, u_int sort_size,      const struct menu_item *menu, const char **sort_list, u_int sort_size,
     struct screen **s)      struct screen **s)
 {  {
Line 402 
Line 428 
         mtd->searchcb = searchcb;          mtd->searchcb = searchcb;
         mtd->menucb = menucb;          mtd->menucb = menucb;
         mtd->heightcb = heightcb;          mtd->heightcb = heightcb;
           mtd->keycb = keycb;
   
         TAILQ_INIT(&mtd->children);          TAILQ_INIT(&mtd->children);
   
Line 596 
Line 623 
         struct screen_write_ctx  ctx;          struct screen_write_ctx  ctx;
         struct grid_cell         gc0, gc;          struct grid_cell         gc0, gc;
         u_int                    w, h, i, j, sy, box_x, box_y, width;          u_int                    w, h, i, j, sy, box_x, box_y, width;
         char                    *text, *start, key[7];          char                    *text, *start, *key;
         const char              *tag, *symbol;          const char              *tag, *symbol;
         size_t                   size, n;          size_t                   size, n;
         int                      keylen;          int                      keylen, pad;
   
         if (mtd->line_size == 0)          if (mtd->line_size == 0)
                 return;                  return;
Line 614 
Line 641 
         screen_write_start(&ctx, s);          screen_write_start(&ctx, s);
         screen_write_clearscreen(&ctx, 8);          screen_write_clearscreen(&ctx, 8);
   
         if (mtd->line_size > 10)          keylen = 0;
                 keylen = 6;          for (i = 0; i < mtd->line_size; i++) {
         else                  mti = mtd->line_list[i].item;
                 keylen = 4;                  if (mti->key == KEYC_NONE)
                           continue;
                   if ((int)mti->keylen + 3 > keylen)
                           keylen = mti->keylen + 3;
           }
   
         for (i = 0; i < mtd->line_size; i++) {          for (i = 0; i < mtd->line_size; i++) {
                 if (i < mtd->offset)                  if (i < mtd->offset)
                         continue;                          continue;
                 if (i > mtd->offset + h - 1)                  if (i > mtd->offset + h - 1)
                         break;                          break;
   
                 line = &mtd->line_list[i];                  line = &mtd->line_list[i];
                 mti = line->item;                  mti = line->item;
   
                 screen_write_cursormove(&ctx, 0, i - mtd->offset, 0);                  screen_write_cursormove(&ctx, 0, i - mtd->offset, 0);
   
                 if (i < 10)                  pad = keylen - 2 - mti->keylen;
                         snprintf(key, sizeof key, "(%c)  ", '0' + i);                  if (mti->key != KEYC_NONE)
                 else if (i < 36)                          xasprintf(&key, "(%s)%*s", mti->keystr, pad, "");
                         snprintf(key, sizeof key, "(M-%c)", 'a' + (i - 10));  
                 else                  else
                         *key = '\0';                          key = xstrdup("");
   
                 if (line->flat)                  if (line->flat)
                         symbol = "";                          symbol = "";
Line 698 
Line 727 
                         }                          }
                 }                  }
                 free(text);                  free(text);
                   free(key);
   
                 if (mti->tagged) {                  if (mti->tagged) {
                         gc.attr ^= GRID_ATTR_BRIGHT;                          gc.attr ^= GRID_ATTR_BRIGHT;
Line 951 
Line 981 
         struct mode_tree_item   *current, *parent, *mti;          struct mode_tree_item   *current, *parent, *mti;
         u_int                    i, x, y;          u_int                    i, x, y;
         int                      choice;          int                      choice;
         key_code                 tmp;  
   
         if (KEYC_IS_MOUSE(*key) && m != NULL) {          if (KEYC_IS_MOUSE(*key) && m != NULL) {
                 if (cmd_mouse_at(mtd->wp, m, &x, &y, 0) != 0) {                  if (cmd_mouse_at(mtd->wp, m, &x, &y, 0) != 0) {
Line 993 
Line 1022 
         current = line->item;          current = line->item;
   
         choice = -1;          choice = -1;
         if (*key >= '0' && *key <= '9')          for (i = 0; i < mtd->line_size; i++) {
                 choice = (*key) - '0';                  if (*key == mtd->line_list[i].item->key) {
         else if (((*key) & KEYC_MASK_MODIFIERS) == KEYC_META) {                          choice = i;
                 tmp = (*key) & KEYC_MASK_KEY;                          break;
                 if (tmp >= 'a' && tmp <= 'z')                  }
                         choice = 10 + (tmp - 'a');  
         }          }
         if (choice != -1) {          if (choice != -1) {
                 if ((u_int)choice > mtd->line_size - 1) {                  if ((u_int)choice > mtd->line_size - 1) {

Legend:
Removed from v.1.51  
changed lines
  Added in v.1.52