[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[screen-devel] [PATCH 1/2] [screen-v4] ansi: add support for xterm OSC 1
From: |
Lubomir Rintel |
Subject: |
[screen-devel] [PATCH 1/2] [screen-v4] ansi: add support for xterm OSC 11 |
Date: |
Mon, 10 Sep 2018 19:34:02 +0200 |
It allows for getting and setting the background color. Notably, Vim uses
OSC 11 to learn whether it's running on a light or dark colored terminal
and choose a color scheme accordingly.
Tested with gnome-terminal and xterm. When called with "?" argument the
current background color is returned:
$ echo -ne "\e]11;?\e\\"
$ 11;rgb:2323/2727/2929
Signed-off-by: Lubomir Rintel <address@hidden>
(cherry picked from commit 7059bff20a28778f9d3acf81cad07b1388d02309)
---
src/ansi.c | 17 ++++++++++-------
src/display.c | 3 ++-
src/process.c | 2 +-
3 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/src/ansi.c b/src/ansi.c
index d2b3cbc..28e3529 100644
--- a/src/ansi.c
+++ b/src/ansi.c
@@ -1562,25 +1562,28 @@ StringEnd()
}
#endif
#ifdef RXVT_OSC
- if (typ == 0 || typ == 1 || typ == 2 || typ == 20 || typ == 39 || typ ==
49)
+ if (typ == 0 || typ == 1 || typ == 2 || typ == 11 || typ == 20 || typ ==
39 || typ == 49)
{
int typ2;
typ2 = typ / 10;
- if (--typ2 < 0)
- typ2 = 0;
if (strcmp(curr->w_xtermosc[typ2], p))
{
- strncpy(curr->w_xtermosc[typ2], p, sizeof(curr->w_xtermosc[typ2])
- 1);
- curr->w_xtermosc[typ2][sizeof(curr->w_xtermosc[typ2]) - 1] = 0;
+ if (typ != 11 || strcmp("?", p))
+ {
+ strncpy(curr->w_xtermosc[typ2], p,
sizeof(curr->w_xtermosc[typ2]) - 1);
+ curr->w_xtermosc[typ2][sizeof(curr->w_xtermosc[typ2]) - 1] =
0;
+ }
for (display = displays; display; display = display->d_next)
{
if (!D_CXT)
continue;
if (D_forecv->c_layer->l_bottom == &curr->w_layer)
- SetXtermOSC(typ2, curr->w_xtermosc[typ2]);
- if ((typ2 == 2 || typ2 == 3) && D_xtermosc[typ2])
+ SetXtermOSC(typ2, p);
+ if ((typ2 == 3 || typ2 == 4) && D_xtermosc[typ2])
Redisplay(0);
+ if (typ == 11 && !strcmp("?", p))
+ break;
}
}
}
diff --git a/src/display.c b/src/display.c
index 190d418..dbc7d74 100644
--- a/src/display.c
+++ b/src/display.c
@@ -2939,6 +2939,7 @@ char *s;
{
static char *oscs[][2] = {
{ WT_FLAG ";", "screen" }, /* set window title */
+ { "11;", ""}, /* background RGB */
{ "20;", "" }, /* background */
{ "39;", "black" }, /* default foreground (black?) */
{ "49;", "white" } /* default background (white?) */
@@ -2966,7 +2967,7 @@ void
ClearAllXtermOSC()
{
int i;
- for (i = 3; i >= 0; i--)
+ for (i = 4; i >= 0; i--)
SetXtermOSC(i, 0);
if (D_xtermosc[0])
AddStr("\033[23;" WT_FLAG "t"); /* unstack titles (xterm patch #251) */
diff --git a/src/process.c b/src/process.c
index ec5a911..3c7cce8 100644
--- a/src/process.c
+++ b/src/process.c
@@ -7190,7 +7190,7 @@ RefreshXtermOSC()
struct win *p;
p = Layer2Window(D_forecv->c_layer);
- for (i = 3; i >=0; i--)
+ for (i = 4; i >=0; i--)
SetXtermOSC(i, p ? p->w_xtermosc[i] : 0);
}
#endif
--
2.17.1