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

feat(POC): initial support for tab notifications #2

Closed
wants to merge 11 commits into from

Conversation

cristiand391
Copy link
Owner

initial POC for tab notifications.

use-cases:

Notify finished processes on non-active tabs by start blinking on tab section.

I had this idea a few weeks ago when I had to run gh pr checks in watch mode in ~3 tabs at the morning, then forgot to check back for a few hours even when I had the tabs opened in the same session.

This POC uses zellij pipes to allow the status bar to receive data (currently the tab index, maybe it should accept exit status too?).
https://zellij.dev/documentation/plugin-pipes

demo

send tab index via zellij pipe, the plugin will keep these in a hashmap and use timers to trigger a re-render every 1s.
The tab section will keep blinking until you visit it, then it's cleared internally from the hashmap.

Screencast.from.05-01-2024.06.13.43.PM.webm

side-notes

Thinking about the end UX... having to append zellij pipe to every command pane isn't good. I use mostly zellij run --in-place to do this
https://zellij.dev/documentation/zellij-run

explored creating a 2nd plugin that creates spawns command panes in-place but these don't emit the RunCommandResult event:
https://zellij.dev/documentation/plugin-api-events#runcommandresult

once the status bar POC is done I'll either re-create command panes using run_command or append something to the command pane names to be able to find them programatically.

src/tab.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
@elythh elythh mentioned this pull request May 2, 2024
@cristiand391
Copy link
Owner Author

Notes after using it for a few days:

  1. as mentioned, having to chain zellij pipe ... to the command to watch is annoying, specially having to check which tab I'm in. This should be solved with the "command runner" plugin mentioned in the PR (WIP).

  2. new tabs miss current alerts (new plugin instances start fresh, don't know about these)
    I think this could be solved by having the plugin broadcast the alerts on each timer update.
    Need to settle on payload format before implementing this.

  3. add support for specifying success/failure (mostly for green/red background on a tab blink).
    also define a third color if multiple commands in a pane send alerts.

nice to have: only clear panes from internal state after the user focused on them.

panes should send a process status like this:

zellij pipe --name zj-status-bar:process_status --args "pane_id=$ZELLIJ_PANE_ID,exit_code=$?"

then the plugin will find the pane's tab using `pane_id`

tab background color will be green/red depending on `exit_code`
@cristiand391
Copy link
Owner Author

cristiand391 commented May 27, 2024

just pushed another refactor to use pipe args to send the process status...

Today I explored just subscribing to pane updates and find command panes by check if pane.exit_status was defined (like folks on discord suggested last month), it worked but I found one blocker:

by inserting panes that had exit_status into the state, each pane update would add them again and trigger all alerts.
Maybe this could be solved by adding some caching but I found it over-complicated this feature...

For now I think best way to use this (at least until the 2nd cmd-runner plugin is done) will be by appending this to each command:

zellij pipe --name zj-status-bar:process_status --args "pane_id=$ZELLIJ_PANE_ID,exit_code=$?"

now that the tab index isn't required to be passed this can be wrapped in a shell func like zellij's zri built-in funcs, so you would run someting like:

zw "gh pr checks --watch"

@cristiand391
Copy link
Owner Author

cristiand391 commented Jun 5, 2024

new tabs miss current alerts (new plugin instances start fresh, don't know about these)
I think this could be solved by having the plugin broadcast the alerts on each timer update.
Need to settle on payload format before implementing this.

Done ✅

final TODO:

  • update pipe msg names
  • docs + zw shell func helper
  • handle possible panics, there's a bunch of unwrap calls.

@cristiand391 cristiand391 deleted the tab-notifications branch June 8, 2024 03:11
@cristiand391 cristiand391 mentioned this pull request Jun 8, 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

Successfully merging this pull request may close these issues.

1 participant