screen-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[screen-devel] [PATCH] ansi: add support for xterm OSC 11


From: Lubomir Rintel
Subject: [screen-devel] [PATCH] ansi: add support for xterm OSC 11
Date: Wed, 30 Aug 2017 17:23:41 +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>
---
 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) {
                        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);
 }
 
 void ClearAllXtermOSC()
-- 
2.13.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]