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

select_pane not working correctly with multiple sessions #487

Open
Timoses opened this issue Jun 28, 2023 · 2 comments
Open

select_pane not working correctly with multiple sessions #487

Timoses opened this issue Jun 28, 2023 · 2 comments

Comments

@Timoses
Copy link
Contributor

Timoses commented Jun 28, 2023

The code of select_pane is:

        if target_pane in ["-l", "-U", "-D", "-L", "-R"]:
            proc = self.cmd("select-pane", "-t%s" % self.window_id, target_pane)
        else:
            proc = self.cmd("select-pane", "-t%s" % target_pane)

If calling it with a pane index (e.g. window.select_pane(3)) the resulting command will be select-pane -t3. This will result in self.server.cmd('select-pane -t3').

=> It will always change the pane in the session number 1.

Shouldn't there be some kind of further target description like
select-pane -t $3:@9.3 (change to pane 3 in session 3, window9)
?

@tony
Copy link
Member

tony commented Jun 28, 2023

Hi!

Can you restate some of the above? It isn't clear to me.

On a side note: PRs, especially ones with good tests, are also welcome

@Timoses
Copy link
Contributor Author

Timoses commented Jun 28, 2023

Hey tony. Sure.

As an example, I have the following

session = None
sessions = self._server.attached_sessions
if len(sessions) > 1:
    log.info('There are more than 1 sessions active. Unable to detect active one.')
elif len(sessions) == 1:
    session = sessions[0]
else:
    log.info('No active sessions found.')

session.attached_window.select_pane(3)

I use only one client attached to one session, which I make sure is true.

The session is always correct (the one I am active in).
However, running select_pane(3) on the attached window always switches the pane in one specific session (even when I am active in another and the session variable is correct.

The select_pane method ultimately calls the window function self.cmd here: https://github.com/tmux-python/libtmux/blob/master/src/libtmux/window.py#L163

self.cmd("select-pane", "-t%s" % target_pane)

(select-pane -t3)

This ends up in the server function self.server.cmd here: https://github.com/tmux-python/libtmux/blob/master/src/libtmux/window.py#L141

self.server.cmd(cmd, *args, **kwargs)

(select-pane -t3)

Which then ends up here: https://github.com/tmux-python/libtmux/blob/master/src/libtmux/server.py#L177

tmux_cmd(*cmd_args, **kwargs)

which will probably end up in calling tmux select-pane -t3.

=> This does not switch the pane in the active session window, but in another one.

I just tested a bit. When I run the shell command tmux select-pane -t3 in any session it correctly switches the pane.

Could it be that, because the python program (doing the switching) is running in another session, it always switches panes in that session?
^ I just tested above theory: and yes, that is the case.

=> I think it would be wise to always pass the session_id and window_id with the -t argument!?

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

No branches or pull requests

2 participants