Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TERMINFO capabilities for 24-bit color support in emacs. #1141

Closed
sykloid opened this issue Nov 14, 2018 · 21 comments
Closed

Update TERMINFO capabilities for 24-bit color support in emacs. #1141

sykloid opened this issue Nov 14, 2018 · 21 comments

Comments

@sykloid
Copy link

sykloid commented Nov 14, 2018

Just as the kitty terminfo file contains non-standard setrgbf/setrgbb capabilities for neovim, it would be nice if it included the equally non-standard setf24/setb24 capabilities which emacs decided to use.

The specifics of emacs' desired capabilities are outlined at https://www.gnu.org/software/emacs/manual/html_node/efaq/Colors-on-a-TTY.html, the relevant termcap stanza is:

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,

After doing a bunch of testing, I found that the colors capability needs to be updated to colors#16777216 indicating that kitty actually supports 24bit colors.

I've attached the terminfo file I used to get things running, before I realized that the checked-in xterm-kitty file was actually generated. I can try looking into how to get the generation to work as desired, but it would probably be faster/safer if someone else did that.

Cheers!
kitty.terminfo.txt

@kovidgoyal
Copy link
Owner

there actually is a standard way to detect support for truecolor now, the RGB flag in the terminfo database. See https://gist.github.com/XVilka/8346728#detection

I'd prefer to actually add that to kitty's terminfo rather then yet another alias for setrgbf. According to the emacs faq page once a standard way is supported they are going to remove setf24 anyway, so it does not seem worthwhile.

If their FAQ page is wrong and the emacs developers say they dont want to use RGB then update this bug and I will reconsider.

@wedens
Copy link

wedens commented Jan 9, 2019

There is an entry in a changelog:

Add some non standard terminfo capabilities used by neovim and tmux.

So, apparently some exceptions are already made. Why not do the same for emacs? :)

@kovidgoyal
Copy link
Owner

Because according to emacs' own developers setf24 support will be dropped in the future.

@nolanwrightdev
Copy link

Hello, according to this bug report, the Emacs master branch should now support the standard RGB flag. However when I run the latest Emacs in Kitty, I am still stuck with 256 colors. Has the Kitty terminfo entry been updated to use the standard RGB flag as of version 0.14.6?

@Luflosi
Copy link
Contributor

Luflosi commented Oct 12, 2019

@kovidgoyal Do you think the following patch makes sense? If so, I'd be happy to make a PR.
colors is defined as "specify the maximum numbers of colors that can be displayed simultaneously". Does kitty have a limit on the number of colours it can display simultaneously?
Do we need to adjust pairs as well? And what about that RGB capability the emacs bug report mentions?

