unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#41846: [PATCH] Fix 24-bit direct TTY colors on FreeBSD
@ 2020-06-14  4:49 Jan Beich
  2020-06-20  8:32 ` Eli Zaretskii
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Beich @ 2020-06-14  4:49 UTC (permalink / raw)
  To: 41846

[-- Attachment #1: Type: text/plain, Size: 677 bytes --]

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


[-- Attachment #2: Fix with a commit message --]
[-- Type: text/plain, Size: 1822 bytes --]

From bd215324fde6a79302f5f19456f755d9be98daed Mon Sep 17 00:00:00 2001
From: Jan Beich <jbeich@FreeBSD.org>
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
 

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#41846: [PATCH] Fix 24-bit direct TTY colors on FreeBSD
  2020-06-14  4:49 bug#41846: [PATCH] Fix 24-bit direct TTY colors on FreeBSD Jan Beich
@ 2020-06-20  8:32 ` Eli Zaretskii
  0 siblings, 0 replies; 2+ messages in thread
From: Eli Zaretskii @ 2020-06-20  8:32 UTC (permalink / raw)
  To: Jan Beich; +Cc: 41846-done

> From: Jan Beich <jbeich@FreeBSD.org>
> 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.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-20  8:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-14  4:49 bug#41846: [PATCH] Fix 24-bit direct TTY colors on FreeBSD Jan Beich
2020-06-20  8:32 ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).