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

[Request] Display session name in Zellij #573

Closed
techhazard opened this issue Jun 10, 2021 · 8 comments · Fixed by #608
Closed

[Request] Display session name in Zellij #573

techhazard opened this issue Jun 10, 2021 · 8 comments · Fixed by #608
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@techhazard
Copy link

I usually have at least two sessions open for Zellij; 1 for work (Work), and 1 for personal things (Personal). Sometimes I open other sessions for specific projects.

I'd like to be able to view the name of the session somewhere in Zellij, instead of having to do env | grep -i zellij.
Perhaps in the top-left, which currently reads "Zellij", or the top right.
Or perhaps somewhere in the bottom bar, just like in Tmux.

I know I can have a different theme for each session, and I'm looking into that, but I like to be able to read the name as well.

Would this be possible?

@imsnif
Copy link
Member

imsnif commented Jun 10, 2021

Definitely possible! I'd go for top left, something like Zellij (session-name)

Shouldn't be too hard to implement, if you or anyone else wants to give it a go?

@imsnif imsnif added help wanted Extra attention is needed good first issue Good for newcomers labels Jun 10, 2021
@techhazard
Copy link
Author

I'll give it a go, but if somebody is faster that's fine with me 🙂

@imsnif
Copy link
Member

imsnif commented Jun 10, 2021

Awesome. Feel free to reach out here or on our discord if you want help/guidance.

@techhazard
Copy link
Author

techhazard commented Jun 14, 2021

I tried to get the session name in default-plugins/tab-bar by using std::env::var. Because in zellij-client/src/lib.rs I saw std::env::set_var being used.

But that does not work, because it is not being set. is it because plugins are WASM and are run as separate binaries (and therefor with a different environment?).
I can't seem to find where the plugins are being called/started. Where is this located?

@imsnif
Copy link
Member

imsnif commented Jun 14, 2021

Yeah, I think we don't share the environment variables with the plugins. We use exported WASM functions to communicate with them, and IMO that's the best way to go with this.

Atm we don't send the plugins any info on startup and rather have them subscribe to events that we send them every time there's been a change (correct me if I'm wrong @TheLostLambda ?). A good example can be seen with the tabs that subscribe to events here: https://github.com/zellij-org/zellij/blob/main/default-plugins/tab-bar/src/main.rs#L30

And these events are defined here:

pub enum Event {
ModeUpdate(ModeInfo),
TabUpdate(Vec<TabInfo>),
KeyPress(Key),
Timer(f64),
}

So I think if you add an event (something like SessionNameUpdate maybe?) and mimic the behaviour of the 'TabUpdate` event, it should do the trick. Makes sense?

@TheLostLambda
Copy link
Member

Heya! Figured I'd jump in here! There is actually an easier way to go about this, I think! The ModeUpdate event is guaranteed to be sent to every plugin at load time at least once, so I think the best way to go about this would be to add a String containing the session name to ModeInfo. Then it will be passed to the plugin on load!

Normally @imsnif is right about how we communicate with plugins, but the ModeInfo has the special status of an "initialization event" as well as its usual role. Adding a field to ModeInfo also avoids creating anything like SessionNameUpdate which is a touch misleading since I don't think the session name changes during runtime? I could be wrong about that though.

@imsnif
Copy link
Member

imsnif commented Jun 14, 2021

Normally @imsnif is right about how we communicate with plugins, but the ModeInfo has the special status of an "initialization event" as well as its usual role. Adding a field to ModeInfo also avoids creating anything like SessionNameUpdate which is a touch misleading since I don't think the session name changes during runtime? I could be wrong about that though.

I think it might be nice to allow changing the session name at runtime at some point - but for now it indeed doesn't change. Thanks for the suggestion! Could you point out a good place for @techhazard to get started on this?

@TheLostLambda
Copy link
Member

ModeUpdate can also accommodate for changes at runtime so we should be able to eventually handle that change :)

As for where to start, I'd point @techhazard to:

pub struct ModeInfo {
pub mode: InputMode,
// FIXME: This should probably return Keys and Actions, then sort out strings plugin-side
pub keybinds: Vec<(String, String)>, // <shortcut> => <shortcut description>
pub palette: Palette,
pub capabilities: PluginCapabilities,
}

Personally, I'd add a field like session_name: String, then follow the compiler errors to find all of the places ModeInfo is constructed or consumed!

Putting things in the top-left would then mean using the ModeInfo saved in the tab-bar on this line:

Event::ModeUpdate(mode_info) => self.mode_info = mode_info,

Eventually (I think) you'll want to pass the session name into this function:

You should be able to render it from within there? Good luck and let me know if you run into any issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants