From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?q?Rami=20Ylim=C3=A4ki?= Newsgroups: gmane.emacs.devel Subject: [PATCH 1/1] Detect 24-bit TTY color support with standard Terminfo capabilites. Date: Tue, 23 Jan 2018 22:05:36 +0200 Message-ID: <20180123200536.26554-2-rami.ylimaki@vincit.fi> References: <20180123200536.26554-1-rami.ylimaki@vincit.fi> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1516738123 6712 195.159.176.226 (23 Jan 2018 20:08:43 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 23 Jan 2018 20:08:43 +0000 (UTC) Cc: =?UTF-8?q?Rami=20Ylim=C3=A4ki?= To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jan 23 21:08:38 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ee4rt-0000zS-F8 for ged-emacs-devel@m.gmane.org; Tue, 23 Jan 2018 21:08:29 +0100 Original-Received: from localhost ([::1]:50281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee4tt-0005s8-RV for ged-emacs-devel@m.gmane.org; Tue, 23 Jan 2018 15:10:33 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee4qN-0003vt-DB for emacs-devel@gnu.org; Tue, 23 Jan 2018 15:06:56 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ee4qM-0000Pn-83 for emacs-devel@gnu.org; Tue, 23 Jan 2018 15:06:55 -0500 Original-Received: from mail.kapsi.fi ([2001:67c:1be8::25]:52571) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ee4qM-0000NM-0D for emacs-devel@gnu.org; Tue, 23 Jan 2018 15:06:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=3SSE4z1DQJox1BB1Qpds60eotFCx1w5W3zFwKPtVZGQ=; b=i8u5NvZPOatlgQp9zKurLw53o1KWzUdC+YKGDExnBhxARzy6HhruCS5KwOvPpym9H+eA+cKnghfJYGFSYzteloC7UzG5dgZ0ZpJD5lPAcwF3pGsnN5ffA2hCUdnXOvEkHcURx/do3iv2uFNsKrcuVDLUIf1sZNt9I/IQr6joQs5SmkUg5dTsU6NJPb1uqoSDvoYjL8g8FeipYs5mgAj2ZGcbff/CHjmHLQS6uCOBBklRGfAyzd7HrlyUnPFEATTrmAVEqafhoJr34Y9XbSw0T/y3CMxHpiQ+OrjQqAn9j0BisaWgXshUWA/N7YePJteOlMx/XmXjtPG2NToplpRiDQ==; Original-Received: from 91-157-45-84.elisa-laajakaista.fi ([91.157.45.84] helo=nopsakone.home) by mail.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1ee4qK-0004Br-SV; Tue, 23 Jan 2018 22:06:52 +0200 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180123200536.26554-1-rami.ylimaki@vincit.fi> X-SA-Exim-Connect-IP: 91.157.45.84 X-SA-Exim-Mail-From: rami.ylimaki@vincit.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:67c:1be8::25 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:222177 Archived-At: Latest Terminfo supports RGB capability flag for direct color mode terminals. Foreground and background colors are set with setaf and setab capability strings. * src/term.c (init_tty): Use standard Terminfo capabilities to detect 24-bit TTY color support. * src/tparam.h: Define prototype for tigetflag. * doc/misc/efaq.texi (Colors on a TTY): Fix instructions on how to enable direct color TTY mode. --- doc/misc/efaq.texi | 34 +++++++--------------------------- src/term.c | 26 +++++++++++++------------- src/tparam.h | 3 ++- 3 files changed, 22 insertions(+), 41 deletions(-) diff --git a/doc/misc/efaq.texi b/doc/misc/efaq.texi index 8014c2b71f..0ed58eda66 100644 --- a/doc/misc/efaq.texi +++ b/doc/misc/efaq.texi @@ -1491,37 +1491,17 @@ Colors on a TTY Syntax highlighting is on by default since version 22.1. Emacs 26.1 and later support direct color mode in terminals. If Emacs -finds Terminfo capabilities @samp{setb24} and @samp{setf24}, 24-bit -direct color mode is used. The capability strings are expected to -take one 24-bit pixel value as argument and transform the pixel to a -string that can be used to send 24-bit colors to the terminal. - -There aren't yet any standard terminal type definitions that would -support the capabilities, but Emacs can be invoked with a custom -definition as shown below. +finds Terminfo capability @samp{RGB}, 24-bit direct color mode is +used. @example -$ cat terminfo-24bit.src - -# Use colon separators. -xterm-24bit|xterm with 24-bit direct color mode, - use=xterm-256color, - setb24=\E[48:2:%p1%@{65536@}%/%d:%p1%@{256@}%/%@{255@}%&%d:%p1%@{255@}%&%dm, - setf24=\E[38:2:%p1%@{65536@}%/%d:%p1%@{256@}%/%@{255@}%&%d:%p1%@{255@}%&%dm, -# Use semicolon separators. -xterm-24bits|xterm with 24-bit direct color mode, - use=xterm-256color, - setb24=\E[48;2;%p1%@{65536@}%/%d;%p1%@{256@}%/%@{255@}%&%d;%p1%@{255@}%&%dm, - setf24=\E[38;2;%p1%@{65536@}%/%d;%p1%@{256@}%/%@{255@}%&%d;%p1%@{255@}%&%dm, - -$ tic -x -o ~/.terminfo terminfo-24bit.src - -$ TERM=xterm-24bit emacs -nw +$ TERM=xterm-direct2 emacs -nw @end example -Currently there's no standard way to determine whether a terminal -supports direct color mode. If such standard arises later on, support -for @samp{setb24} and @samp{setf24} may be removed. +Currently direct color mode support is quite fragmented and therefore +Terminfo provides various terminal specifications. You need to make +sure that the @samp{setab} and @samp{setaf} capabilites of your TERM +match your terminal. @node Debugging a customization file @section How do I debug a @file{.emacs} file? diff --git a/src/term.c b/src/term.c index b3707da70a..975ba956d7 100644 --- a/src/term.c +++ b/src/term.c @@ -4144,19 +4144,19 @@ use the Bourne shell command 'TERM=...; export TERM' (C-shell:\n\ tty->TN_max_colors = tgetnum ("Co"); #ifdef TERMINFO - /* Non-standard support for 24-bit colors. */ - { - const char *fg = tigetstr ("setf24"); - const char *bg = tigetstr ("setb24"); - if (fg && bg - && fg != (char *) (intptr_t) -1 - && bg != (char *) (intptr_t) -1) - { - tty->TS_set_foreground = fg; - tty->TS_set_background = bg; - tty->TN_max_colors = 16777216; - } - } + if (tigetflag ("RGB") > 0) + { + const char *fg = tigetstr ("setaf"); + const char *bg = tigetstr ("setab"); + if (fg && bg + && fg != (char *) (intptr_t) -1 + && bg != (char *) (intptr_t) -1) + { + tty->TS_set_foreground = fg; + tty->TS_set_background = bg; + tty->TN_max_colors = 16777216; + } + } #endif tty->TN_no_color_video = tgetnum ("NC"); diff --git a/src/tparam.h b/src/tparam.h index f8fb9e0869..3a3cb52c17 100644 --- a/src/tparam.h +++ b/src/tparam.h @@ -37,7 +37,8 @@ extern char *BC; extern char *UP; #ifdef TERMINFO -char *tigetstr(const char *); +int tigetflag (const char *); +char *tigetstr (const char *); #endif #endif /* EMACS_TPARAM_H */ -- 2.11.0