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

Errors with neovim when termguicolors is set #160

Closed
schaden-freude opened this issue Nov 1, 2017 · 64 comments
Closed

Errors with neovim when termguicolors is set #160

schaden-freude opened this issue Nov 1, 2017 · 64 comments

Comments

@schaden-freude
Copy link

I am using the onedark colorscheme in neovim. If I set the option termguicolors then kitty borks and throws [PARSE ERROR] Invalid character in CSI: 0x3a, ignoring the sequence repeatedly.

Here is a comparison with terminator(left) and kitty.
2017-11-01-131749_1366x768_scrot

In case I don't set termguicolors in my .vimrc, then it kinda works, but the colors are quite different (I believe the colorscheme then uses 256 colors instead of truecolor.)

@kovidgoyal
Copy link
Owner

You need to set the correct t_8f and t_8b settings in vim as well. From my .vimrc

            set termguicolors
            let &t_8f = "\e[38;2;%lu;%lu;%lum"
            let &t_8b = "\e[48;2;%lu;%lu;%lum"

IIRC these are the defaults in vim so you are probably changing them in either .vimrc or some plugin.

@kovidgoyal
Copy link
Owner

Looking at vim help, those are only set if TERM is xterm, so presumably terminator sets term to xterm.

@schaden-freude
Copy link
Author

schaden-freude commented Nov 1, 2017

It works for me on vim without setting t_8f and t_8b.

However on neovim, despite setting t_8f and t_8b, I have the same error.

@kovidgoyal
Copy link
Owner

kovidgoyal commented Nov 1, 2017

Presumably neovim does not honor those settings. From the error message kitty prints, neovim is using the colon form of the escape code instead of the semi-colon form. The semi-colon form is the correct form. See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Functions-using-CSI-_-ordered-by-the-final-character_s_

You should report the bug to neovim.

@kovidgoyal
Copy link
Owner

To be precise the semi-colon form is mandated by ISO-8613-3

@kovidgoyal
Copy link
Owner

And as further evidence, a quick glance at https://gist.github.com/XVilka/8346728#now-supporting-truecolour shows you that all terminals that support truecolor support the semi-colon form and many do not support the colon form at all. So I have no idea why neovim chose to use the colon form.

@justinmk
Copy link

justinmk commented Nov 1, 2017

Neovim only uses the colon form for terminals that it thinks support it. ISO-8613-3 does not mandate semicolon, in fact it's the opposite:

http://invisible-island.net/xterm/xterm.faq.html

But semicolon is pervasive and frankly I wish we hadn't wasted time trying to support the "correct" (colon) form.

The semi-colon form is the correct form.
See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Functions-using-CSI-_-ordered-by-the-final-character_s_

From that URL:

ISO-8613-3 can be interpreted in more than one way; xterm
allows the semicolons in this control to be replaced by
colons (but after the first colon, colons must be used).

@DarkDefender
Copy link

It's not too late to remove the colon support and be done with it... ;)

@kovidgoyal
Copy link
Owner

Really, from just about every reference I have seen ISO-8613 mandates semi-colons. But since no ine is going to pay to get access to the standards documents, who knows :)

Just read the list at https://gist.github.com/XVilka/8346728 every single terminal supports semi-colons and only a subset support colons. There is absolutely no reason to use colons. It's a trivial two line patch for me to add support for colons to kitty, but I'd rather not, since it adds an extra branch to parsing of the escape code for no good reason.

@DarkDefender
Copy link

@kovidgoyal Yes, that is what I argued when colon support were added.

I think it's madness to complicate the code when it seems like the de facto standard of semi colons has already been decided. We'll see if rolling back to only supporting semi colons goes better this time.

You should not have to add support for colons.

@DarkDefender
Copy link

I've opened up a pull request that should fix this in neovim neovim/neovim#7482

@kovidgoyal
Copy link
Owner

Thanks :)

@justinmk
Copy link

justinmk commented Nov 2, 2017

There is absolutely no reason to use colons

That's not exactly true, AFAIU semicolons are ambiguous in some cases.

@kovidgoyal
Copy link
Owner

I dont know of any such cases. In fact, all other CSI codes that need to be parsed by a terminal emulator use semi-colons. Using colons for this one variant makes no sense. Run your eye over this list and you will see there are no colons anywhere: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Functions-using-CSI-_-ordered-by-the-final-character_s_

@schaden-freude
Copy link
Author

Okay so I tried neovim/neovim#7482 and it works fine for me.

However, kitty now throws a [PARSE ERROR] Unknown CSI code: 0x74 each time neovim is opened. This doesn't happen with vim.

