aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorRaheman Vaiya <r.vaiya@gmail.com>2021-12-26 18:57:04 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2021-12-26 18:57:44 +0100
commit8e310303903792c010d03c046ba75f8b18f7d3a7 (patch)
treef634e71e556b312e64ed1cc9ddd5b1e3fb3ced71 /st.c
parent2f6e597ed871cff91c627850d03152cae5f45779 (diff)
downloadst-patched-8e310303903792c010d03c046ba75f8b18f7d3a7.tar.bz2
st-patched-8e310303903792c010d03c046ba75f8b18f7d3a7.tar.xz
st-patched-8e310303903792c010d03c046ba75f8b18f7d3a7.zip
Add support for OSC color sequences
Diffstat (limited to 'st.c')
-rw-r--r--st.c80
1 files changed, 79 insertions, 1 deletions
diff --git a/st.c b/st.c
index a9338e1..781dbf2 100644
--- a/st.c
+++ b/st.c
@@ -1843,6 +1843,42 @@ csireset(void)
1843} 1843}
1844 1844
1845void 1845void
1846osc4_color_response(int num)
1847{
1848 int n;
1849 char buf[32];
1850 unsigned char r, g, b;
1851
1852 if (xgetcolor(num, &r, &g, &b)) {
1853 fprintf(stderr, "erresc: failed to fetch osc4 color %d\n", num);
1854 return;
1855 }
1856
1857 n = snprintf(buf, sizeof buf, "\033]4;%d;rgb:%02x%02x/%02x%02x/%02x%02x\007",
1858 num, r, r, g, g, b, b);
1859
1860 ttywrite(buf, n, 1);
1861}
1862
1863void
1864osc_color_response(int index, int num)
1865{
1866 int n;
1867 char buf[32];
1868 unsigned char r, g, b;
1869
1870 if (xgetcolor(index, &r, &g, &b)) {
1871 fprintf(stderr, "erresc: failed to fetch osc color %d\n", index);
1872 return;
1873 }
1874
1875 n = snprintf(buf, sizeof buf, "\033]%d;rgb:%02x%02x/%02x%02x/%02x%02x\007",
1876 num, r, r, g, g, b, b);
1877
1878 ttywrite(buf, n, 1);
1879}
1880
1881void
1846strhandle(void) 1882strhandle(void)
1847{ 1883{
1848 char *p = NULL, *dec; 1884 char *p = NULL, *dec;
@@ -1880,6 +1916,45 @@ strhandle(void)
1880 } 1916 }
1881 } 1917 }
1882 return; 1918 return;
1919 case 10:
1920 if (narg < 2)
1921 break;
1922
1923 p = strescseq.args[1];
1924
1925 if (!strcmp(p, "?"))
1926 osc_color_response(defaultfg, 10);
1927 else if (xsetcolorname(defaultfg, p))
1928 fprintf(stderr, "erresc: invalid foreground color: %s\n", p);
1929 else
1930 redraw();
1931 break;
1932 case 11:
1933 if (narg < 2)
1934 break;
1935
1936 p = strescseq.args[1];
1937
1938 if (!strcmp(p, "?"))
1939 osc_color_response(defaultbg, 11);
1940 else if (xsetcolorname(defaultbg, p))
1941 fprintf(stderr, "erresc: invalid background color: %s\n", p);
1942 else
1943 redraw();
1944 break;
1945 case 12:
1946 if (narg < 2)
1947 break;
1948
1949 p = strescseq.args[1];
1950
1951 if (!strcmp(p, "?"))
1952 osc_color_response(defaultcs, 12);
1953 else if (xsetcolorname(defaultcs, p))
1954 fprintf(stderr, "erresc: invalid cursor color: %s\n", p);
1955 else
1956 redraw();
1957 break;
1883 case 4: /* color set */ 1958 case 4: /* color set */
1884 if (narg < 3) 1959 if (narg < 3)
1885 break; 1960 break;
@@ -1887,7 +1962,10 @@ strhandle(void)
1887 /* FALLTHROUGH */ 1962 /* FALLTHROUGH */
1888 case 104: /* color reset, here p = NULL */ 1963 case 104: /* color reset, here p = NULL */
1889 j = (narg > 1) ? atoi(strescseq.args[1]) : -1; 1964 j = (narg > 1) ? atoi(strescseq.args[1]) : -1;
1890 if (xsetcolorname(j, p)) { 1965
1966 if (!strcmp(p, "?"))
1967 osc4_color_response(j);
1968 else if (xsetcolorname(j, p)) {
1891 if (par == 104 && narg <= 1) 1969 if (par == 104 && narg <= 1)
1892 return; /* color reset without parameter */ 1970 return; /* color reset without parameter */
1893 fprintf(stderr, "erresc: invalid color j=%d, p=%s\n", 1971 fprintf(stderr, "erresc: invalid color j=%d, p=%s\n",