termptyesc: handle xterm color format starting with "rgbi:"

devs/bu5hm4n/fix-for-billiob
Boris Faure 2 years ago
parent 2245782dd4
commit ac9a92480b
Signed by: borisfaure
GPG Key ID: 35C0410516166BE8
  1. 62
      src/bin/termptyesc.c
  2. 1
      tests/tests.results
  3. 45
      tests/xterm-colors-rgbi.sh

@ -3762,14 +3762,64 @@ _xterm_parse_color_sharp(Eina_Unicode *p,
return 0;
}
/* returns len read or -1 in case of error */
static int
_xterm_parse_color_rgbi(Eina_Unicode *p EINA_UNUSED,
unsigned char *r EINA_UNUSED,
unsigned char *g EINA_UNUSED,
unsigned char *b EINA_UNUSED,
int len EINA_UNUSED)
_xterm_parse_intensity(Eina_Unicode *p, unsigned char *c, int len)
{
return -1;
int l = 0;
char buf[64];
char *endptr_double;
double d;
while (l < 64 && len && p[0] && p[0] != '/' && p[0] != '\007' && p[0] < 128)
{
buf[l++] = p[0];
len--;
p++;
}
if (l == 0)
return -1;
buf[l] = '\0';
d = eina_convert_strtod_c(buf, &endptr_double);
if (endptr_double == buf || d < 0 || d > 1.0 || isnan(d))
return -1;
*c = d * 255.0;
return endptr_double - buf;
}
static int
_xterm_parse_color_rgbi(Eina_Unicode *p,
unsigned char *r,
unsigned char *g,
unsigned char *b,
int len)
{
int l;
/* parse r */
l = _xterm_parse_intensity(p, r, len);
if (l <= 0)
return -1;
p += l;
if (p[0] != '/')
return -1;
p++;
/* parse g */
l = _xterm_parse_intensity(p, g, len);
if (l <= 0)
return -1;
p += l;
if (p[0] != '/')
return -1;
p++;
/* parse b */
l = _xterm_parse_intensity(p, b, len);
if (l <= 0)
return -1;
return 0;
}
/* returns len read or -1 in case of error */

@ -147,3 +147,4 @@ xterm-osc-10.sh b8c23c9c5482b1e9c30d8a261edc29f0
xterm-osc-11.sh 3e02038964b78d948fb599c996bf370d
xterm-colors-sharp.sh 79d6f72df04237d76a0fa3e722dcec5b
xterm-colors-rgb.sh d9b55817ef8428343105b44dabd535a8
xterm-colors-rgbi.sh d9b55817ef8428343105b44dabd535a8

@ -0,0 +1,45 @@
#!/bin/sh
# char width: 7
# char height: 15
# set color
printf '\033[0;31;3m'
# clear screen
printf '\033[2J'
# move to 0; 0
printf '\033[0;0H'
# set color
printf '\033[0m'
printf 'The purpose of computing is insight, not numbers.\r\n'
printf 'Richard Hamming\r\n'
# valid colors
printf '\033]10;rgbi:1.0/0/1.0\007'
printf '\033]10;rgbi:1/0.0/1\007'
printf '\033]10;rgbi:1/0.0/1\007'
##
# invalid
##
printf '\033]10;rgbi:1.1/0/1\007'
printf '\033]10;rgbi:f/1.1/1\007'
printf '\033]10;rgbi:f/0/1.1\007'
printf '\033]10;rgbi:-0.1/0/1\007'
printf '\033]10;rgbi:1/-0.1/1\007'
printf '\033]10;rgbi:1/0/-0.1\007'
printf '\033]10;rgbi:+Inf/0/1\007'
printf '\033]10;rgbi:1/+Inf/0\007'
printf '\033]10;rgbi:1/0/+Inf\007'
printf '\033]10;rgbi:1.0|0.0/1.0\007'
printf '\033]10;rgbi:1.0/0.0|1.0\007'
printf '\033]10;rgbi:1.0/0.0/1.0/0.0\007'
Loading…
Cancel
Save