qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs tty.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs tty.c
Date: Thu, 4 May 2017 04:15:16 -0400 (EDT)

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        17/05/04 04:15:16

Modified files:
        .              : tty.c 

Log message:
        tty: improve terminal color capabilities  detection
        - use COLORTERM environment variable
        - detect OS/X iTerm.app

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/tty.c?cvsroot=qemacs&r1=1.83&r2=1.84

Patches:
Index: tty.c
===================================================================
RCS file: /sources/qemacs/qemacs/tty.c,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -b -r1.83 -r1.84
--- tty.c       25 Apr 2017 16:58:46 -0000      1.83
+++ tty.c       4 May 2017 08:15:16 -0000       1.84
@@ -163,6 +163,7 @@
     TTYState *ts;
     struct termios tty;
     struct sigaction sig;
+    const char *p;
 
     ts = calloc(1, sizeof(*ts));
     if (ts == NULL) {
@@ -207,32 +208,41 @@
                               USE_BOLD_AS_BRIGHT_FG | USE_BLINK_AS_BRIGHT_BG;
         }
     }
-#if TTY_STYLE_BITS == 32
     if (strstr(ts->term_name, "true") || strstr(ts->term_name, "24")) {
-        ts->term_flags |= USE_TRUE_COLORS;
+        ts->term_flags |= USE_TRUE_COLORS | USE_256_COLORS;
     }
-#endif
     if (strstr(ts->term_name, "256")) {
         ts->term_flags |= USE_256_COLORS;
     }
+    if ((p = getenv("TERM_PROGRAM")) && strequal(p, "iTerm.app")) {
+        /* iTerm and iTerm2 support true colors */
+        ts->term_flags |= USE_TRUE_COLORS | USE_256_COLORS;
+    }        
     /* actual color mode can be forced via environment variables */
     /* XXX: should have qemacs variables too */
+    if ((p = getenv("COLORTERM")) != NULL) {
+        /* Check COLORTERM environment variable as documented in
+         * https://gist.github.com/XVilka/8346728
+         */
 #if TTY_STYLE_BITS == 32
-    if (getenv("USE_24_BIT_COLORS") || getenv("USE_TRUE_COLORS")) {
+        if (strstr(p, "truecolor")
+        ||  strstr(p, "24bit")
+        ||  strstr(p, "hicolor")) {
         ts->term_flags &= ~(USE_BOLD_AS_BRIGHT_FG | USE_BLINK_AS_BRIGHT_BG |
                             USE_256_COLORS | USE_TRUE_COLORS);
         ts->term_flags |= USE_TRUE_COLORS;
     } else
 #endif
-    if (getenv("USE_256_COLORS")) {
+        if (strstr(p, "256")) {
         ts->term_flags &= ~(USE_BOLD_AS_BRIGHT_FG | USE_BLINK_AS_BRIGHT_BG |
                             USE_256_COLORS | USE_TRUE_COLORS);
         ts->term_flags |= USE_256_COLORS;
     } else
-    if (getenv("USE_16_COLORS")) {
+        if (strstr(p, "16")) {
         ts->term_flags &= ~(USE_BOLD_AS_BRIGHT_FG | USE_BLINK_AS_BRIGHT_BG |
                             USE_256_COLORS | USE_TRUE_COLORS);
     }
+    }
 #if TTY_STYLE_BITS == 32
     if (ts->term_flags & USE_TRUE_COLORS) {
         ts->term_fg_colors_count = 0x1000000;



reply via email to

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