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

OSC11 query caches response until client is changed #3582

Closed
Baspar opened this issue May 31, 2023 · 10 comments
Closed

OSC11 query caches response until client is changed #3582

Baspar opened this issue May 31, 2023 · 10 comments

Comments

@Baspar
Copy link

Baspar commented May 31, 2023

Issue description

Following commit a41a927, the OSC 11 sequence correctly returns the background color, but doesn't reflect any change in background color until client is detached/attached

How to reproduce:

~/osc11.bash

#!/usr/bin/env bash
read -rs -d \\ -p $'\e]11;?\e\\' BG
echo "$BG" \
    | xxd -c 64 \
    | grep -o -E "rgb:.{4}/.{4}/.{4}"
  1. Clean existing tmux tmux kill-server
  2. Start a new session tmux new
  3. bash ~/osc11.bash => rgb:fbfb/f1f1/c8c8
  4. Update the background from the terminal (In my case, Change from OS light mode to dark mode)
  5. bash ~/osc11.bash => rgb:fbfb/f1f1/c8c8 Still shows the previous background color
  6. Detach session C-b d
  7. Re-attach tmux attach
  8. bash ~/osc11.bash => rgb:2020/2020/2020 Shows the new background color

Required information

  • tmux version: tmux next-3.4 @ 0eb5d25
  • Platform: Darwin arm
  • $TERM inside tmux: xterm-256color
  • $TERM outside tmux: xterm-256color
  • Terminal: Wezterm
@nicm
Copy link
Member

nicm commented May 31, 2023

There is no mechanism for the terminal to tell tmux the colour has changed and polling for the background colour would be silly. If you change the background colour outside tmux you need to detach and reattach.

@Baspar
Copy link
Author

Baspar commented Jun 1, 2023

Isn't a41a927 simply relaying the OSC11 ? request to the terminal in case the default background colour isn't set ?
In which case, it should print the updated background in step 5., since that's how it behaves when I run those steps outside of Tmux

@nicm
Copy link
Member

nicm commented Jun 1, 2023

Good point, but no, it doesn't, it reads the default value on attach and uses that if you haven't set a background inside tmux.

@Baspar
Copy link
Author

Baspar commented Jun 1, 2023

Then it explains the behavior indeed.
Is there any plan to add that functionality (If it's possible to implement), or would you be open to a PR for it ?

@nicm
Copy link
Member

nicm commented Jun 1, 2023

I would accept a PR but I don't know how easy it would be, it might be fiddly to do (there isn't a way for it to wait for a reply before sending the response).

@vimpostor
Copy link

vimpostor commented Jul 7, 2023

polling for the background colour would be silly

Zellij queries for the bg/fg colour on every SIGWINCH (in addition to on attach), see: zellij-org/zellij#1358

Maybe this could help here, but it looks like not many terminals send SIGWINCH when their colorscheme changes (I only know of iTerm that does this, but it might be something worth implementing in other terminal emulators).

Edit: On second thought, SIGWINCH may be triggered multiple times per second on a real window resize. Repeatedly polling for fg/bg colors could cause performance problems.

@nicm
Copy link
Member

nicm commented Sep 2, 2023

Try this please which will do it on WINCH but at most once every 30 seconds: tmux-fgbg-winch.diff.txt

@vimpostor
Copy link

@nicm I can confirm the patch is working.

Tested with starting vim inside tmux (which sets background according to OSC11 response), as well as with a manual printf '\e]11;?\a'.

The only problem with this implementation is that tmux may miss a colorscheme change, if the user resizes the window and then changes the colorscheme within the next 30 seconds. But still, it's better than nothing.

@nicm
Copy link
Member

nicm commented Sep 2, 2023

Great, I have applied this to OpenBSD now, it will be in GitHub later. Thanks!

@nicm nicm closed this as completed Sep 2, 2023
@github-actions
Copy link

github-actions bot commented Oct 3, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants