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

Use background color for character below cursor #126

Closed
koekeishiya opened this issue Sep 15, 2017 · 45 comments
Closed

Use background color for character below cursor #126

koekeishiya opened this issue Sep 15, 2017 · 45 comments

Comments

@koekeishiya
Copy link
Contributor

As per the title; it would be nice to be able to have kitty draw the character currently below the block cursor in the same color as the background color.

I did not find any way in the current setting to allow for this, and it would go really well with having full cursor opacity.

Do you think this would be hard to implement, and if not, would you consider adding this?

Thanks.

@kovidgoyal
Copy link
Owner

Implementing it is probably not difficult, but why background color? Shouldn't it be a dedicated color contrasting with the cursor color? After all the background color changes depnding on the application.

@koekeishiya
Copy link
Contributor Author

I suppose that would indeed be more appropriate.

@kovidgoyal
Copy link
Owner

Hmm I'm not convinced this is a good idea. With a blinking cursor it would look pretty bad to have the foreground color changing both when cursor moves and on blink. But maybe I am imagining it. Do you know of any other terminal that have this feature, so Ican try it out and see how it looks, before spending the time to implement it?

@koekeishiya
Copy link
Contributor Author

koekeishiya commented Sep 16, 2017

iTerm2 for macOS does this. I don't know of any terminal applications on Linux that does this, but I'm sure there has to be some. I've attached a short gif demonstrating the behaviour with the effect I'd like.

cursor

kovidgoyal added a commit that referenced this issue Sep 17, 2017
The text is rendered in the background color on top of the opaque
block cursor. We use the background color since applications can change
both cursor and background colors, so it is up to the application to
ensure the colors have good contrast. Fix #126
@kovidgoyal
Copy link
Owner

Implemented in the fast branch.

@koekeishiya
Copy link
Contributor Author

Works great, thanks!

@Asheq
Copy link

Asheq commented Jul 12, 2018

Is there any way to use a constant color for the text under the cursor? The current approach causes a visibility problem if the cursor is light and it is currently over some text with a light background.

I'm imagining two separate settings: cursor_foreground for the text under the cursor and cursor_background for the cursor itself.

If cursor_foreground is unspecified, then kitty can fallback to the current behaviour. What do you think?

Thanks for an incredible terminal!

@kovidgoyal
Copy link
Owner

There are three possible approaches:

  1. Use a defined foreground and background color
  2. Use a defined background color and the foreground color from the current terminal background
  3. Use a full reverse video effect (invert the colors in the terminal for the cursor)

Different terminals typically support one of these three approaches. And different kitty users have requested all three at different times. I am fine with (1) and (2). The problem with (3) is that it breaks the terminal escape codes used to change cursor colors.

That said I also dont much see the point of (1). You should set your cursor color to have good contrast with the background color. If you do that and you still have poor contrast with text , then that means the text already has poor contrast with the background, and is hard to see regardless of whether the cursor is over it or not.

@Asheq
Copy link

Asheq commented Jul 12, 2018

Thanks for the quick reply! The problem for me is that my colorscheme in Vim has a dark background under normal circumstances, but search matches have a light background (yellow) with a dark foreground. Please see this gif:

test

@kovidgoyal
Copy link
Owner

Yeah, the easiest thing to do is change either the search highlight color to be a bit darker, or your cursor color to be a bit darker. Although, given that the cursor blinks, it isn't that hard to see the text under it :)

kovidgoyal added a commit that referenced this issue Jul 12, 2018
@kovidgoyal
Copy link
Owner

There you go: 55fc5c4

@Asheq
Copy link

Asheq commented Jul 12, 2018

Thank you, I'll give it a try!

EDIT: It works great!

@romgrk
Copy link

romgrk commented Jan 18, 2019

@kovidgoyal is cursor color invertion supported? (as showed in #126 (comment)) I've tried the background cursor text color, but it's not quite what I want. Color invertion ensures the cursor is visible at all times, as explained in #126 (comment).
I'd be happy to open a PR if it's not supported yet and you're ok with including it.

@kovidgoyal
Copy link
Owner

As I said above, I am not a fan of inversion because it breaks the terminal escape codes used to set cursor colors. It means that it is no longer possible for terminal applications to control cursor colors, as needed.

@romgrk
Copy link

romgrk commented Jan 19, 2019

Ok, I get your point, it's true that it has downsides. However, I think that ultimately, if the user really wants to have inversion, it should have priority over terminal applications.
Besides, cursor color inversion is also the best way (that I know of) to make the cursor clearly visible at all times. For example, I use a dark colorscheme in the terminal, but a light colorscheme in neovim. Any cursor bg color choice will fail to make it visible at some point. The proof that it's so useful is that it is implemented in most other terminals (which unfortunately lack the features of Kitty, thus why I'm being insistent on having it in Kitty :)
I understand that you're not a fan of using it yourself and thus have no interest in implementing it, but if you can tolerate it being implemented in Kitty I can do it myself. Let me know what you think.