diff --git a/kitty/terminfo.py b/kitty/terminfo.py
index 174a236a..77eb3a26 100644
--- a/kitty/terminfo.py
+++ b/kitty/terminfo.py
@@ -77,7 +77,7 @@ termcap_aliases.update({
 
 numeric_capabilities = {
     # maximum number of colors on screen
-    'colors': 256,
+    'colors': 16777216,
     'cols': 80,
     'lines': 24,
     # tabs initially every # spaces
diff --git a/terminfo/kitty.terminfo b/terminfo/kitty.terminfo
index 14c5907c..43007f6d 100644
--- a/terminfo/kitty.terminfo
+++ b/terminfo/kitty.terminfo
@@ -11,7 +11,7 @@ xterm-kitty|KovIdTTY,
 	msgr,
 	npc,
 	xenl,
-	colors#256,
+	colors#16777216,
 	cols#80,
 	it#8,
 	lines#24,

@kovidgoyal
Copy link
Owner

As I recall increasing colors beyond 256 breaks some programs. And do a
git blame on terminfo.py to see why RGB was added and then removed.

@Luflosi
Copy link
Contributor

Luflosi commented Oct 13, 2019

For anyone else interested, here is the link to the commit with the discussion about the RGB capability: 18fe2e8. I can totally see why we don't use RGB in the terminfo anymore.

As I recall increasing colors beyond 256 breaks some programs.

That is unfortunate. So that means that there is no way to support full color in emacs without breaking other programs, right?

@kovidgoyal
Copy link
Owner

kovidgoyal commented Oct 13, 2019 via email

@Sleepful
Copy link

Sleepful commented Feb 15, 2021

@Luflosi follow the emacs FAQ

but instead of use=xterm-256color do use=xterm-kitty

> xterm-emacs|xterm with 24-bit direct color mode for Emacs,
<   use=xterm-256color,
>   use=xterm-kitty,
>   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,
> 

then

$ tic -x -o ~/.terminfo terminfo-custom.src

and you can do

$ TERM=xterm-emacs emacs -nw

why does it work? I have no idea, but it didn't work following the xterm-256color, I would get emacs: cannot open terminfo database file


There is another way in which you follow the faq without replacing the code, but instead using

/usr/bin/tic -x -o ~/.terminfo terminfo-custom.src

Related stackexchange answer

@Luflosi
Copy link
Contributor

Luflosi commented Feb 15, 2021

@Sleepful It sounds like you think that I had a problem with using emacs but I don't use emacs (and never have). I was just trying to make improvement suggestions in general.
Your tip might be useful for anyone else that may have this problem though.

@Sleepful
Copy link

@Luflosi ah okay, I landed on this thread trying to get it to work, thanks for thinking about us emacs users.

@real-or-random
Copy link

I digged into this a little bit and I agree it's a mess.

How bad would it be to ship a xterm-kitty-direct on top of xterm-kitty? It's not great but it seems that's the most supported thing and then at least TERM=xterm-kitty-direct emacs will work.

18fe2e8

@kovidgoyal
Copy link
Owner

IIRC ncurses ships with kitty-direct already, just use that. Though I think their version doesnt match kitty's terminfo fully, so other things might break, or maybe you will ge tlucky and nothing will break.

@real-or-random
Copy link

IIRC ncurses ships with kitty-direct already, just use that. Though I think their version doesnt match kitty's terminfo fully, so other things might break, or maybe you will ge tlucky and nothing will break.

Right, it was just my fear that other things will break, so I created a custom terminfo for now.

I just thought shipping with a -direct may be helpful for others. That's my suggestion.

@kovidgoyal
Copy link
Owner

I'm afraid I am really not inclined to do so, sorry. It's hack,
complicates code, doesn't work with the ssh kitten, requires changing
TERM, etc.

This really needs to be fixed in emacs. I don't know why they are being
stubborn about using the same terminfo properties as everyone else does.

@real-or-random
Copy link

Thanks for your quick response. I can understand.

This really needs to be fixed in emacs. I don't know why they are being
stubborn about using the same terminfo properties as everyone else does.

I'd probably be willing to mention this on the emacs list. But when you say this needs to be fixed in emacs, what fix do you have in mind? It's not clear to me how to fix this. AFAICT the only way to recognize RGB support from kitty's terminfo is to check for the non-standard setrgbf and setrgbb. Do you think they should check for this? That sounds pragmatic at least.

According to the emacs faq page once a standard way is supported they are going to remove setf24 anyway, so it does not seem worthwhile.

If their FAQ page is wrong and the emacs developers say they dont want to use RGB then update this bug and I will reconsider.

In fact what they at least removed that statement from their FAQ that the setb24/setf24 may be removed in the future: emacs-mirror/emacs@7f6153d#diff-d764b434e23a258c9b1467e4cac9a9b1c44143ece693dbeed6ba6c7ec448843eL1522

Now that adding RGB here failed, and setb24 seems permanent in emacs, another pragmatic fix is to add setb24 here, what was initially proposed here. What do you think?

@kovidgoyal
Copy link
Owner

kovidgoyal commented May 31, 2021 via email

@real-or-random
Copy link

Now that adding RGB here failed, and setb24 seems permanent in emacs, another pragmatic fix is to add setb24 here, what was initially proposed here. What do you think?

I dont mind, though it seems bonkers to add another setting for the same damn thing in every terminfo file, when there already exist widely supported ones. So if you dont get anywhere on the emcas mailing list feel free to send a PR for it.

Now this was quicker than I expected. https://debbugs.gnu.org/cgi/bugreport.cgi?bug=44950#20

I guess I'll create a PR here then in the next days...

@gzagatti
Copy link

gzagatti commented Feb 9, 2022

After a lot of search, I finally managed to get 24-bit color support on Emacs in kitty by following @Sleepful suggestion above. So after creating a custom terminfo file, I start emacs with:

TERM=xterm-emacs emacs -nw

Is this the current and suggested working solution to get full color support on Emacs when using kitty?

@real-or-random
Copy link

@gzagatti I'm not sure if there's a suggested solution (because the entire thing is a huge mess) but it's a working solution.

Emacs 29.1 will support honor Tc, so we'll don't need ugly workarounds anymore: emacs-mirror/emacs@f30f531

@gzagatti
Copy link

gzagatti commented Feb 9, 2022

That's great news. Thanks for letting me know. I'm looking forward to this update.

mk12 added a commit to mk12/scripts that referenced this issue Sep 15, 2022
I was going to do tmux-direct and RGB instead of tmux-256color and Tc.
It seemed to work but fish's brblack was wrong, emitting RGB even though
I disabled fish_term24bit. Turns out direct/RGB is a bad idea:

kovidgoyal/kitty#1141
kovidgoyal/kitty@18fe2e8
kovidgoyal/kitty@a91b3b9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants