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-8e310303903792c010d03c046ba75f8b18f7d3a7.tar.gz
st-8e310303903792c010d03c046ba75f8b18f7d3a7.tar.bz2
st-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)
}
void
+osc4_color_response(int num)
+{
+ int n;
+ char buf[32];
+ unsigned char r, g, b;
+
+ if (xgetcolor(num, &r, &g, &b)) {
+ fprintf(stderr, "erresc: failed to fetch osc4 color %d\n", num);
+ return;
+ }
+
+ n = snprintf(buf, sizeof buf, "\033]4;%d;rgb:%02x%02x/%02x%02x/%02x%02x\007",
+ num, r, r, g, g, b, b);
+
+ ttywrite(buf, n, 1);
+}
+
+void
+osc_color_response(int index, int num)
+{
+ int n;
+ char buf[32];
+ unsigned char r, g, b;
+
+ if (xgetcolor(index, &r, &g, &b)) {
+ fprintf(stderr, "erresc: failed to fetch osc color %d\n", index);
+ return;
+ }
+
+ n = snprintf(buf, sizeof buf, "\033]%d;rgb:%02x%02x/%02x%02x/%02x%02x\007",
+ num, r, r, g, g, b, b);
+
+ ttywrite(buf, n, 1);
+}
+
+void
strhandle(void)
{
char *p = NULL, *dec;
@@ -1880,6 +1916,45 @@ strhandle(void)
}
}
return;
+ case 10:
+ if (narg < 2)
+ break;
+
+ p = strescseq.args[1];
+
+ if (!strcmp(p, "?"))
+ osc_color_response(defaultfg, 10);
+ else if (xsetcolorname(defaultfg, p))
+ fprintf(stderr, "erresc: invalid foreground color: %s\n", p);
+ else
+ redraw();
+ break;
+ case 11:
+ if (narg < 2)
+ break;
+
+ p = strescseq.args[1];
+
+ if (!strcmp(p, "?"))
+ osc_color_response(defaultbg, 11);
+ else if (xsetcolorname(defaultbg, p))
+ fprintf(stderr, "erresc: invalid background color: %s\n", p);
+ else
+ redraw();
+ break;
+ case 12:
+ if (narg < 2)
+ break;
+
+ p = strescseq.args[1];
+
+ if (!strcmp(p, "?"))
+ osc_color_response(defaultcs, 12);
+ else if (xsetcolorname(defaultcs, p))
+ fprintf(stderr, "erresc: invalid cursor color: %s\n", p);
+ else
+ redraw();
+ break;
case 4: /* color set */
if (narg < 3)
break;
@@ -1887,7 +1962,10 @@ strhandle(void)
/* FALLTHROUGH */
case 104: /* color reset, here p = NULL */
j = (narg > 1) ? atoi(strescseq.args[1]) : -1;
- if (xsetcolorname(j, p)) {
+
+ if (!strcmp(p, "?"))
+ osc4_color_response(j);
+ else if (xsetcolorname(j, p)) {
if (par == 104 && narg <= 1)
return; /* color reset without parameter */
fprintf(stderr, "erresc: invalid color j=%d, p=%s\n",