Skip to content

Commit 9814075

Browse files
committed
1 parent 590df0a commit 9814075

File tree

4 files changed

+108
-5
lines changed

4 files changed

+108
-5
lines changed

config.def.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,22 @@ static const char *colorname[] = {
115115
[13] = "#d3869b", /* magenta */
116116
[14] = "#8ec07c", /* cyan */
117117
[15] = "#ebdbb2", /* white */
118+
119+
[255] = 0,
120+
121+
/* More colors can be added after 255 to use with DefaultXX. */
122+
"#cccccc",
123+
"#555555",
124+
"gray90", /* default foreground color */
125+
"black", /* default background color */
118126
};
119127

120128
/* Default colors (colorname index).
121129
*/
122-
unsigned int defaultfg = 15; /* foreground color */
123-
unsigned int defaultbg = 0; /* background color */
124-
static unsigned int defaultcs = 15; /* cursor color */
125-
static unsigned int defaultrcs = 257; /* reverse cursor color */
130+
unsigned int defaultfg = 15; /* foreground color */
131+
unsigned int defaultbg = 0; /* background color */
132+
unsigned int defaultcs = 15; /* cursor color */
133+
unsigned int defaultrcs = 258; /* reverse cursor color */
126134

127135
/*********************************************************************
128136
* [VimBrowse] settings and appearance.

st.c

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ static void csidump(void);
174174
static void csihandle(void);
175175
static void csiparse(void);
176176
static void csireset(void);
177+
static void osc4_color_response(int num);
178+
static void osc_color_response(int index, int num);
177179
static int eschandle(uchar);
178180
static void strdump(void);
179181
static void strhandle(void);
@@ -1932,6 +1934,42 @@ csireset(void)
19321934
memset(&csiescseq, 0, sizeof(csiescseq));
19331935
}
19341936

1937+
void
1938+
osc4_color_response(int num)
1939+
{
1940+
int n;
1941+
char buf[32];
1942+
unsigned char r, g, b;
1943+
1944+
if (xgetcolor(num, &r, &g, &b)) {
1945+
fprintf(stderr, "erresc: failed to fetch osc4 color %d\n", num);
1946+
return;
1947+
}
1948+
1949+
n = snprintf(buf, sizeof buf, "\033]4;%d;rgb:%02x%02x/%02x%02x/%02x%02x\007",
1950+
num, r, r, g, g, b, b);
1951+
1952+
ttywrite(buf, n, 1);
1953+
}
1954+
1955+
void
1956+
osc_color_response(int index, int num)
1957+
{
1958+
int n;
1959+
char buf[32];
1960+
unsigned char r, g, b;
1961+
1962+
if (xgetcolor(index, &r, &g, &b)) {
1963+
fprintf(stderr, "erresc: failed to fetch osc color %d\n", index);
1964+
return;
1965+
}
1966+
1967+
n = snprintf(buf, sizeof buf, "\033]%d;rgb:%02x%02x/%02x%02x/%02x%02x\007",
1968+
num, r, r, g, g, b, b);
1969+
1970+
ttywrite(buf, n, 1);
1971+
}
1972+
19351973
void
19361974
strhandle(void)
19371975
{
@@ -1970,14 +2008,56 @@ strhandle(void)
19702008
}
19712009
}
19722010
return;
2011+
case 10:
2012+
if (narg < 2)
2013+
break;
2014+
2015+
p = strescseq.args[1];
2016+
2017+
if (!strcmp(p, "?"))
2018+
osc_color_response(defaultfg, 10);
2019+
else if (xsetcolorname(defaultfg, p))
2020+
fprintf(stderr, "erresc: invalid foreground color: %s\n", p);
2021+
else
2022+
redraw();
2023+
break;
2024+
case 11:
2025+
if (narg < 2)
2026+
break;
2027+
2028+
p = strescseq.args[1];
2029+
2030+
if (!strcmp(p, "?"))
2031+
osc_color_response(defaultbg, 11);
2032+
else if (xsetcolorname(defaultbg, p))
2033+
fprintf(stderr, "erresc: invalid background color: %s\n", p);
2034+
else
2035+
redraw();
2036+
break;
2037+
case 12:
2038+
if (narg < 2)
2039+
break;
2040+
2041+
p = strescseq.args[1];
2042+
2043+
if (!strcmp(p, "?"))
2044+
osc_color_response(defaultcs, 12);
2045+
else if (xsetcolorname(defaultcs, p))
2046+
fprintf(stderr, "erresc: invalid cursor color: %s\n", p);
2047+
else
2048+
redraw();
2049+
break;
19732050
case 4: /* color set */
19742051
if (narg < 3)
19752052
break;
19762053
p = strescseq.args[2];
19772054
/* FALLTHROUGH */
19782055
case 104: /* color reset, here p = NULL */
19792056
j = (narg > 1) ? atoi(strescseq.args[1]) : -1;
1980-
if (xsetcolorname(j, p)) {
2057+
2058+
if (!strcmp(p, "?"))
2059+
osc4_color_response(j);
2060+
else if (xsetcolorname(j, p)) {
19812061
if (par == 104 && narg <= 1)
19822062
return; /* color reset without parameter */
19832063
fprintf(stderr, "erresc: invalid color j=%d, p=%s\n",

st.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ void *xmalloc(size_t);
123123
void *xrealloc(void *, size_t);
124124
char *xstrdup(const char *);
125125

126+
int xgetcolor(int x, unsigned char *r, unsigned char *g, unsigned char *b);
126127
/*
127128
* config.h globals
128129
*/
@@ -137,6 +138,7 @@ extern char *termname;
137138
extern unsigned int tabspaces;
138139
extern unsigned int defaultfg;
139140
extern unsigned int defaultbg;
141+
extern unsigned int defaultcs;
140142

141143
/*
142144
* copyurl

x.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,19 @@ xloadcols(void)
838838
loaded = 1;
839839
}
840840

841+
int
842+
xgetcolor(int x, unsigned char *r, unsigned char *g, unsigned char *b)
843+
{
844+
if (!BETWEEN(x, 0, dc.collen))
845+
return 1;
846+
847+
*r = dc.col[x].color.red >> 8;
848+
*g = dc.col[x].color.green >> 8;
849+
*b = dc.col[x].color.blue >> 8;
850+
851+
return 0;
852+
}
853+
841854
int
842855
xsetcolorname(int x, const char *name)
843856
{

0 commit comments

Comments
 (0)