Skip to content

fix(lazygit): only write palette escapes when a TUI can receive them - #2922

Open
wmaurer wants to merge 1 commit into
folke:mainfrom
wmaurer:fix/lazygit-osc-only-on-tty
Open

fix(lazygit): only write palette escapes when a TUI can receive them#2922
wmaurer wants to merge 1 commit into
folke:mainfrom
wmaurer:fix/lazygit-osc-only-on-tty

Conversation

@wmaurer

@wmaurer wmaurer commented Jul 27, 2026

Copy link
Copy Markdown

Fixes #2921

Snacks.lazygit writes OSC 4 palette escapes for numeric theme keys straight to stdout. With a GUI frontend (Neovide, neovim-qt, any --embed client) stdout is the msgpack-RPC channel, so the bytes corrupt the protocol stream instead of reaching a terminal; Neovide logs ERROR [neovide::bridge::session] ]4;241;... on every lazygit open.

This PR guards the write the same way Neovim core does:

  • On 0.12+ it uses vim.api.nvim_ui_send(), which is routed to the TUI host terminal and is a no-op for GUIs; core's OSC 52 clipboard moved to it.
  • On 0.10/0.11 it falls back to the nvim_list_uis() check from runtime/lua/vim/_defaults.lua (ui.chan == 1 and ui.stdout_tty). Under Neovide the attached UI reports chan == 1, stdout_tty == false, so stdout_tty is the discriminating field.
  • On 0.9 the stdout_tty field does not exist yet, so the old behavior is kept there.

Same fix as AstroNvim/astroui#66, where this code was adapted to.

Tested on Neovim 0.12.4 with the repro from #2921: headless/GUI path no longer leaks the escape; under a real pty the escape still reaches the terminal. stylua --check and selene are clean on the changed file.

With a GUI frontend (Neovide, neovim-qt, any --embed client) stdout is
the msgpack-RPC channel, so writing OSC 4 palette escapes to it corrupts
the protocol stream instead of reaching a terminal. Use
vim.api.nvim_ui_send() on 0.12+ (routed to the TUI host terminal, no-op
for GUIs) and fall back to the nvim_list_uis() check Neovim core uses in
runtime/lua/vim/_defaults.lua on 0.10/0.11. On 0.9 the stdout_tty field
does not exist yet, so the old behavior is kept there.

Fixes folke#2921
@github-actions github-actions Bot added lazygit size/m Medium PR (<50 lines changed) labels Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lazygit size/m Medium PR (<50 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: lazygit writes OSC 4 palette escapes to stdout under GUI frontends (Neovide), corrupting the RPC stream

1 participant