@kovidgoyal
Copy link
Owner

Simply have neovim change the cursor color as part of changing the color scheme. That's the whole point of having application controllable cursor colors in the first place. If you dont know how to get neovim to do that, make a shell script wrapper for it that changes the cursor color and then launches it. It would be a five line script.

The problem with having inverted colors is that it means the entire ecosystem can no longer rely on being able to change cursor colors, so that feature becomes unusable for everybody.

@subnut
Copy link

subnut commented Nov 14, 2020

The problem with having inverted colors is that it means the entire ecosystem can no longer rely on being able to change cursor colors

@kovidgoyal @romgrk
Isn't it possible to set inverted cursor as a kind of default? I mean, I imagine an option, which when set to true, will cause kitty to render inverted cursor by default unless the terminal application (neovim in this case) explicitly mentions something else. Isn't it possible?

it is implemented in most other terminals (which unfortunately lack the features of Kitty, thus why I'm being insistent on having it in Kitty :)

Exactly. :)
I perfectly understand that @kovidgoyal doesn't want to implement it himself. But if this feature is possible to implement, and if someone can submit a PR, then I think there should not be any problem....

@romgrk
Copy link

romgrk commented Nov 15, 2020

I'm not using kitty at the moment so I don't plan to submit a PR.

@subnut
Copy link

subnut commented Nov 15, 2020

@romgrk What are you using now?

@romgrk
Copy link

romgrk commented Nov 15, 2020

tilix

@gshpychka
Copy link

The lack of cursor color inversion is what's preventing me from switching from Alacritty, which has this on by default.

@eddyekofo94
Copy link

I wish to move away from Alacrity but this is a let down a little

@tamton-aquib
Copy link

tamton-aquib commented Jun 2, 2021

Same as gshpychka,I feel this is the only feature alacritty has over kitty.
It would be nice if there was an option :( .

@rosshadden
Copy link

rosshadden commented Jun 15, 2021

I don't disagree that in a vacuum this is something that makes more sense for an application (vim, zsh, etc.) to handle than a terminal. But the reality is many terminals support this and it's an (admittedly weird) turn-off when a terminal doesn't. At the end of the day it's subjective and many of us like our cursors behaving this way while many may not. I'm not the author but I don't see what harm it does to add in a strongly-requested feature and let people opt-in to it if they wish.

My personal reason for liking this and using it in every terminal I use is very well captured in the image that @Asheq shared above. In ~5 years of doing this in various terminals (termite being my most recent) I have not once seen a color combination that was hard to see such as in the aforementioned gif. Which is kind of the point---it's at the very least extremely unlikely if not outright impossible.

@metaory
Copy link

metaory commented Jun 23, 2021

Alacricity handles cursor so nicely, but dont play nice with x wm motif and size hints,
alacritty/alacritty#1702 (comment) 🤪

Kitty handles size hints nicely and support X spec, but this bad vi cursor color support,,,,
this even carries into my vim/nVim too,

still bad cursor better than bad size hints, Ive been telling myself 😬 but it hurts!!

wezterm?! 🎉

@yebt
Copy link

yebt commented Aug 18, 2021

iTerm2 for macOS does this. I don't know of any terminal applications on Linux that does this, but I'm sure there has to be some. I've attached a short gif demonstrating the behaviour with the effect I'd like.

cursor

What is this font?

@koekeishiya
Copy link
Contributor Author

koekeishiya commented Aug 19, 2021 via email

@VKondakoff
Copy link

I'm missing the Alacritty way of highlighting cursor too.
May I suggest this highlighting:

  • Use the color of the text under cursor to set the cursor color.
    and_at_the_same_time
  • Use the color of the cell background to set the text color inside the cursor.

@VKondakoff
Copy link

Thanks a lot for implementing this. Looks great!
Here are my first experiments with Neovim and the new option. Looks like there is still some room for improvements! ;)

Seoul256 theme:

2021-10-27.23.45.15.mov
2021-10-28.00.16.30.mov

Cake16 theme:

2021-10-27.23.43.53.mov

Nord theme:

2021-10-27.23.40.32.mov

@VKondakoff
Copy link

And here is how it looks in iTerm2:

2021-10-28.00.27.27.mov
2021-10-28.00.26.34.mov
2021-10-28.00.25.42.mov
2021-10-28.00.25.05.mov

@kovidgoyal
Copy link
Owner

