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

Diff for /src/usr.bin/tmux/input.c between version 1.185 and 1.186

version 1.185, 2020/10/30 11:34:13 version 1.186, 2021/02/15 09:39:38
Line 138 
Line 138 
 static void     input_osc_11(struct input_ctx *, const char *);  static void     input_osc_11(struct input_ctx *, const char *);
 static void     input_osc_52(struct input_ctx *, const char *);  static void     input_osc_52(struct input_ctx *, const char *);
 static void     input_osc_104(struct input_ctx *, const char *);  static void     input_osc_104(struct input_ctx *, const char *);
   static void     input_osc_110(struct input_ctx *, const char *);
   static void     input_osc_111(struct input_ctx *, const char *);
   
 /* Transition entry/exit handlers. */  /* Transition entry/exit handlers. */
 static void     input_clear(struct input_ctx *);  static void     input_clear(struct input_ctx *);
Line 2304 
Line 2306 
         case 104:          case 104:
                 input_osc_104(ictx, p);                  input_osc_104(ictx, p);
                 break;                  break;
           case 110:
                   input_osc_110(ictx, p);
                   break;
           case 111:
                   input_osc_111(ictx, p);
                   break;
         case 112:          case 112:
                 if (*p == '\0') /* no arguments allowed */                  if (*p == '\0') /* no arguments allowed */
                         screen_set_cursor_colour(sctx->s, "");                          screen_set_cursor_colour(sctx->s, "");
Line 2422 
Line 2430 
   
 /* Parse colour from OSC. */  /* Parse colour from OSC. */
 static int  static int
 input_osc_parse_colour(const char *p, u_int *r, u_int *g, u_int *b)  input_osc_parse_colour(const char *p)
 {  {
         u_int            rsize, gsize, bsize;          double   c, m, y, k = 0;
         const char      *cp, *s = p;          u_int    r, g, b;
           size_t   len = strlen(p);
           int      colour = -1;
           char    *copy;
   
         if (sscanf(p, "rgb:%x/%x/%x", r, g, b) != 3)          if ((len == 12 && sscanf(p, "rgb:%02x/%02x/%02x", &r, &g, &b) == 3) ||
                 return (0);              (len == 7 && sscanf(p, "#%02x%02x%02x", &r, &g, &b) == 3) ||
         p += 4;              sscanf(p, "%d,%d,%d", &r, &g, &b) == 3)
                   colour = colour_join_rgb(r, g, b);
         cp = strchr(p, '/');          else if ((len == 18 &&
         rsize = cp - p;              sscanf(p, "rgb:%04x/%04x/%04x", &r, &g, &b) == 3) ||
         if (rsize == 1)              (len == 13 && sscanf(p, "#%04x%04x%04x", &r, &g, &b) == 3))
                 (*r) = (*r) | ((*r) << 4);                  colour = colour_join_rgb(r >> 8, g >> 8, b >> 8);
         else if (rsize == 3)          else if ((sscanf(p, "cmyk:%lf/%lf/%lf/%lf", &c, &m, &y, &k) == 4 ||
                 (*r) >>= 4;              sscanf(p, "cmy:%lf/%lf/%lf", &c, &m, &y) == 3) &&
         else if (rsize == 4)              c >= 0 && c <= 1 && m >= 0 && m <= 1 &&
                 (*r) >>= 8;              y >= 0 && y <= 1 && k >= 0 && k <= 1) {
         else if (rsize != 2)                  colour = colour_join_rgb(
                 return (0);                      (1 - c) * (1 - k) * 255,
                       (1 - m) * (1 - k) * 255,
         p = cp + 1;                      (1 - y) * (1 - k) * 255);
         cp = strchr(p, '/');          } else {
         gsize = cp - p;                  while (*p == ' ')
         if (gsize == 1)                          p++;
                 (*g) = (*g) | ((*g) << 4);                  while (len != 0 && p[len - 1] == ' ')
         else if (gsize == 3)                          len--;
                 (*g) >>= 4;                  copy = xstrndup(p, len);
         else if (gsize == 4)                  colour = colour_byname(copy);
                 (*g) >>= 8;                  free(copy);
         else if (gsize != 2)          }
                 return (0);          log_debug("%s: %s = %s", __func__, p, colour_tostring(colour));
           return (colour);
         bsize = strlen(cp + 1);  
         if (bsize == 1)  
                 (*b) = (*b) | ((*b) << 4);  
         else if (bsize == 3)  
                 (*b) >>= 4;  
         else if (bsize == 4)  
                 (*b) >>= 8;  
         else if (bsize != 2)  
                 return (0);  
   
         log_debug("%s: %s = %02x%02x%02x", __func__, s, *r, *g, *b);  
         return (1);  
 }  }
   
 /* Reply to a colour request. */  /* Reply to a colour request. */
Line 2493 
Line 2492 
         struct window_pane      *wp = ictx->wp;          struct window_pane      *wp = ictx->wp;
         char                    *copy, *s, *next = NULL;          char                    *copy, *s, *next = NULL;
         long                     idx;          long                     idx;
         u_int                    r, g, b;          int                      c;
   
         if (wp == NULL)          if (wp == NULL)
                 return;                  return;
Line 2507 
Line 2506 
                         goto bad;                          goto bad;
   
                 s = strsep(&next, ";");                  s = strsep(&next, ";");
                 if (!input_osc_parse_colour(s, &r, &g, &b)) {                  if ((c = input_osc_parse_colour(s)) == -1) {
                         s = next;                          s = next;
                         continue;                          continue;
                 }                  }
   
                 window_pane_set_palette(wp, idx, colour_join_rgb(r, g, b));                  window_pane_set_palette(wp, idx, c);
                 s = next;                  s = next;
         }          }
   
Line 2530 
Line 2529 
 {  {
         struct window_pane      *wp = ictx->wp;          struct window_pane      *wp = ictx->wp;
         struct grid_cell         defaults;          struct grid_cell         defaults;
         u_int                    r, g, b;          int                      c;
   
         if (wp == NULL)          if (wp == NULL)
                 return;                  return;
Line 2541 
Line 2540 
                 return;                  return;
         }          }
   
         if (!input_osc_parse_colour(p, &r, &g, &b))          if ((c = input_osc_parse_colour(p)) == -1)
                 goto bad;                  goto bad;
         wp->fg = colour_join_rgb(r, g, b);          wp->fg = c;
         wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);          wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
   
         return;          return;
Line 2552 
Line 2551 
         log_debug("bad OSC 10: %s", p);          log_debug("bad OSC 10: %s", p);
 }  }
   
   /* Handle the OSC 110 sequence for resetting background colour. */
   static void
   input_osc_110(struct input_ctx *ictx, const char *p)
   {
           struct window_pane      *wp = ictx->wp;
   
           if (wp == NULL)
                   return;
   
           if (*p != '\0')
                   return;
   
           wp->fg = 8;
           wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
   }
   
 /* Handle the OSC 11 sequence for setting and querying background colour. */  /* Handle the OSC 11 sequence for setting and querying background colour. */
 static void  static void
 input_osc_11(struct input_ctx *ictx, const char *p)  input_osc_11(struct input_ctx *ictx, const char *p)
 {  {
         struct window_pane      *wp = ictx->wp;          struct window_pane      *wp = ictx->wp;
         struct grid_cell         defaults;          struct grid_cell         defaults;
         u_int                    r, g, b;          int                      c;
   
         if (wp == NULL)          if (wp == NULL)
                 return;                  return;
Line 2569 
Line 2584 
                 return;                  return;
         }          }
   
         if (!input_osc_parse_colour(p, &r, &g, &b))          if ((c = input_osc_parse_colour(p)) == -1)
             goto bad;                  goto bad;
         wp->bg = colour_join_rgb(r, g, b);          wp->bg = c;
         wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);          wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
   
         return;          return;
   
 bad:  bad:
         log_debug("bad OSC 11: %s", p);          log_debug("bad OSC 11: %s", p);
   }
   
   /* Handle the OSC 111 sequence for resetting background colour. */
   static void
   input_osc_111(struct input_ctx *ictx, const char *p)
   {
           struct window_pane      *wp = ictx->wp;
   
           if (wp == NULL)
                   return;
   
           if (*p != '\0')
                   return;
   
           wp->bg = 8;
           wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
 }  }
   
 /* Handle the OSC 52 sequence for setting the clipboard. */  /* Handle the OSC 52 sequence for setting the clipboard. */

Legend:
Removed from v.1.185  
changed lines
  Added in v.1.186