Skip to content

Commit

Permalink
feat: tab alerts (#4)
Browse files Browse the repository at this point in the history
PR: #4

* feat(POC): initial support for tab notifications

* refactor: use pipe args + take exit code

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`

* feat: broadcast state to all instances of `zj-status-bar`

broadcast internal state so that new instances "catch up" on alerts already sent.

* chore: refactor

* chore: mutate values in place, avoid cloning state

* chore: refactor

* chore: update pipe msg names

* fix: handle pipe args parse panics

* fix: avoid infinite re-render b/c of timers

* chore: clippy

* Update README.md

* Update README.md
  • Loading branch information
cristiand391 authored Jun 8, 2024
1 parent 5048c3c commit 81a0d4b
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 35 deletions.
71 changes: 42 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ license = "MIT"
[dependencies]
ansi_term = "0.12"
unicode-width = "0.1.8"
zellij-tile = "0.39.2"
zellij-tile-utils = "0.39.2"
zellij-tile = "0.40.0"
zellij-tile-utils = "0.40.0"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ An opinionated status bar plugin for [`zellij`](https://zellij.dev/) based on th
### Features
* Pane fullscreen indicator
* Tab indexes
* [Tab alerts](#tab-alerts)

### Others
* No alternate tab colors
Expand Down Expand Up @@ -44,6 +45,31 @@ On the first load you need to navigate to the plugin pane and press `y` to accep
> If you start the plugin pane with [`borderless`](https://zellij.dev/documentation/creating-a-layout#borderless) set to true you won't be able to view it and accept the perms.
> After accepting permissions you can disable borders again.
## Tab alerts

Always keep an eye on long-running processes, even if they are on different tabs!

[tab-alerts-demo.webm](https://github.com/cristiand391/zj-status-bar/assets/6853656/953d7abf-3011-48d4-ad38-f45c96c3583a)

When running commands via `zw` you'll get a green/red alert (based on the exit code > 0) on the tab section when you are on a different tab.
The alerts are rendered every 1s and are cleared once you focus on that tab.

Add the `zw` helper to your shell setup:

zsh/bash:
```zsh
zw() {
eval "$*"
zellij pipe --name zj-status-bar:cli:tab_alert --args "pane_id=$ZELLIJ_PANE_ID,exit_code=$?"
}
```

then pass it the command you want to watch
`zw cargo build`

> [!NOTE]
> If you want to chain multiple commands make sure to wrap them in quotes (e.g `zw 'sleep 3 && cargo build'`), otherwise your shell will interpret it as 2 different commands and you'll only get an alert about the first one.
## Development

1. Clone repo: `gh repo clone cristiand391/zj-status-bar`
Expand Down
8 changes: 6 additions & 2 deletions src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ fn tab_line_prefix(
})
}
let mode_part = format!("{:?}", mode).to_uppercase();
let mode_part_padded = format!("{:^mode_part_width$}", mode_part, mode_part_width = mode_part.width() + 2);
let mode_part_padded = format!(
"{:^mode_part_width$}",
mode_part,
mode_part_width = mode_part.width() + 2
);
let mode_part_len = mode_part_padded.width();
let mode_part_styled_text = if mode == InputMode::Locked {
style!(locked_mode_color, bg_color)
Expand Down Expand Up @@ -347,7 +351,7 @@ fn swap_layout_status(
"{}{}{}",
prefix_separator, swap_layout_name, suffix_separator
);
let (part, full_len) = (format!("{}", swap_layout_indicator), swap_layout_name_len);
let (part, full_len) = (swap_layout_indicator.to_string(), swap_layout_name_len);
let short_len = swap_layout_name_len + 1; // 1 is the space between
if full_len <= max_len {
Some(LinePart {
Expand Down
Loading

0 comments on commit 81a0d4b

Please sign in to comment.