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

xplr plugin experiment #383

Open
sayanarijit opened this issue Apr 26, 2021 · 8 comments
Open

xplr plugin experiment #383

sayanarijit opened this issue Apr 26, 2021 · 8 comments
Labels
plugin system Enhancement or fixes related to plugin system plugin Issue related to plugins

Comments

@sayanarijit
Copy link

Creating this issue to discuss the possibility and challenges of having xplr as a Zellij plugin.

@sayanarijit
Copy link
Author

sayanarijit commented Apr 26, 2021

As of now, I'm stuck at getting let pid = std::process::id(); to work.
I need some ID unique to each xplr session so that I can create the ${runtimedir}/xplr/sessions/${session_pid} directory.
This directory will be used to store runtime files for each particular xplr session.

@sayanarijit
Copy link
Author

However, when I execute std::process::id() the process panics with

➜  xplr git:(experiment/zellith) RUST_BACKTRACE=1 zellij -l plugin.yaml
thread 'main' panicked at 'unsupported', library/std/src/sys/wasi/os.rs:222:5
                                                                             note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@a-kenji a-kenji added plugin Issue related to plugins plugin system Enhancement or fixes related to plugin system labels Apr 26, 2021
@TheLostLambda
Copy link
Member

TheLostLambda commented Apr 26, 2021

Hello @sayanarijit ! The WASI environment is rather sandboxed and quite unaware of the operating system it is running on (by design), so using anything from std::process is probably not going to work very well. If you'd just like a unique id, we can add an API call for that?

If you decide that you definitely need a unique ID, drop a message in #280 and I'll bump that to the top of my priority list!

EDIT: Would it be more useful for you to have the PID of Zellij? Perhaps a combination of the Zellij PID and internal plugin ID?

@sayanarijit
Copy link
Author

sayanarijit commented Apr 26, 2021

Hey @TheLostLambda then I guess most of xplrs functionalities won't work since it depends heavily on command invocation. Is it possible to expose an API via which xplr can delegate commands? If yes, would it be possible to also return the status code of the invoked command.?
As for the pid, zellij pid should work fine. The combination will also work if it stays the same across the panes and windows.

@sayanarijit
Copy link
Author

Even better if I can get both, id unique to session and panes & windows.

@TheLostLambda
Copy link
Member

Can definitely add an API for command delegation! I think the only thing that needs to happen before that is some sort of plugin permissions system (as plugins being able to call arbitrary shell commands is a bit of a security risk). I'll add that to my list!

How would you like a get_id() function that returns a struct like:

ID {
   plugin_id: u32,
   zellij_pid: u32
}

That's something easy enough to knock out in a couple of minutes I think!

@sayanarijit
Copy link
Author

@TheLostLambda awesome. That will work.

@TheLostLambda
Copy link
Member

@sayanarijit Et voila! It's bizarre, but this simple API addition actually represents a new class of API for plugins. You can call the function anywhere and it just returns the value you're looking for – no update() stuff or Events needed!

We used to have a couple of things like this but moved to the update() and event-bus because we ran into some awful deadlocks. I think as long as these new "query functions" are non-blocking though, this should be fine.

Latest main should have the get_plugin_ids() query function that you need!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin system Enhancement or fixes related to plugin system plugin Issue related to plugins
Projects
None yet
Development

No branches or pull requests

3 participants