summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2020-07-02 23:01:42 +0200
committerBoris Faure <billiob@gmail.com>2020-07-02 23:01:42 +0200
commitac9a92480b24d76ad9ecdd6dda50b7bbc741dfef (patch)
treed8272a6204ab458c47de4c49eb4223e29311f7f5
parent2245782dd45728619b8ba024aaf3055e6e0cc1db (diff)
termptyesc: handle xterm color format starting with "rgbi:"
-rw-r--r--src/bin/termptyesc.c62
-rw-r--r--tests/tests.results1
-rwxr-xr-xtests/xterm-colors-rgbi.sh45
3 files changed, 102 insertions, 6 deletions
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index f4f7940..76e0991 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -3762,14 +3762,64 @@ _xterm_parse_color_sharp(Eina_Unicode *p,
3762 return 0; 3762 return 0;
3763} 3763}
3764 3764
3765/* returns len read or -1 in case of error */
3765static int 3766static int
3766_xterm_parse_color_rgbi(Eina_Unicode *p EINA_UNUSED, 3767_xterm_parse_intensity(Eina_Unicode *p, unsigned char *c, int len)
3767 unsigned char *r EINA_UNUSED,
3768 unsigned char *g EINA_UNUSED,
3769 unsigned char *b EINA_UNUSED,
3770 int len EINA_UNUSED)
3771{ 3768{
3772 return -1; 3769 int l = 0;
3770 char buf[64];
3771 char *endptr_double;
3772 double d;
3773
3774 while (l < 64 && len && p[0] && p[0] != '/' && p[0] != '\007' && p[0] < 128)
3775 {
3776 buf[l++] = p[0];
3777 len--;
3778 p++;
3779 }
3780 if (l == 0)
3781 return -1;
3782 buf[l] = '\0';
3783
3784 d = eina_convert_strtod_c(buf, &endptr_double);
3785 if (endptr_double == buf || d < 0 || d > 1.0 || isnan(d))
3786 return -1;
3787
3788 *c = d * 255.0;
3789 return endptr_double - buf;
3790}
3791
3792static int
3793_xterm_parse_color_rgbi(Eina_Unicode *p,
3794 unsigned char *r,
3795 unsigned char *g,
3796 unsigned char *b,
3797 int len)
3798{
3799 int l;
3800
3801 /* parse r */
3802 l = _xterm_parse_intensity(p, r, len);
3803 if (l <= 0)
3804 return -1;
3805 p += l;
3806 if (p[0] != '/')
3807 return -1;
3808 p++;
3809 /* parse g */
3810 l = _xterm_parse_intensity(p, g, len);
3811 if (l <= 0)
3812 return -1;
3813 p += l;
3814 if (p[0] != '/')
3815 return -1;
3816 p++;
3817 /* parse b */
3818 l = _xterm_parse_intensity(p, b, len);
3819 if (l <= 0)
3820 return -1;
3821
3822 return 0;
3773} 3823}
3774 3824
3775/* returns len read or -1 in case of error */ 3825/* returns len read or -1 in case of error */
diff --git a/tests/tests.results b/tests/tests.results
index 1d33d20..7977578 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -147,3 +147,4 @@ xterm-osc-10.sh b8c23c9c5482b1e9c30d8a261edc29f0
147xterm-osc-11.sh 3e02038964b78d948fb599c996bf370d 147xterm-osc-11.sh 3e02038964b78d948fb599c996bf370d
148xterm-colors-sharp.sh 79d6f72df04237d76a0fa3e722dcec5b 148xterm-colors-sharp.sh 79d6f72df04237d76a0fa3e722dcec5b
149xterm-colors-rgb.sh d9b55817ef8428343105b44dabd535a8 149xterm-colors-rgb.sh d9b55817ef8428343105b44dabd535a8
150xterm-colors-rgbi.sh d9b55817ef8428343105b44dabd535a8
diff --git a/tests/xterm-colors-rgbi.sh b/tests/xterm-colors-rgbi.sh
new file mode 100755
index 0000000..8508dca
--- /dev/null
+++ b/tests/xterm-colors-rgbi.sh
@@ -0,0 +1,45 @@
1#!/bin/sh
2
3# char width: 7
4# char height: 15
5
6# set color
7printf '\033[0;31;3m'
8
9# clear screen
10printf '\033[2J'
11
12# move to 0; 0
13printf '\033[0;0H'
14
15# set color
16printf '\033[0m'
17
18printf 'The purpose of computing is insight, not numbers.\r\n'
19printf 'Richard Hamming\r\n'
20
21# valid colors
22printf '\033]10;rgbi:1.0/0/1.0\007'
23printf '\033]10;rgbi:1/0.0/1\007'
24printf '\033]10;rgbi:1/0.0/1\007'
25
26##
27# invalid
28##
29
30printf '\033]10;rgbi:1.1/0/1\007'
31printf '\033]10;rgbi:f/1.1/1\007'
32printf '\033]10;rgbi:f/0/1.1\007'
33
34printf '\033]10;rgbi:-0.1/0/1\007'
35printf '\033]10;rgbi:1/-0.1/1\007'
36printf '\033]10;rgbi:1/0/-0.1\007'
37
38printf '\033]10;rgbi:+Inf/0/1\007'
39printf '\033]10;rgbi:1/+Inf/0\007'
40printf '\033]10;rgbi:1/0/+Inf\007'
41
42printf '\033]10;rgbi:1.0|0.0/1.0\007'
43printf '\033]10;rgbi:1.0/0.0|1.0\007'
44
45printf '\033]10;rgbi:1.0/0.0/1.0/0.0\007'