From unknown Sat Jun 14 03:58:12 2025 X-Loop: help-debbugs@gnu.org Subject: bug#41846: [PATCH] Fix 24-bit direct TTY colors on FreeBSD Resent-From: Jan Beich Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 14 Jun 2020 07:00:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 41846 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 41846@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.15921179893814 (code B ref -1); Sun, 14 Jun 2020 07:00:01 +0000 Received: (at submit) by debbugs.gnu.org; 14 Jun 2020 06:59:49 +0000 Received: from localhost ([127.0.0.1]:42761 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jkMcO-0000zP-73 for submit@debbugs.gnu.org; Sun, 14 Jun 2020 02:59:49 -0400 Received: from lists.gnu.org ([209.51.188.17]:52922) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jkKg4-0006Ew-1U for submit@debbugs.gnu.org; Sun, 14 Jun 2020 00:55:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jkKg3-0004YB-Oz for bug-gnu-emacs@gnu.org; Sun, 14 Jun 2020 00:55:27 -0400 Received: from mx2.freebsd.org ([96.47.72.81]:10578) by eggs.gnu.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jkKg1-0007so-Vz for bug-gnu-emacs@gnu.org; Sun, 14 Jun 2020 00:55:27 -0400 Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 25C28970AF for ; Sun, 14 Jun 2020 04:49:34 +0000 (UTC) (envelope-from jbeich@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49l27K6Cgvz3dx8 for ; Sun, 14 Jun 2020 04:49:33 +0000 (UTC) (envelope-from jbeich@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1354) id C959BEC9C; Sun, 14 Jun 2020 04:49:33 +0000 (UTC) From: Jan Beich Date: Sun, 14 Jun 2020 06:49:31 +0200 Message-ID: <366y-fe04-wny@FreeBSD.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=96.47.72.81; envelope-from=jbeich@freebsd.org; helo=mx2.freebsd.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/14 00:49:36 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Mailman-Approved-At: Sun, 14 Jun 2020 02:59:47 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --=-=-= Content-Type: text/plain FreeBSD only ships with /etc/termcap. However, termcap is limited to 2 arguments while RGB colors require 3. To support RGB add a fallback via COLORTERM, using semicolon version for better compatibility. https://unix.stackexchange.com/questions/512845/emacs-with-24bit-terminal-support-on-freebsd https://gist.github.com/XVilka/8346728#true-color-detection https://github.com/alacritty/alacritty/issues/1485 Test case: $ pkg install emacs-devel-nox alacritty libxkbcommon mesa-dri dejavu $ alacritty $ env -u COLORTERM emacs -nw -Q -f list-colors-display $ env COLORTERM=rxvt emacs -nw -Q -f list-colors-display $ env COLORTERM=truecolor emacs -nw -Q -f list-colors-display --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=rgb.colorterm.diff Content-Description: Fix with a commit message >From bd215324fde6a79302f5f19456f755d9be98daed Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Sun, 14 Jun 2020 03:51:24 +0000 Subject: [PATCH] Add RGB fallback if environment has COLORTERM=truecolor * src/term.c (init_tty): When COLORTERM=truecolor is declared override setaf/setab/colors terminfo capabilities with RGB support. --- doc/misc/efaq.texi | 3 +++ src/term.c | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/doc/misc/efaq.texi b/doc/misc/efaq.texi index be1ffc026dd..fa09cf67471 100644 --- a/doc/misc/efaq.texi +++ b/doc/misc/efaq.texi @@ -1595,6 +1595,9 @@ xterm-direct2 xterm with direct-color indexing (old) xterm-direct xterm with direct-color indexing @end example +If Terminfo database is not available 24-bit direct color mode can +still be enabled by defining @env{COLORTERM} to @samp{truecolor}. + 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 diff --git a/src/term.c b/src/term.c index 94bf013f4a0..50547a1c21d 100644 --- a/src/term.c +++ b/src/term.c @@ -4168,6 +4168,13 @@ use the Bourne shell command 'TERM=...; export TERM' (C-shell:\n\ could return 32767. */ tty->TN_max_colors = 16777216; } + /* Fall back to xterm+direct (semicolon version) if requested by COLORTERM */ + else if ((bg = getenv("COLORTERM")) != NULL && !strcasecmp(bg, "truecolor")) + { + tty->TS_set_foreground = "\033[%?%p1%{8}%<%t3%p1%d%e38;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%d%;m"; + tty->TS_set_background = "\033[%?%p1%{8}%<%t4%p1%d%e48;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%d%;m"; + tty->TN_max_colors = 16777216; + } } #endif --=-=-=-- From unknown Sat Jun 14 03:58:12 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Jan Beich Subject: bug#41846: closed (Re: bug#41846: [PATCH] Fix 24-bit direct TTY colors on FreeBSD) Message-ID: References: <83eeqaw30o.fsf@gnu.org> <366y-fe04-wny@FreeBSD.org> X-Gnu-PR-Message: they-closed 41846 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 41846@debbugs.gnu.org Date: Sat, 20 Jun 2020 08:34:01 +0000 Content-Type: multipart/mixed; boundary="----------=_1592642041-26510-1" This is a multi-part message in MIME format... ------------=_1592642041-26510-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #41846: [PATCH] Fix 24-bit direct TTY colors on FreeBSD which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 41846@debbugs.gnu.org. --=20 41846: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D41846 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1592642041-26510-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 41846-done) by debbugs.gnu.org; 20 Jun 2020 08:33:12 +0000 Received: from localhost ([127.0.0.1]:57255 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jmYw4-0006sX-5s for submit@debbugs.gnu.org; Sat, 20 Jun 2020 04:33:12 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36900) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jmYw3-0006sK-5U for 41846-done@debbugs.gnu.org; Sat, 20 Jun 2020 04:33:11 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:36780) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmYvx-0000Nw-OI; Sat, 20 Jun 2020 04:33:05 -0400 Received: from [176.228.60.248] (port=1658 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jmYvw-00040q-Qr; Sat, 20 Jun 2020 04:33:05 -0400 Date: Sat, 20 Jun 2020 11:32:55 +0300 Message-Id: <83eeqaw30o.fsf@gnu.org> From: Eli Zaretskii To: Jan Beich In-Reply-To: <366y-fe04-wny@FreeBSD.org> (message from Jan Beich on Sun, 14 Jun 2020 06:49:31 +0200) Subject: Re: bug#41846: [PATCH] Fix 24-bit direct TTY colors on FreeBSD References: <366y-fe04-wny@FreeBSD.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 41846-done Cc: 41846-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Jan Beich > Date: Sun, 14 Jun 2020 06:49:31 +0200 > > FreeBSD only ships with /etc/termcap. However, termcap is limited to 2 > arguments while RGB colors require 3. To support RGB add a fallback via > COLORTERM, using semicolon version for better compatibility. > > https://unix.stackexchange.com/questions/512845/emacs-with-24bit-terminal-support-on-freebsd > https://gist.github.com/XVilka/8346728#true-color-detection > https://github.com/alacritty/alacritty/issues/1485 > > Test case: > $ pkg install emacs-devel-nox alacritty libxkbcommon mesa-dri dejavu > $ alacritty > $ env -u COLORTERM emacs -nw -Q -f list-colors-display > $ env COLORTERM=rxvt emacs -nw -Q -f list-colors-display > $ env COLORTERM=truecolor emacs -nw -Q -f list-colors-display Thanks, I installed the changes on the master branch. ------------=_1592642041-26510-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 14 Jun 2020 06:59:49 +0000 Received: from localhost ([127.0.0.1]:42761 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jkMcO-0000zP-73 for submit@debbugs.gnu.org; Sun, 14 Jun 2020 02:59:49 -0400 Received: from lists.gnu.org ([209.51.188.17]:52922) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jkKg4-0006Ew-1U for submit@debbugs.gnu.org; Sun, 14 Jun 2020 00:55:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jkKg3-0004YB-Oz for bug-gnu-emacs@gnu.org; Sun, 14 Jun 2020 00:55:27 -0400 Received: from mx2.freebsd.org ([96.47.72.81]:10578) by eggs.gnu.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jkKg1-0007so-Vz for bug-gnu-emacs@gnu.org; Sun, 14 Jun 2020 00:55:27 -0400 Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 25C28970AF for ; Sun, 14 Jun 2020 04:49:34 +0000 (UTC) (envelope-from jbeich@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49l27K6Cgvz3dx8 for ; Sun, 14 Jun 2020 04:49:33 +0000 (UTC) (envelope-from jbeich@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1354) id C959BEC9C; Sun, 14 Jun 2020 04:49:33 +0000 (UTC) From: Jan Beich To: bug-gnu-emacs@gnu.org Subject: [PATCH] Fix 24-bit direct TTY colors on FreeBSD Date: Sun, 14 Jun 2020 06:49:31 +0200 Message-ID: <366y-fe04-wny@FreeBSD.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=96.47.72.81; envelope-from=jbeich@freebsd.org; helo=mx2.freebsd.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/14 00:49:36 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Sun, 14 Jun 2020 02:59:47 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --=-=-= Content-Type: text/plain FreeBSD only ships with /etc/termcap. However, termcap is limited to 2 arguments while RGB colors require 3. To support RGB add a fallback via COLORTERM, using semicolon version for better compatibility. https://unix.stackexchange.com/questions/512845/emacs-with-24bit-terminal-support-on-freebsd https://gist.github.com/XVilka/8346728#true-color-detection https://github.com/alacritty/alacritty/issues/1485 Test case: $ pkg install emacs-devel-nox alacritty libxkbcommon mesa-dri dejavu $ alacritty $ env -u COLORTERM emacs -nw -Q -f list-colors-display $ env COLORTERM=rxvt emacs -nw -Q -f list-colors-display $ env COLORTERM=truecolor emacs -nw -Q -f list-colors-display --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=rgb.colorterm.diff Content-Description: Fix with a commit message >From bd215324fde6a79302f5f19456f755d9be98daed Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Sun, 14 Jun 2020 03:51:24 +0000 Subject: [PATCH] Add RGB fallback if environment has COLORTERM=truecolor * src/term.c (init_tty): When COLORTERM=truecolor is declared override setaf/setab/colors terminfo capabilities with RGB support. --- doc/misc/efaq.texi | 3 +++ src/term.c | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/doc/misc/efaq.texi b/doc/misc/efaq.texi index be1ffc026dd..fa09cf67471 100644 --- a/doc/misc/efaq.texi +++ b/doc/misc/efaq.texi @@ -1595,6 +1595,9 @@ xterm-direct2 xterm with direct-color indexing (old) xterm-direct xterm with direct-color indexing @end example +If Terminfo database is not available 24-bit direct color mode can +still be enabled by defining @env{COLORTERM} to @samp{truecolor}. + 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 diff --git a/src/term.c b/src/term.c index 94bf013f4a0..50547a1c21d 100644 --- a/src/term.c +++ b/src/term.c @@ -4168,6 +4168,13 @@ use the Bourne shell command 'TERM=...; export TERM' (C-shell:\n\ could return 32767. */ tty->TN_max_colors = 16777216; } + /* Fall back to xterm+direct (semicolon version) if requested by COLORTERM */ + else if ((bg = getenv("COLORTERM")) != NULL && !strcasecmp(bg, "truecolor")) + { + tty->TS_set_foreground = "\033[%?%p1%{8}%<%t3%p1%d%e38;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%d%;m"; + tty->TS_set_background = "\033[%?%p1%{8}%<%t4%p1%d%e48;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%d%;m"; + tty->TN_max_colors = 16777216; + } } #endif --=-=-=-- ------------=_1592642041-26510-1--