Hey, On Wed, 30 Aug 2017 17:23:41 +0200 Lubomir Rintel <lkund...@v3.sk> wrote:
> 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 <lkund...@v3.sk> > --- > src/ansi.c | 16 +++++++++------- > src/display.c | 6 +++++- > 2 files changed, 14 insertions(+), 8 deletions(-) > > diff --git a/src/ansi.c b/src/ansi.c > index 8f3ddd6..034648b 100644 > --- a/src/ansi.c > +++ b/src/ansi.c > @@ -1250,22 +1250,24 @@ static int StringEnd(Window *win) > } > break; > } > - if (typ == 0 || typ == 1 || typ == 2 || typ == 20 || typ == 39 > || typ == 49) { > + if (typ == 0 || typ == 1 || typ == 2 || typ == 20 || typ == 39 > || typ == 49 || typ == 11) { Values here are in growing order, so put typ == 11 between 2 and 20 checks, for clarity. > int typ2; > typ2 = typ / 10; > - if (--typ2 < 0) > - typ2 = 0; > if (strcmp(win->w_xtermosc[typ2], p)) { > - strncpy(win->w_xtermosc[typ2], p, > ARRAY_SIZE(win->w_xtermosc[typ2]) - 1); > - > win->w_xtermosc[typ2][ARRAY_SIZE(win->w_xtermosc[typ2]) - 1] = 0; > + if (typ != 11 || strcmp("?", p)) { > + strncpy(win->w_xtermosc[typ2], p, > ARRAY_SIZE(win->w_xtermosc[typ2]) - 1); > + > win->w_xtermosc[typ2][ARRAY_SIZE(win->w_xtermosc[typ2]) - 1] = 0; > + } > > for (display = displays; display; display = > display->d_next) { > if (!D_CXT) > continue; > if (D_forecv->c_layer->l_bottom == > &win->w_layer) > - SetXtermOSC(typ2, > win->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 94eb2e5..af4ec2a 100644 > --- a/src/display.c > +++ b/src/display.c > @@ -2128,6 +2128,7 @@ void SetXtermOSC(int i, 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?) */ > @@ -2147,7 +2148,10 @@ void SetXtermOSC(int i, char *s) > AddStr("\033]"); > AddStr(oscs[i][0]); > AddStr(s); > - AddChar(7); > + if (i == 1) > + AddStr("\033\\"); > + else > + AddChar(7); From what I can see string terminator can either be "\e\\" or '\a' (http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Operating-System-Commands), so it would be nice if we could handle both correctly, without forcing one depending on i parameter. In xterm I see: $ echo -ne "\e]11;?\e\\" ^[]11;rgb:0000/0000/0505^[\ $ echo -ne "\e]11;?\a" ^[]11;rgb:0000/0000/0505^G > } > > void ClearAllXtermOSC() Do notice that you change SetXtermOSC, and there are 2 places in code, where code loops over all values, so you need to also update those. display.c-2160- for (i = 3; i >= 0; i--) display.c:2161: SetXtermOSC(i, 0); process.c-5671- for (i = 3; i >= 0; i--) process.c:5672: SetXtermOSC(i, p ? p->w_xtermosc[i] : 0); Cheers, Amadeusz