screen-devel
[Top][All Lists]
Advanced

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

[screen-devel] [PATCH 1/2 v2] ansi: add support for xterm OSC 11


From: Lubomir Rintel
Subject: [screen-devel] [PATCH 1/2 v2] ansi: add support for xterm OSC 11
Date: Thu, 31 Aug 2017 16:27:55 +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>
---
Changed in v2:
 * Reordered the type condition by their numeric value
 * Updated the places that iterate oscs[] with correct array length
 * Backed out the change of the OSC terminator sequence

 src/ansi.c    | 16 +++++++++-------
 src/display.c |  3 ++-
 src/process.c |  2 +-
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/ansi.c b/src/ansi.c
index 8f3ddd6..b3e3889 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 == 11 || typ == 20 
|| typ == 39 || typ == 49) {
                        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..43546b0 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?) */
@@ -2153,7 +2154,7 @@ void SetXtermOSC(int i, char *s)
 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 d99c6be..d8794cd 100644
--- a/src/process.c
+++ b/src/process.c
@@ -5668,7 +5668,7 @@ void RefreshXtermOSC()
        Window *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);
 }
 
-- 
2.13.5




reply via email to

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