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 v3 3/4] Let user turn 24-bit terminal colors on. Date: Tue, 14 Feb 2017 17:58:21 +0200 Message-ID: <1487087902-6661-4-git-send-email-rami.ylimaki@vincit.fi> References: <1487087902-6661-1-git-send-email-rami.ylimaki@vincit.fi> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1487088020 15636 195.159.176.226 (14 Feb 2017 16:00:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 14 Feb 2017 16:00:20 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Feb 14 17:00:13 2017 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 1cdfWQ-0003Lt-Uy for ged-emacs-devel@m.gmane.org; Tue, 14 Feb 2017 17:00:08 +0100 Original-Received: from localhost ([::1]:35618 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdfWW-0000Us-LE for ged-emacs-devel@m.gmane.org; Tue, 14 Feb 2017 11:00:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33064) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdfVG-0000Sc-PU for emacs-devel@gnu.org; Tue, 14 Feb 2017 10:58:56 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdfVB-0000nz-TJ for emacs-devel@gnu.org; Tue, 14 Feb 2017 10:58:54 -0500 Original-Received: from mx1.kapsi.fi ([2001:1bc8:1004::1:25]:59560 helo=mail.kapsi.fi) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cdfVB-0000mw-L7 for emacs-devel@gnu.org; Tue, 14 Feb 2017 10:58:49 -0500 Original-Received: from 91-158-222-159.elisa-laajakaista.fi ([91.158.222.159] helo=nopsakone.home) by mail.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1cdfV8-0005Tc-1c for emacs-devel@gnu.org; Tue, 14 Feb 2017 17:58:46 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487087902-6661-1-git-send-email-rami.ylimaki@vincit.fi> X-SA-Exim-Connect-IP: 91.158.222.159 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:1bc8:1004::1: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:212377 Archived-At: From: Rami Ylimäki ITU-T T.412 9.1.4 and ITU-T T.416 13.1.8 specify control function for changing terminal foreground and background colors. One possible format for the control function parameters is: 2:n:r:g:b, where 2 is color access mode indicating direct RGB space, n is an indentifier that gives detailed information about the color space and r, g, b are the color values. Most 24-bit terminals implement this function as 2;r;g;b. Color space identifier has been omitted because of its complexity and rgb values are assumed to be in range 0-255. Parameters are separated by semicolons instead of colons for historical reasons. The terminfo database supports only indexed color control functions and can't be used to determine whether a terminal has implemented direct color control functions. However, this can be worked around by creating user defined functions for setting 24-bit foreground and background colors. This can be done by creating a terminfo source file with the required capabilities and compiling a custom terminal type definition. For example: $ cat terminfo-24bit.src # Replace semicolons with colons in setb24 and setf24 on terminals # that use ITU-T separators (iTerm2). A 24-bit integer (p1) is given # as a parameter to the control functions which calculate rgb # component values with following formulas: # r = p1 / 65536, g = (p1 / 256) & 255, b = p1 & 255 xterm-24bits|xterm with 16777216 colors, 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-24bits emacs * src/term.c (init_tty): Use 24-bit terminal colors if corresponding foreground and background functions are present in terminal type definition. * src/tparam.h: Define prototype for tigetstr. --- src/term.c | 14 ++++++++++++++ src/tparam.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/src/term.c b/src/term.c index b0ff9cb..35fa8c9 100644 --- a/src/term.c +++ b/src/term.c @@ -4131,6 +4131,20 @@ 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 *)-1 && bg != (char *)-1) + { + tty->TS_set_foreground = fg; + tty->TS_set_background = bg; + tty->TN_max_colors = 16777216; + } + } +#endif + tty->TN_no_color_video = tgetnum ("NC"); if (tty->TN_no_color_video == -1) tty->TN_no_color_video = 0; diff --git a/src/tparam.h b/src/tparam.h index 15664d6..02136b6 100644 --- a/src/tparam.h +++ b/src/tparam.h @@ -36,4 +36,8 @@ extern char PC; extern char *BC; extern char *UP; +#ifdef TERMINFO +char *tigetstr(const char *); +#endif + #endif /* EMACS_TPARAM_H */ -- 2.7.4