@kovidgoyal
Copy link
Owner

That just means neovim is using the CSI code to manipulate the graphical window. kitty does not support that. Indeed, since I always use tiling window managers, kitty cannot support that, as it has no way to control its size/position. I dont know why neovim is using that code. Perhaps to query the window title? You'd have to ask @justinmk

@kovidgoyal
Copy link
Owner

And with this commit: 013fd31

you should get more details about the unknown CSI code.

@justinmk
Copy link

justinmk commented Nov 2, 2017

Kitty should ignore unexpected CSI codes, not show anything to normal users.

@kovidgoyal
Copy link
Owner

It does not show anything to normal users. You only see them if you look at its stdout/stderr.

@justinmk
Copy link

justinmk commented Nov 4, 2017

For reference, regarding the colon question see https://bugzilla.gnome.org/show_bug.cgi?id=685759

We overlooked the detail about ":" as a subparameter delimiter (documented
in 5.4.t2 in ECMA-48). Some discussion in KDE in mid-2006 led Lars Doelle
to discuss the issue with me. Lars' initial concern dealt with the fact
that a sequence such as
CSI 38 ; 5 ; 1 m
violated the principle that SGR parameters could be used in any order.
Further discussion (see KDE #107487) resolved that the standard expected
that the sequence would look like
CSI 38 ; 5 : 1 m
which still violates that principle, since the "5:1" parameter has to
follow the "38" to be useful.

This function accepts either format (per request by Paul Leonerd Evans).
It also accepts
CSI 38 : 5 : 1 m
according to Lars' original assumption.

And https://bugzilla.gnome.org/show_bug.cgi?id=704449 discusses the ambiguous cases:

accepting ':' instead of ';' as the delimiter after CSI 38/48, something we should do too. The problem with semicolon is that it's supposed to delimit properties that are independent from each other and take no additional parameters. E.g. vte currently doesn't recognize ^[[38;2;1;3;4 as a true color escape sequence (rgb:1/3/4), but instead it switches to bold(1), italic(3) and underline(4) since it has no clue how many parameters 38;2 is supposed to take.

@egmontkob
Copy link

egmontkob commented Nov 4, 2017

It's a trivial two line patch for me to add support for colons to kitty,

I don't know anything about kitty's internals, so maybe it's really only 2 lines of code, but I have a bit of a doubt here. At least in VTE, it was significantly more complicated than that.

The catch is: You cannot handle ":" the same way as you do ";", that would give us two equivalent separators for no good reason at all and the core problem would remain unsolved. The point is that ":" must only be accepted as a separator between subparameters, and must be refused as a separator at the outer level, that is, between independent attributes.

but I'd rather not, since it adds an extra branch to parsing of the escape code for no good reason.

The very reason is to avoid the mess we're currently having if there's ever again an extension, let's say "38;6;1;2;3;4;5". We can't foresee how many parameters it'll take, and as such, cannot tell where the list continues with other, independent values. Going instead with a syntax like "38:6:1:2:3;4;5" you can already tell where "38:6:" ends and you can already tell that "1" is not bold/bright, "2" is not dim, "3" is not italic, but 4 is underline and 5 is blink; without having any clue whatsoever what the heck "38:6" will mean in the future and how many parameters it'll take. As such, with this syntax you can safely ignore the bits that aren't (yet) supported, and at the same time, correctly process the rest.

Therefore I blame all the terminal emulators that support ";" and not ":" for keeping this mess alive for future extensions, and not putting an end to it now. (Needless to say, it was messed up by whoever first thought it was a good idea to take semicolon-separated subparameters.) Of course, it would only work if all terminal emulators supported ":", or at least a critical majority of them supported so that apps wouldn't revert for the easy solution of ";" but would rather insist on using ":" and would push the remaining terminal emulators to change their behavior. Given that kitty is by far not the only emulator not supporting colon, I don't see a reasonable chance for this to happen, I'm afraid we'll stick with those stupid semicolons and will face this mess again whenever some new extension is added.

@kovidgoyal
Copy link
Owner

:) I see we are coming from very different places. To me, SGR codes are a legacy mess (and this is not the fault of the codes themselves, but of history, and differing implementations in the age before frictionless communication). Generally, better to start in a clean namespace with an escape code design that is well documented (with documentation that is not behind a paywall) and efficient to parse and that comes with a test suite.

As for the actual problem you point out. If you really wanted to extend the SGR codes further you simply specify that parameters after 38, 48 and 58 (for colored underlines) have special semantics. Then you can extend the other codes to your hearts desire. Of course, this complicates parser implementations, but it is no worse than specifying that the colon has special semantics different from the semi-colon, either.

The semi-colon horse has already left the barn. There is no practical way anyone can change all terminal implementations at this point, not to mention the actual terminal emulators in use by users.

So, to re-iterate, in the world we have right now, semi-colons work everywhere, colons work in some places.

@egmontkob
Copy link

egmontkob commented Nov 4, 2017

Generally, better to start in a clean namespace with an escape code design that is well documented (with documentation that is not behind a paywall) and efficient to parse and that comes with a test suite.

Would be nice to have, although I see an even much smaller chance for this than for proper introduction of ":".

The semi-colon horse has already left the barn.

For true colors, yup, it has. For potential future extensions, not necessarily. Although I can't foresee any potential extension (as subcommands of 38 and 48), and indeed the motivation in various terminal emulators' developers is damn low.

There is no practical way anyone can change all terminal implementations at this point, not to mention the actual terminal emulators in use by users.

Ideally, if everyone agreed that we should make an effort here, or if there was some common standard that released a new version which marked ";" as obsolete in favor of ":", it could reasonable be done. Of course you'd still need to wait for a few years before switching the behavior of apps. It's quite hypothetical, I know that (unfortunately – if you ask me) it's most likely not going to happen.

So, to re-iterate, in the world we have right now, semi-colons work everywhere, colons work in some places.

Exactly.

@kovidgoyal
Copy link
Owner

Well, for my part, to be a good citizen, I have added colon support to the SGR parsing code in kitty. It has the good side-effect of making kitty robust against apps like neovim that implement colon output based on fragile capability detection heuristics. e90aaa8

@XVilka You might want to update your list accordingly.

@egmontkob
Copy link

Awesome, thanks a lot! :)

@justinmk
Copy link

justinmk commented Nov 5, 2017

@kovidgoyal Thanks! We will work on better detection in Neovim, where possible.

@kovidgoyal
Copy link
Owner

kovidgoyal commented Nov 23, 2017 via email

@kovidgoyal
Copy link
Owner

And here is my proposal for a better way to fix this:

A new escape code that combines SGR codes with a cell range specification, so you can easily set/reset any attribute on any block of cells with only a few bytes transmitted. With this code, erasing the screen would mean, doing a normal erase and then sending the code to set the background color on all cells.

justinmk added a commit to justinmk/neovim that referenced this issue Nov 23, 2017
133ae5e implemented BCE (background color erase).  That's fine if
the system terminfo claims to support it; but our built-in fallback
should not assume it.

Per kovidgoyal/kitty#160 (comment)
terminal support for BCE seems to be (1) optional and (2) inconsistent.
So the built-in terminfos should disable it by default.

ref neovim#4210
ref neovim#4421
ref neovim#7035
ref neovim#7337
ref neovim#7381
ref neovim#7425
closes neovim#7618
@egmontkob
Copy link

IME only full screen apps need to set default background colors.

My point here was that full screen apps don't necessarily switch to the alternate screen. An approach that doesn't work in the latter case just doesn't sound right.

Another point of mine was the top and bottom lines of Midnight Commander. To push it even further, try mcedit with multiple files in randomly scattered windows (click on the [*] at the upper right and move the subwindows with mouse). Or even just a single file, with a different background color showing when the 80-color right margin is exceeded. Which color should be the terminal's default, and why should this concept exist at all? We'd still want semantically correct copy-pasting or trailing whitespaces, no matter if the text exceeds to the right margin on not.

The notion of one certain color being the "default" one does not necessarily exist (and does not exist in these cases) and should not be forced on apps. Let apps decide which cell has which color, that's all.

I'm not a (neo)vim user but I suppose (neo)vim has something similar too. I'd be surprised if it didn't support something that mcedit does.

The concept of a configurable per-terminal default background is clearly insufficient to address these use cases. The concept of a configurable per-row default background is probably sufficient, and this is kinda-sorta what bce brings in semantically (along with a handful of bad behavior).

Another question is: What should tmux-like software do upon OCS 11?? It cannot directly forward that to the emulator, as that would badly influence other panes as well. It could maybe convert them to SGR RGB and paint each cell with spaces accordingly (if it can be sure that RGB is supported by the emulator).

As for overwriting colors the user has set via OSC 11, that is trivially handled by querying the terminal emulator for the current value of OSC 11

Querying the terminal emulator is anything but trivial, in fact, it's a similarly huge pain point as the palette approach. See https://unix.stackexchange.com/a/390797/53656.

Well, tons of things are not supported by tons of emulators. If we wait for widespread support, we will never progress.

But terminal emulators all adding their own extensions, causing them to diverge more and more, requiring apps to be tested on each and have tons of terminal-specific extensions/quirks/etc. isn't the right approach either. Something is more deeply fundamentally broken here.

So if you wish to propose a better alternative by all means do so, I might even be willing to implement it in kitty,

I'd love to cooperate towards a new solution if I saw any chance of that getting widespread (that is, not VTE and Kitty only). As mentioned, I've actually raised this issue with the key person (xterm/ncurses/tereminfo maintainer) who could help the most to move forward, and whose cooperation is necessary, since without terminfo support you won't be getting anywhere. I failed to get his buy-in or make any progress.

but in the world we have right now, OSC 11 is the best way for fullscreen apps, such as nvim to do themes with background colors.

For the reasons I outlined above, I still disagree with this.

Anyway, I think we agree that all the current approaches have significant drawbacks. Which one is worse and which one is better (read: less bad) is probably a matter of personal taste.

It's not ease of implementation, it's performance. kitty cares about performance, and part of that caring is not implementing stupid features that are bad for performance.

I totally buy your argument that bce is a stupid feature :-) I don't buy the performance one; I mean if it wasn't a stupid one then even if performance was crucial, a memset vs. for-loop couldn't make such a difference to ditch a good feature for it. bce is not a good one, we agree on it, and for this reason (and not the performance one) I totally accept and respect your decision of not supporting it.

Another possible alternative is to use erase-keeping-attributes. [...] A new escape code that combines SGR codes with a cell range specification

I guess I like the former approach better. Anyway, without buy-in from key people, unfortunately I'm not interested in working towards a solution. I just wanted to show a broader picture of the existing problems. As for VTE, a solution would require to eventually ditch bce and hence stop piggybacking on TERM=xterm-256color, deviating from most of the graphical emulators out there. Without seeing most of the major terminal emulators and screen libraries cooperating towards a unified good solution, I don't see a point in VTE diverging further away from the rest and being the "odd" one. (And by the way I probably wouldn't even get approval from the project's main developer.)

Don't get me wrong, I would LOVE to see all key players in the game cooperating, designing and implementing a good solution! Alas, the two of us is nowhere near sufficient for this.

@mtreca
Copy link

mtreca commented Nov 23, 2017

@justinmk Tried in neovim from your tui branch. I still run into the same issue sadly.

@kovidgoyal
Copy link
Owner

@egmontkob I feel for you. A major reason I developed kitty was so I dont have to depend on the stagnant terminal ecosystem for the tools I use. I'm afraid if we are always going to be waiting for "everyone to co-operate" we are going to be waiting forever. The way forward is to get buy in not from the maintainers of terminfo/ncurses, but instead from the developers of key terminal applications. Once major applications start using features not blessed by terminfo, the rest of the ecosystem will follow.

Fortunately, since I write most of the sophisticated terminal applications that I use (apart from vim and zsh) this is easy for me :)

@kovidgoyal
Copy link
Owner

Oh and I know you hate querying terminal emulators, but we have to agree to disagree there. For instance, none of your objections apply to this use case. If the terminal emulator has not responded with the pre-existing OSC 11 value by the time the application quits, it simply resets to null instead. Since this is actually almost never going to happen in practice, it is a non-issue.

@egmontkob
Copy link

A major reason I developed kitty was so I dont have to depend on the stagnant terminal ecosystem for the tools I use.

We have indeed different motives, goals, ideas, and this leads to most of the disagreement between us. You're much more free to go wherever you want to and experiment, I'm more stuck with the current state of things. It'll be interesting to see where this takes us in the long run.

justinmk added a commit to justinmk/neovim that referenced this issue Nov 23, 2017
133ae5e implemented BCE (background color erase).  That's fine if
the system terminfo claims to support it; but our built-in fallback
should not assume it.

Per kovidgoyal/kitty#160 (comment)
terminal support for BCE seems to be (1) optional and (2) inconsistent.
So the built-in terminfos should disable it by default.

ref neovim#4210 neovim#4421 neovim#7035 neovim#7337 neovim#7381 neovim#7425 neovim#7618
justinmk added a commit to justinmk/neovim that referenced this issue Nov 23, 2017
133ae5e implemented BCE (background color erase).  It has caused
a lot of trouble and gained almost nothing.

Per kovidgoyal/kitty#160 (comment)
terminal support for BCE seems to be (1) optional and (2) inconsistent.

ref neovim#4210 neovim#4421 neovim#7035 neovim#7337 neovim#7381 neovim#7425 neovim#7618
@justinmk
Copy link

justinmk commented Nov 23, 2017

@Vxid updated neovim/neovim#7624 to disable BCE almost entirely (for all terminals except real xterm). Can you try it now?

