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

[Feature Request] Support use of Zellij with Neovim smart splits plugin #2434

Closed
linux-cultist opened this issue May 9, 2023 · 18 comments
Closed

Comments

@linux-cultist
Copy link

This neovim plugin supports tmux and I was wondering if it could support zellij as well: https://github.com/mrjones2014/smart-splits.nvim

I asked on the plugin github page and the author says he would need command line support for a few things: mrjones2014/smart-splits.nvim#111

Have a look and see if this is something you would consider implementing, to increase adoption of zellij in the neovim community. Thank you!

@mrjones2014
Copy link

mrjones2014 commented May 9, 2023

Adding extra context here. I reached out in the matrix channel and there is a caveat:

tl;dr: the only hard blocker to my plugin supporting ZelliJ is a way to get the currently focused pane ID via the CLI, is that possible?

hey, so this is a bit of a hard thing to do in the context of Zellij... Zellij supports true multiplayer sessions, meaning each connected user gets their own cursor. If they are focused on different panes, which ID would you expect to receive?
We can't know who issued the command from the CLI, because the shell doesn't know about the multiple users. It could very well be that one user started typing the CLI command, another user finished typing it and a third user pressed ENTER.
We could give you a list, but then we're just offloading the problem to you :)

Maybe it would be possible for smart-splits.nvim to just not support multiple sessions and disable the mux integration if Zellij returns more than one focused pane ID.

I'll also copy my table here for convenience. I have a Lua API wrapper around multiplexer backends, here's the support table I made for Zellij:

Lua method Zellij CLI support
is_in_session() Maybe possible with zellij list-sessions?
current_pane_id() No CLI command I could find. Is there an environment variable, maybe?
current_pane_at_edge(direction) No CLI command I could find. Can possibly be worked around with zellij cli move-focus back and forth.
current_pane_is_zoomed() zellij cli toggle-fullscreen exists, but no way to check if it is fullscreen. Not a critical component for the plugin, options may not work completely correctly.
next_pane(direction) zellij action move-focus [direction]
resize_pane(direction) zellij action resize [direction]
split_pane(direction) zellij action new-pane --direction [direction]

For the current_pane_is_zoomed(), it's not critical, but the smart-splits.nvim option disabled_multiplexer_navigation_while_zoomed will not work without it. That's alright though, Kitty terminal's built-in mux doesn't support this option either.

@linux-cultist
Copy link
Author

Yes I think not supporting multiple sessions would be fine, and plugin integration would still be super useful for most users.

@jaeheonji
Copy link
Member

Maybe this issue will help. #967

@mrjones2014
Copy link

It looks like that issue is already resolved. Anyway, it's only somewhat related.

A way to get the currently focused Pane ID is the only thing preventing smart-splits.nvim from supporting Zellij at the moment.

smart-splits.nvim adds some extra nice navigational features, some of which require being able to determine the current mux pane ID.

@tlinford
Copy link
Contributor

Adding this action to get the current pane id should not be a problem really, just needs someone to pick it up.

@Kangaxx-0
Copy link
Contributor

I am not familiar with smart-splits.nvim plugin, but if the requirement is only to add a new action that returns the current active pane id, I can spend some time on that

@mrjones2014
Copy link

For full/better support, we'd also need a way to check if that pane is at an edge of the screen, and a way to tell if the pane is zoomed/maximized, but we can do rudimentary support with just a way to get the current pane ID.

To check if we're at the edge, we can try moving to a new pane, and if the same pane ID is returned, then we're at an edge. It's a bit of a hack and looks a little weird since the cursor will flash, but it works.

See the table I support posted above.

@Kangaxx-0
Copy link
Contributor

I've got an active pr to implement swap tab - #2242, it already does a check if pane is at an edge, I can include that in my pr as rudimentary support :)

@Kangaxx-0
Copy link
Contributor

I've published a pr for this, want to have some feedbacks before I continue

@Kangaxx-0
Copy link
Contributor

QQs:

  • what does is-in-session API do?, what is expected to return ?
  • current_pane_at_edge(direction) -> if I call this with right, then the expected result is either true or false, a simply boolean value?

@mrjones2014
Copy link

is_in_session just returns a Boolean indicating if you’re in a session for the mux.

current_pane_at_edge('right') should return true if the current page is at the right edge, correct.

@Kangaxx-0
Copy link
Contributor

is_in_session just returns a Boolean indicating if you’re in a session for the mux.

current_pane_at_edge('right') should return true if the current page is at the right edge, correct.

Thanks, :) FYI - I am having an active pr to handle wrap around panes: Say you have one tab with 3 panes in zellij - A|B|C, and the C is current one, then when you move to the right, zellij will automatically focus the leftmost one which is A.

For this feature request - having 3 separated APIs(paneId, at the edge and is_in_session) makes more sense, I will continue the rest of code changes

@Kangaxx-0
Copy link
Contributor

I've added the support to know if a pane is on the edge by giving direction. For is_in_session, I don't think it is really necessary since it is always the case

@mrjones2014
Copy link

mrjones2014 commented Jun 10, 2023

For is_in_session, I don't think it is really necessary since it is always the case

yeah this is more for my side, it can be implemented by checking if the current pane ID returns a value or not, in my plugin. I don’t think we need anything special from zellij for this.

@lukebarton
Copy link

I’d really like to see this supported because having 3 separate sets of keybinds for switching windows, zellij panes and nvim splits is quite inconvenient.

@imsnif
Copy link
Member

imsnif commented May 2, 2024

Hey @mrjones2014 - just released a patch version (0.40.1) that among other things includes:

  1. zellij action list-clients (feat(cli): list clients, their focused pane_id and the running command #3314)
  2. Support for binding Ctrl j

I think these two should allow you to perform the integration?

Also just note: you can always look at the ZELLIJ_PANE_ID environment variable to get the terminal pane id of a pane (in zellij action list-clients this will be translated to terminal_<ZELLIJ_PANE_ID>.

@mrjones2014
Copy link

you can always look at the ZELLIJ_PANE_ID environment variable to get the terminal pane id of a pane

This is the pane ID of the current pane, right? I still need to use zellij action list-clients if I want to be able to get the ID of the active pane, from any other pane?

If that's possible now, then yeah I think we should be able to integrate with Zellij!

@imsnif
Copy link
Member

imsnif commented May 2, 2024

To your questions, in order: yes and yes :)

Happy hacking!

@imsnif imsnif closed this as completed May 2, 2024
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

7 participants