The good lord alone knows what iTerm is doing. That's not reverse video, that's some pick whatever cursor color I think looks good algorithm. If you like it so much feel free to look in its source code and figure out the algorithm and submit a PR for it, you just need to modify the pick_cursor_color() function in kitty.

@gshpychka
Copy link

Thanks a lot for implementing this, I will look into switching from alacritty now.

@carlosala
Copy link

carlosala commented Nov 1, 2021

The good lord alone knows what iTerm is doing. That's not reverse video, that's some pick whatever cursor color I think looks good algorithm. If you like it so much feel free to look in its source code and figure out the algorithm and submit a PR for it, you just need to modify the pick_cursor_color() function in kitty.

As I understand, what is expected to happen when you have anything selected (as because is below the cursor or just a big selection) is that background should be the text color and text color should be cursor background color. And just that character, the others must have the normal color. Should be easier to implement than the last change you did. Just invert colors for that character, no more.

@carlosala
Copy link

Thanks a lot for implementing this. Looks great! Here are my first experiments with Neovim and the new option. Looks like there is still some room for improvements! ;)

Seoul256 theme:

2021-10-27.23.45.15.mov
2021-10-28.00.16.30.mov
Cake16 theme:

2021-10-27.23.43.53.mov
Nord theme:

2021-10-27.23.40.32.mov

As you can see in the first video, both braces change color. This is not expected (or doesn't work like this in Alacritty or other terms)

@kovidgoyal
Copy link
Owner

kovidgoyal commented Nov 2, 2021

I dont know what you are talking about. The cursor and the cursor alone changes color because fo kitty. anything else changing color is because vim changed its color.

@page-down
Copy link
Contributor

The good lord alone knows what iTerm is doing. That's not reverse video, that's some pick whatever cursor color I think looks good algorithm.

As I understand, ... background should be the text color and text color should be cursor background color. ...

No, it is not. I don't even have to look at the code at all. iTerm2 uses the text foreground color as the cursor background color. When the color is lighter than 50%, black is used as the cursor text color. When the color is darker than 50%, white is used instead. Black and white refer to two of the 8 ANSI colors in the iTerm2 configuration.

This is clearly not a reverse video effect. And this iTerm2 feature is completely dead when the cursor is on RGB true color text.

@carlosala
Copy link

The good lord alone knows what iTerm is doing. That's not reverse video, that's some pick whatever cursor color I think looks good algorithm.

As I understand, ... background should be the text color and text color should be cursor background color. ...

No, it is not. I don't even have to look at the code at all. iTerm2 uses the text foreground color as the cursor background color. When the color is lighter than 50%, black is used as the cursor text color. When the color is darker than 50%, white is used instead. Black and white refer to two of the 8 ANSI colors in the iTerm2 configuration.

This is clearly not a reverse video effect. And this iTerm2 feature is completely dead when the cursor is on RGB true color text.

I am talking about Alacritty and gnome-terminal, I hadn't used iTerm2.

@carlosala
Copy link

I tried nightly version and looks great. I'm looking forward to seeing a new release with this!

@romgrk
Copy link

romgrk commented Feb 16, 2022

I've just noticed that this was implemented :O Thanks a lot for this, @kovidgoyal !

@kovidgoyal
Copy link
Owner

you are welcome!

@Yuxin0610
Copy link

iTerm2 for macOS does this. I don't know of any terminal applications on Linux that does this, but I'm sure there has to be some. I've attached a short gif demonstrating the behaviour with the effect I'd like.

cursor

I am also using iterm2 but it doesn't do this for me. How did you make it work in iterm2?

@joelpeapen
Copy link

joelpeapen commented Feb 15, 2024

After playing with this for a while trying to get it to work, i realised the themes were setting the cursor colors. Can the kitty.conf override the colors from current-theme.conf so switching between themes with kitten themes doesn't interfere with my permanent options? Thanks.

@kovidgoyal
Copy link
Owner

kovidgoyal commented Feb 15, 2024 via email

@joelpeapen
Copy link

On Wed, Feb 14, 2024 at 09:19:56PM -0800, Joel Eapen wrote: After playing with this for a while trying to get it to work, i realised the themes were setting the cursor colors. Can the kitty.conf to override the colors from current-theme.conf so switching between themes with kitten themes doesn't interfere with my permanent options? Thanks.
Use --config-file-name for the themes kitten and include that file in kitty.conf, then the themes kitten wont touch kitty.conf.

kitten themes --config-file-name modifies themes.conf with incude current-theme.conf, which contains a new cursor value from the chosen theme. kitty.conf is untouched, but current-theme.conf's cursor value takes precedence over cursor none in kitty.conf

@kovidgoyal
Copy link
Owner

kovidgoyal commented Feb 15, 2024 via email

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