justinmk added a commit to justinmk/neovim that referenced this issue Nov 24, 2017
133ae5e implemented BCE (background color erase). But we can't
trust terminfo, so it is safer disable BCE if we are not certain.

Per kovidgoyal/kitty#160 (comment)
terminal support for BCE seems to be (1) optional and (2) inconsistent.

ref neovim#4210 neovim#4421 neovim#7035 neovim#7337 neovim#7381 neovim#7425 neovim#7618
@mtreca
Copy link

mtreca commented Nov 24, 2017

@justinmk Still broken I'm afraid...

2017-11-24-104112_1920x1080_scrot

@justinmk
Copy link

@Vxid is $XTERM_VERSION defined?

This doesn't make sense.

@mtreca
Copy link

mtreca commented Nov 24, 2017

@justinmk No it is not. $TERM is set to xterm-kitty.

By the way I kitty still echoes the following error messages when opening/using neovim:

[PARSE ERROR] Unknown CSI code: 't' with start_modifier: '' and end_modifier: '' and parameters: '0 69 18'

I also just noticed that the problem does not appear when using neovim inside tmux.

@kovidgoyal
Copy link
Owner

@egmontkob Since you also dont like bce, you might be interested in https://github.com/kovidgoyal/kitty/blob/master/protocol-extensions.asciidoc#setting-text-stylescolors-in-arbitrary-regions-of-the-screen

which allows setting arbitrary style/color attributes in arbitrary reqions of the screen, by extending the existing DECCARA escape code to work with all SGR sequences.

@dryya
Copy link

dryya commented Apr 2, 2018

Hi all, I am still having this issue. As I understand it, neovim still does not support &t_ut, and the fix disabling BCE as long as $XTERM_VERSION is unset does not address this. Are there any known workarounds for the issue? Thanks!

@justinmk
Copy link

justinmk commented Apr 2, 2018

@Aenda Please always mention the exact version of Nvim you're using.

the fix disabling BCE as long as $XTERM_VERSION is unset does not address this

That doesn't make sense.

neovim still does not support &t_ut

It's never going to, there's no reason to.

@dryya
Copy link

dryya commented Apr 2, 2018

I am running 0.2.2-3.

the fix disabling BCE as long as $XTERM_VERSION is unset does not address this

That doesn't make sense.

I am referencing neovim/neovim#7624 which if I am understanding correctly did not stop this issue from occurring. And I only mention &t_ut because it was the other suggested fix in this thread, and is not an option when using neovim. If I have missed a solution to this problem in the thread above, I apologize, and if not, I was just wondering if anyone has discovered a workaround besides just refreshing with ^L when a line disappears.

@justinmk
Copy link

justinmk commented Apr 2, 2018

I am referencing neovim/neovim#7624 which if I am understanding correctly did not stop this issue from occurring.

It can't stop the issue if you use an old version of Nvim. You must use a version that contains that fix.

On GitHub, you can see which tags contain the fix by viewing the commit:

neovim/neovim@303e1df

only tag there (currently) is "nightly", which means it wasn't released. When it is released, you will need to upgrade, Nvim 0.2.2 will never have the fix.

@dryya
Copy link

dryya commented Apr 3, 2018

Sorry - I didn't look closely enough and thought the fix had made it into the November release. I just tried yesterday's neovim nightly build (NVIM v0.2.3-955-g60e96a45b) on the most recent KiTTY build (0.8.4) and the issue still occurs (I used no config file + set relativenumber for neovim and the default config file for KiTTY). Do you have any suggestions? Thanks again for your help and patience.

@whitelynx
Copy link

neovim/neovim#7624 (comment)

Does that mean that neovim/neovim#7624 was reverted? That could explain why it's not helping you, @Aenda.

@justinmk
Copy link

justinmk commented May 9, 2018

@whitelynx No, that's not correct.

@dryya
Copy link

dryya commented May 15, 2018

Not sure what has been changed upstream since I last tried building from source, but the 3.0 build fixes this problem for me - thanks!

@MachFour
Copy link

MachFour commented May 16, 2018

Hi, I recently migrated to Kitty and have been having the missing line issue, reproducible with the commands in a comment further up:

nvim -u NONE
:set relativenumber
iddd<ESC>
yy12p
o<CR>

nvim --version: NVIM v0.3.0-1233-gde7a0bdc3 (built using AUR neovim-git package today)
kitty --version: 0.9.1.r71.g082c771-1 (built using AUR kitty-git package yesterday).

Is there anything I can do about this?

EDIT: Apparently this is a bug in Neovim, so I'll open an issue there.

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