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

pr/199 #209

Merged
merged 5 commits into from
Oct 2, 2024
Merged

pr/199 #209

merged 5 commits into from
Oct 2, 2024

Conversation

3rd
Copy link
Owner

@3rd 3rd commented Aug 15, 2024

@maxbol
Copy link
Contributor

maxbol commented Sep 29, 2024

#199 still does not work for me. Doing some quick print debugging on the code it looks like utils.tmux.get_current_session() always returns the name of the session where the editor that lost focus lives. So it always is the same as initial_tmux_session when losing focus due to switching sessions, and therefore nothing gets cleared. Using tmux 3.4 and Neovim 0.10.1.

EDIT: Ran a quick experiment with tmux display-message and it looks like #{session_name} always reports the name of the session that the process is run from. To validate, open a tmux session and run:

sleep 2 && tmux display-message -p '#{session_name}'

And quickly step into another session before the command triggers. It will never pick up any other session name than the name of the session from where the cmd was run. (Note that this behavior is different from when running display-message from outside of tmux.)

EDIT2: Changing session_name to client_session at least gives the expected behavior, ie the handler for FocusLost triggers when it is supposed to. But this still doesn't seem to actually clear the image for me!! And the reason for this is that seems to be that pane_tty (that gets send to kitty by backend.delete) seems to have the same limitation as session_name, i.e. it only provides the tty of the pane that is currently active in the same session where the cmd is run... sigh...

@maxbol
Copy link
Contributor

maxbol commented Sep 29, 2024

I believe the correct way to get the pane TTY for deleting the image should be:

tmux list-panes -t $(tmux display-message -p '#{client_session}') -F '#{pane_tty}' -f '#{pane_active}'

EDIT: This tmux.lua solved the issue for me. Will try to get a PR together tomorrow.

local is_tmux = vim.env.TMUX ~= nil

local has_passthrough = false
if is_tmux then
  local ok, result = pcall(vim.fn.system, "tmux show -Apv allow-passthrough")
  if ok and result:sub(-3) == "on\n" then has_passthrough = true end
end

local create_dm_getter = function(name)
  return function()
    if not is_tmux then return nil end
    local result = vim.fn.system("tmux display-message -p '#{" .. name .. "}'")
    return vim.fn.trim(result)
  end
end

local create_dm_window_getter = function(name)
  return function()
    if not is_tmux then return nil end
    local result = vim.fn.system(
      "tmux list-windows -t $(tmux display-message -p '#{client_session}') -F '#{" .. name .. "}' -f '#{window_active}'"
    )
    return vim.fn.trim(result)
  end
end

local create_dm_pane_getter = function(name)
  return function()
    if not is_tmux then return nil end
    local result = vim.fn.system(
      "tmux list-panes -t $(tmux display-message -p '#{client_session}') -F '#{" .. name .. "}' -f '#{pane_active}'"
    )
    return vim.fn.trim(result)
  end
end

local escape = function(sequence)
  return "\x1bPtmux;" .. sequence:gsub("\x1b", "\x1b\x1b") .. "\x1b\\"
end

return {
  is_tmux = is_tmux,
  has_passthrough = has_passthrough,
  get_pid = create_dm_getter("pid"),
  get_socket_path = create_dm_getter("socket_path"),
  get_current_session = create_dm_getter("client_session"),
  get_window_id = create_dm_window_getter("window_id"),
  get_window_name = create_dm_window_getter("window_name"),
  get_pane_id = create_dm_pane_getter("pane_id"),
  get_pane_pid = create_dm_pane_getter("pane_pid"),
  get_pane_tty = create_dm_pane_getter("pane_tty"),
  get_cursor_x = create_dm_getter("cursor_x"),
  get_cursor_y = create_dm_getter("cursor_y"),
  escape = escape,
}

@maxbol
Copy link
Contributor

maxbol commented Sep 30, 2024

See #221

…us-getters

Add TMUX session agnostic status getters
@3rd
Copy link
Owner Author

3rd commented Oct 2, 2024

Thank you @maxbol 🙏

@3rd 3rd closed this Oct 2, 2024
@3rd 3rd reopened this Oct 2, 2024
@3rd 3rd merged commit e59eabf into master Oct 2, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

3 participants