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

Zellij + Noice.nvim causes screen flickering. #3208

Closed
malaow3 opened this issue Mar 19, 2024 · 21 comments · Fixed by #3439
Closed

Zellij + Noice.nvim causes screen flickering. #3208

malaow3 opened this issue Mar 19, 2024 · 21 comments · Fixed by #3439

Comments

@malaow3
Copy link

malaow3 commented Mar 19, 2024

This issue is documented in an issue for Noice, however, it is not reproducible when outside of Zellij.
Link to the original issue: folke/noice.nvim#658

I have had the issue occur on both Mac and WSL.

@Avanta8
Copy link

Avanta8 commented Mar 31, 2024

I also have this cursor flickering issue when using Zellij with Neovim.

I've found that it's not necessarily due with noice.nvim, as it also happens if I have a few floating windows open at the same time.

@Peeeaje
Copy link

Peeeaje commented May 14, 2024

Any update for this? (I have flickering even when disalbling noice.)

I didn't have any flickering on v0.39 but when I updated to v0.40 it started to happen for me.

@imsnif
Copy link
Member

imsnif commented May 14, 2024

A few things:

  1. Try to use a terminal that supports synchronized renders (CSI 2026) - without this most remedies we can make are cosmetic and won't do much for eg. old hardware (I recommend Alacritty)
  2. If nvim/noice (I'm not sure who's in charge of rendering in that ecosystem) don't use CSI 2026, I'd recommend their maintainers implement them for supported terminals
  3. If 2 and 3 are true (i.e. nvim+noice use CSI 2026 and the terminal supports it) and there are still flickers, this might be something on the Zellij-side (eg. an extra render in certain cases). In this case, please follow the rules in the issue template and attach a debug log so that I can take a look.

Thanks!

@johnpyp
Copy link

johnpyp commented May 31, 2024

This isn't a full reproduction, but I've found that https://github.com/j-hui/fidget.nvim causing LSP status messages to come through (like for rust-analyzer) causes this flickering intensely with Zellij, and I also have noice.nvim turned on. I also see it with tmux but significantly less, and I don't see it all just on kitty.

All of this is happening with kitty, which does support CSI 2026, and I also confirmed with contour (term from the CSI 2026 spec creator) that the same behavior happens there.


Update: It seems that disabling all of noice's messages and notify options, then using fidget.nvim without noice's overridden backends, gets rid of the flickering. This might be an easy way to reproduce.

I'm guessing this doesn't have to do specifically with noice, but it's doing pretty invasive things, which cause this issue aggressively particularly when combined with fast re-draw updates like with fidget.nvim.

@johnpyp
Copy link

johnpyp commented Jun 1, 2024

Another thing I found: doing set notermsync in neovim seems to get rid of the issue of the cursor flickering around for me, though it introduces some other slight flickering during things like pane resizes.

I realized that doing a pane resize in Zellij was causing the same cursor flickering that I was noticing with noice, so that may be an even easier predictable way to trigger the issue.

Unfortunately, running nvim -u NONE and running set termsync doesn't seem to exhibit the same behavior... so there's something else happening too (or maybe something slowing down neovim redraws that makes it slow enough to be noticeable, possibly noice).

@Peeeaje
Copy link

Peeeaje commented Jun 1, 2024

@johnpyp
Disabling set notermsync fixed the flickering for me too, using alacritty.

@pierregoutheraud
Copy link

pierregoutheraud commented Jun 18, 2024

I am also experiencing this flickering cursor issue in Neovim (0.10.0) only when using zellij (version 0.41.0) and not when using Tmux. This problem occurs in both Kitty and Alacritty terminals. The notermsync option does resolves the issue when switching between tabs in zellij but the flickering remains when moving the cursor at the same as Neovim tries to render a floating window.

On zellij the cursor flickers:

bug-zellij.mov

During that flickering frame the cursor is sometimes actually rendered somewhere else in the terminal:
Screenshot 2024-06-18 at 14 31 32

Sometimes during that frame, the cursor just disapears and the floating window is half rendered:
Screenshot 2024-06-18 at 15 17 53

It almost feels like zellij is making the terminal render too many or unnecessary frames.

On tmux, the cursor does not flicker:

no-bug-tmux.mov

@imsnif
Copy link
Member

imsnif commented Jun 18, 2024

Hi friends,

Thanks to everyone for pointing out their reproductions and experiences here, but at this point I don't think this adds anything to the discussion. This issue is 99% a misimplementation of CSI 2026 (synchronized renders) by either noice or nvim (as demonstrated by shutting them down mitigating this issue).

I'm happy to look into this on the Zellij side if (and only if) I am given a dump of ANSI instructions (as specified in the ISSUE_TEMPLATE) that can be cated into the terminal to reproduce the issue, that has a CSI 2026 start and end instructions at its beginning and end and the cursor still flickers in between.

I don't want to lock this issue for further comments, but I'm sorry - I'm going to have to delete further comments that only retell the same experience (even if they do include very thoughtful and detailed reconstructions or videos). I don't mean to shut anyone up or be ungrateful for your details, but such comments don't add to the discussion and get in the way of solving the issue by pushing away this very explicit requirement of mine expressed here and in the comment above.

Thank you for understanding.

@pierregoutheraud
Copy link

Hello @imsnif Thank you for your answer!
I understand that we are not really helpful and I am sorry it is frustrating.
That said, Neovim is quite a popular tool so I feel like it's worth investigating.
I would like to provide you with what you need but bare with me as my knowledge of how terminal works is close to 0.
If I understand correctly zellij debug only keeps the ANSI sequences of the last few frames of the terminal state in the log (when we press ctrl+q).
As this issue is only visible on 1 frame, I failed to understand how I can be fast enough to capture the exact moment of the issue before it's gone?
Do you indeed need that I press ctrl+q on the exact moment the cursor flicker?
I am not sure that I can do that but I tried so here is what I did achieve to capture:

zellij-12.log

I can successfully cat this file on my computer and see the state of the terminal captured.

Size of my terminal:

$ stty size
57 252

Let me know how I can help you to debug this.
Thank you again!

@pierregoutheraud
Copy link

Just so you know I posted an issue on neovim since you seem to think that its an issue on their implementation.
neovim/neovim#29427
I will let you know.

@imsnif
Copy link
Member

imsnif commented Jun 20, 2024

Hey, for the record: I looked at the dump and the CSI 2026 appears at the beginning and end properly (this is a dump of the whole terminal state, not just one frame - indeed the CSI 2026 serves as the definition of the frame start and end).

I cated it into my terminal and saw no flicker. It was rendered as one frame properly. I'm not saying there isn't a bug here, but I'll need a reproduction: namely one that involves misbehaving ANSI. I'm sorry, I realize this might be a lot to ask from someone who is not familiar with the ecosystem, but so is installing the right set of neovim plugins to reproduce a set of misbehaving ANSI.

I'm happy to look into this further and am not trying to throw blame on anyone, but I'm still not certain the bug is in Zellij and I'm going to need more legwork in the reproduction.

@pierregoutheraud
Copy link

pierregoutheraud commented Jun 20, 2024

I manage to reproduce the issue with this minimal neovim configuration:

-- minimal.lua file
function open_floating_window()
  -- Get the current buffer handle
  local buf = vim.api.nvim_create_buf(false, true)

  -- Define the window options
  local opts = {
    relative = "editor",
    width = math.floor(vim.o.columns * 0.8),
    height = math.floor(vim.o.lines * 0.8),
    col = math.floor(vim.o.columns * 0.1),
    row = math.floor(vim.o.lines * 0.1),
    anchor = "NW",
    style = "minimal",
  }
  
  -- Create the window
  vim.api.nvim_open_win(buf, true, opts)
end

-- Open the window with "f" key in normal mode
vim.api.nvim_set_keymap(
  "n",
  "f",
  ":lua open_floating_window()<CR>",
  { noremap = true, silent = true }
)

Start zellij and then open neovim with this configuration file with nvim --clean -u minimal.lua
When you press "f" you should see a window open and the weird cursor behavior happen. (More info here: neovim/neovim#29427)

Disabling termsync on neovim "improves" the bug as the cursor stay put in 1 position but it still blinks.

@imsnif
Copy link
Member

imsnif commented Jun 20, 2024

Not reproducing I'm afraid...

2024-06-20.18-39-23.mp4

Are you on the latest version of Alacritty? They only implemented support for synchronized renders in 0.13.0 iirc.

@pierregoutheraud
Copy link

pierregoutheraud commented Jun 20, 2024

@imsnif And when you spam "f" the cursor isn't blinking at all?

Kitty 0.35.1 and Alacritty 0.14.0-dev next to each other:

Screen.Recording.2024-06-20.at.21.52.54.mov

@Peeeaje
Copy link

Peeeaje commented Jun 21, 2024

It reproduced for me too, using the minimal.lua.
Alacritty Version 0.13.2
NVIM v0.10.0
zellij 0.40.1

@imsnif
Copy link
Member

imsnif commented Jun 21, 2024

Alright, I got it! This was indeed an issue in the Zellij rendering engine, as nvim here was correctly sending us a single frame in this case and we were issuing two renders for it (one for the frame, one for the cursor at an arbitrary time within the frame). That's why the flickering only happened sometimes, and why I had trouble reproducing it even with the ANSI dump.

The reproduction with the single lua file was a good call @pierregoutheraud, thanks! It was a good compromise that didn't require me to do a PhD in neovim plugin installation/configuration as these reproductions often do :) I am but a simple vim user who doesn't even use static code analysis when developing.

This will be released in the next version, which I unfortunately do not yet have an ETA for. You can always use the version from main, but I very much do not recommend using unreleased versions.

@pierregoutheraud
Copy link

Thank you very much @imsnif, zellij is awesome.

@pierregoutheraud
Copy link

pierregoutheraud commented Jun 21, 2024

@imsnif Out of curiosity I built the main branch and I am still unfortunately reproducing the cursor flickering.
Also another glitch (I doubt this is caused by #3439) which could be related to the cursor flickering is that the window is now rendered in multiple frames from top to bottom as you can see here:

Screen.Recording.2024-06-21.at.15.01.48.mov

zellij-12.log

@imsnif
Copy link
Member

imsnif commented Jun 21, 2024

For the removal of doubt: I'm not reproducing this (otherwise I wouldn't have issued the fix). Only thing I can think of is to make sure you built correctly following the instructions in CONTRIBUTING.md (and of course the other stipulations from above). This issue is solved, if you find other issues, please open them as separate issues with either an ANSI dump (the one you attached above seems correct and without issues) or a reproduction similar to your previous one.

Please be 100% sure in your reproduction, this is a large project and I don't usually have the capacity for this back-and-forth.

@patrick91
Copy link

@imsnif @pierregoutheraud not sure if this helps, but for me the flicker is gone when
installing with brew: brew install --HEAD zellij 😊

@pierregoutheraud
Copy link

pierregoutheraud commented Jun 21, 2024

@imsnif My bad, I had added vim.opt.termsync = false on my the minimal.lua -_-
That's perfect now with vim.opt.termsync = true on your main branch 👍 Thank you for your patience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants