From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Rami =?UTF-8?Q?Ylim=C3=A4ki?= Newsgroups: gmane.emacs.bugs Subject: bug#30308: [PATCH v2] Support standard Terminfo direct mode terminals. Date: Thu, 1 Feb 2018 11:41:33 +0200 Message-ID: <20180201094133.11024-1-rami.ylimaki@vincit.fi> References: <20180131094308.24946-1-rami.ylimaki@vincit.fi> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1517478086 4567 195.159.176.226 (1 Feb 2018 09:41:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 1 Feb 2018 09:41:26 +0000 (UTC) To: 30308@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Feb 01 10:41:21 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1ehBMl-00005H-RD for geb-bug-gnu-emacs@m.gmane.org; Thu, 01 Feb 2018 10:41:12 +0100 Original-Received: from localhost ([::1]:45517 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ehBOk-0003dx-VG for geb-bug-gnu-emacs@m.gmane.org; Thu, 01 Feb 2018 04:43:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60892) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ehBOd-0003dQ-Oc for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2018 04:43:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ehBOY-0000wN-QX for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2018 04:43:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43920) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ehBOY-0000vo-HR for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2018 04:43:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ehBOY-0004mq-7m for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2018 04:43:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <20180131094308.24946-1-rami.ylimaki@vincit.fi> Resent-From: Rami =?UTF-8?Q?Ylim=C3=A4ki?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 01 Feb 2018 09:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30308 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 30308-submit@debbugs.gnu.org id=B30308.151747816318369 (code B ref 30308); Thu, 01 Feb 2018 09:43:02 +0000 Original-Received: (at 30308) by debbugs.gnu.org; 1 Feb 2018 09:42:43 +0000 Original-Received: from localhost ([127.0.0.1]:51817 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ehBOD-0004mA-Sz for submit@debbugs.gnu.org; Thu, 01 Feb 2018 04:42:43 -0500 Original-Received: from mail-lf0-f51.google.com ([209.85.215.51]:36380) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ehBOB-0004lu-BS for 30308@debbugs.gnu.org; Thu, 01 Feb 2018 04:42:40 -0500 Original-Received: by mail-lf0-f51.google.com with SMTP id t79so25217335lfe.3 for <30308@debbugs.gnu.org>; Thu, 01 Feb 2018 01:42:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vincit.fi; s=ticniv; h=from:to:subject:date:message-id; bh=oT181XrJHqQDsl89mX88prc6xUjQg7seF6m2RvEN2X8=; b=ir+MmD0OxPvZetbzTFyqEKpOF/GQLlV4Fh3P6oMv/1hG7EtnVPQSIsBsGoRgkgnml5 GCASzUFPGO0PBleLwHkTNhvnN7uaWJwD/z9kpi3IS2J8nACPgSpLuhh18fFdwP6MwNvO HXD5wPbCl+PcBHnxpW0Bl1EpahHctmo0UvFyw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=oT181XrJHqQDsl89mX88prc6xUjQg7seF6m2RvEN2X8=; b=iT0tyR8SlLdvy+K8b1o9Ue/BZhQI3toWuN2lJQZ3zYiMAMHJO+3I9MDymSPbXWv7Dz ddH1dA0ncLPXFngF6F7aZsH/P7ILsPRb8bCAi9FWCyqZcOrQYTYSizNbVsDXz5ojWsEU uhocr408+ci2Bz3GQRPw6jTLWaoSyFZs6NozwODBIA6Uluufho3rG9KiGSajfbL6JbjD TDZrSEwHtRz20VIXNDt0/mS+80GoPAIRVv+gHWC+TMKAzgP87eHFwyIaU4oMwSssxKUo hkV5+qowlIMPB8Wz2RDOGJI+Oj8so60y99N+ImVLkhlkeJqqD6TS2HksFxPT16kMP4on kHCQ== X-Gm-Message-State: AKwxytcLVxL0xTiIUA5jMgDDcWZ0SP+J4RNKzR42ShTTs5iHvjzD+34t HtlAY9QVgGgFFEAXWi3OWuOFVNvd0mQ= X-Google-Smtp-Source: AH8x226U/NMzuNBQfEmy0JorTsN+1jyRKNDVlSBF96j/nKLpg5lJ0HDHQvGuIVm0w9JOfb+2F+GfMQ== X-Received: by 10.25.217.210 with SMTP id s79mr21296564lfi.73.1517478152821; Thu, 01 Feb 2018 01:42:32 -0800 (PST) Original-Received: from localhost.localdomain (gw.vincit.cloud. [195.60.252.249]) by smtp.gmail.com with ESMTPSA id w7sm3659426ljw.25.2018.02.01.01.42.31 for <30308@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Feb 2018 01:42:32 -0800 (PST) X-Mailer: git-send-email 2.14.1 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:142762 Archived-At: Latest Terminfo introduces terminal definitions that support direct color mode. The "Co"/"colors" capability is set to 0x1000000 on these terminals and Emacs is already compatible with them. However, if used Terminfo library hasn't been compiled with 32-bit value support, "Co"/"colors" is truncated to 0x7fff. In this case direct color mode support can be detected from the "RGB" capability flag. There are some minor problems if the color count isn't corrected from 0x7fff. First eight standard colors defined in xterm-standard-colors are shown correctly. However, their RGB values match the terminal settings, not the RGB values defined in xterm-standard-colors. Bright versions of these colors are shown incorrectly. They are interpreted as pixels #000008 - #000015, which are very dark shades of blue. * src/term.c (init_tty): Force terminal color count to 0x1000000 if "RGB" capability is present. * src/tparam.h: Define prototype for tigetflag. * doc/misc/efaq.texi (Colors on a TTY): Add information about direct mode terminals supported by Terminfo. --- doc/misc/efaq.texi | 45 +++++++++++++++++++++++++++------------------ src/term.c | 10 +++++++++- src/tparam.h | 3 ++- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/doc/misc/efaq.texi b/doc/misc/efaq.texi index 3e67438ab9..fef9b1051b 100644 --- a/doc/misc/efaq.texi +++ b/doc/misc/efaq.texi @@ -1496,32 +1496,41 @@ Colors on a TTY 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. +Standard terminal definitions don't support these capabilities and +therefore custom definition is needed. @example -$ cat terminfo-24bit.src +$ cat terminfo-custom.src -# Use colon separators. -xterm-24bit|xterm with 24-bit direct color mode, +xterm-emacs|xterm with 24-bit direct color mode for Emacs, 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, + 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-custom.src + +$ TERM=xterm-emacs emacs -nw +@end example + +Emacs 27.1 and later support Terminfo capability @samp{RGB} for +detecting 24-bit direct color mode. Multiple standard terminal +definitions support this capability. + +@example +$ TERM=xterm-direct infocmp | grep seta[bf] -$ tic -x -o ~/.terminfo terminfo-24bit.src + setab=\E[%?%p1%@{8@}%<%t4%p1%d%e48\:2\:\:%p1%@{65536@}%/%d\:%p1%@{256@}%/%@{255@}%&%d\:%p1%@{255@}%&%d%;m, + setaf=\E[%?%p1%@{8@}%<%t3%p1%d%e38\:2\:\:%p1%@{65536@}%/%d\:%p1%@{256@}%/%@{255@}%&%d\:%p1%@{255@}%&%d%;m, -$ TERM=xterm-24bit emacs -nw +$ TERM=xterm-direct 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. +Terminals with @samp{RGB} capability treat pixels #000001 - #000007 as +indexed colors to maintain backward compatibility with applications +that are unaware of direct color mode. Therefore the seven darkest +blue shades may not be available. If this is a problem, you can +always use custom terminal definition with @samp{setb24} and +@samp{setf24}. @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..64a2b7e551 100644 --- a/src/term.c +++ b/src/term.c @@ -4144,10 +4144,10 @@ 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"); + /* Non-standard support for 24-bit colors. */ if (fg && bg && fg != (char *) (intptr_t) -1 && bg != (char *) (intptr_t) -1) @@ -4156,6 +4156,14 @@ use the Bourne shell command 'TERM=...; export TERM' (C-shell:\n\ tty->TS_set_background = bg; tty->TN_max_colors = 16777216; } + /* Standard support for 24-bit colors. */ + else if (tigetflag ("RGB") > 0) + { + /* If the used Terminfo library supports only 16-bit + signed values, tgetnum("Co") and tigetnum("colors") + could return 32767. */ + tty->TN_max_colors = 16777216; + } } #endif 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.14.1