cristiand391 / zj-status-bar

Compact status-bar plugin for zellij
MIT License
18 stars 0 forks source link

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

Closed cristiand391 closed 3 months ago

cristiand391 commented 4 months ago

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.

cristiand391 commented 4 months ago

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.

cristiand391 commented 3 months ago

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 commented 3 months ago

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: