zellij icon indicating copy to clipboard operation
zellij copied to clipboard

Zellij + Noice.nvim causes screen flickering.

Open malaow3 opened this issue 11 months ago • 1 comments

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

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

malaow3 avatar Mar 19 '24 14:03 malaow3

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.

Avanta8 avatar Mar 31 '24 11:03 Avanta8

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.

Peeeaje avatar May 14 '24 05:05 Peeeaje

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!

imsnif avatar May 14 '24 05:05 imsnif

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 avatar May 31 '24 23:05 johnpyp

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).

johnpyp avatar Jun 01 '24 00:06 johnpyp

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

Peeeaje avatar Jun 01 '24 23:06 Peeeaje

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:

https://github.com/zellij-org/zellij/assets/1341781/65495d7e-6274-48f7-9ab7-0f9d6393545e

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:

https://github.com/zellij-org/zellij/assets/1341781/ab54ba43-fdfb-44b0-8113-ef2f81148d1e

pierregoutheraud avatar Jun 18 '24 13:06 pierregoutheraud

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.

imsnif avatar Jun 18 '24 13:06 imsnif

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 avatar Jun 18 '24 15:06 pierregoutheraud

Just so you know I posted an issue on neovim since you seem to think that its an issue on their implementation. https://github.com/neovim/neovim/issues/29427 I will let you know.

pierregoutheraud avatar Jun 20 '24 09:06 pierregoutheraud

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.

imsnif avatar Jun 20 '24 11:06 imsnif

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: https://github.com/neovim/neovim/issues/29427)

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

pierregoutheraud avatar Jun 20 '24 16:06 pierregoutheraud

Not reproducing I'm afraid...

https://github.com/zellij-org/zellij/assets/795598/02c6c0e6-7b3e-4400-bee0-27f8e3ae3984

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

imsnif avatar Jun 20 '24 16:06 imsnif

@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:

https://github.com/zellij-org/zellij/assets/1341781/a81bdb0b-9f9d-4a17-a7cf-8fea5c25203a

pierregoutheraud avatar Jun 20 '24 19:06 pierregoutheraud

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

Peeeaje avatar Jun 21 '24 06:06 Peeeaje

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.

imsnif avatar Jun 21 '24 11:06 imsnif

Thank you very much @imsnif, zellij is awesome.

pierregoutheraud avatar Jun 21 '24 12:06 pierregoutheraud

@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 https://github.com/zellij-org/zellij/pull/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:

https://github.com/zellij-org/zellij/assets/1341781/025f6cba-d128-4c73-b403-e06d752b836c

zellij-12.log

pierregoutheraud avatar Jun 21 '24 13:06 pierregoutheraud

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.

imsnif avatar Jun 21 '24 13:06 imsnif

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

patrick91 avatar Jun 21 '24 13:06 patrick91

@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.

pierregoutheraud avatar Jun 21 '24 16:06 pierregoutheraud

I wonder why this issue persists with iterm? Is there any setting I should look at?

chardskarth avatar Aug 05 '24 21:08 chardskarth

@chardskarth are you using the latest version from main?

patrick91 avatar Aug 08 '24 20:08 patrick91

Nope. Using 0.40.1. I'll try getting the one from main

chardskarth avatar Aug 09 '24 09:08 chardskarth

🎉 it works fine with the latest main! Thanks!!

chardskarth avatar Aug 09 '24 10:08 chardskarth

Hi, bumping this because, although the minimal reproduction is indeed fixed on master, the noice plugin's floating cmdline still causes cursor flickering, both with and without termsync. Will try to come up with a repro.

iniw avatar Aug 29 '24 21:08 iniw

Hi everyone, it seems like I ran into this issue too, I just tested in iterm2, and wezterm + lazyvim and this issue still happened. Here my Wezterm test:

https://github.com/user-attachments/assets/60631375-d116-471a-9a2e-3a6e18071621

namdang-eh avatar Sep 12 '24 02:09 namdang-eh

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

I ran brew install --HEAD zellij and now brew is downloading half of the Internet as dependencies 😅

starkovv avatar Sep 21 '24 15:09 starkovv

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

I ran brew install --HEAD zellij and now brew is downloading half of the Internet as dependencies 😅

This means you're building the latest version right? Does it still flicker when Command modal is open?

chardskarth avatar Sep 21 '24 20:09 chardskarth

Hi, bumping this because, although the minimal reproduction is indeed fixed on master, the noice plugin's floating cmdline still causes cursor flickering, both with and without termsync. Will try to come up with a repro.

Any updates @iniw ? Most of the comments here are (I guess) due to people thinking this has already been released while it's still just in main. I'm trying to close some final bugs before the release, so if you or anyone else has a reproduction (that does not involve installing nvim plugins) where this still happens, I'd be happy to patch it up and include it in the release.

For others reading this issue - I urge you to read the entire thread before commenting, this otherwise creates a lot of noise and gets in the way of solving any issue that may or may not still be present. Thanks. (HINT: if you're unsure whether something has been released or not, you can check the linked PRs to this issue and then cross-reference them with the CHANGELOG.md file in the repository root, there you'll either see them under a specific version or under unreleased - I try to keep the changelog as up to date and concise as possible).

imsnif avatar Oct 01 '24 06:10 imsnif