Skip to content

Commit

Permalink
feat(plugins): plugin pane state events (#2545)
Browse files Browse the repository at this point in the history
* feat(plugins): report pane state to plugins

* refactor(plugins): rename some stuff

* tests(plugins): adjust for new behavior

* style(fmt): rustfmt
  • Loading branch information
imsnif authored Jun 15, 2023
1 parent 8d6f20c commit bcbd940
Show file tree
Hide file tree
Showing 12 changed files with 313 additions and 952 deletions.
6 changes: 6 additions & 0 deletions zellij-server/src/panes/active_panes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,10 @@ impl ActivePanes {
}
}
}
pub fn pane_id_is_focused(&self, pane_id: &PaneId) -> bool {
self.active_panes
.values()
.find(|p_id| **p_id == *pane_id)
.is_some()
}
}
17 changes: 15 additions & 2 deletions zellij-server/src/panes/floating_panes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
mod floating_pane_grid;
use zellij_utils::{
data::{Direction, ResizeStrategy},
data::{Direction, PaneInfo, ResizeStrategy},
position::Position,
};

use crate::resize_pty;
use crate::tab::Pane;
use crate::tab::{pane_info_for_pane, Pane};
use floating_pane_grid::FloatingPaneGrid;

use crate::{
Expand Down Expand Up @@ -885,4 +885,17 @@ impl FloatingPanes {
Err(anyhow!("Pane not found"))
}
}
pub fn pane_info(&self) -> Vec<PaneInfo> {
let mut pane_infos = vec![];
for (pane_id, pane) in self.panes.iter() {
let mut pane_info_for_pane = pane_info_for_pane(pane_id, pane);
let is_focused = self.active_panes.pane_id_is_focused(pane_id);
pane_info_for_pane.is_floating = true;
pane_info_for_pane.is_suppressed = false;
pane_info_for_pane.is_focused = is_focused;
pane_info_for_pane.is_fullscreen = false;
pane_infos.push(pane_info_for_pane);
}
pane_infos
}
}
7 changes: 7 additions & 0 deletions zellij-server/src/panes/plugin_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,13 @@ impl Pane for PluginPane {
self.loading_indication.to_string().as_bytes().to_vec(),
);
}
fn current_title(&self) -> String {
if self.pane_name.is_empty() {
self.pane_title.to_owned()
} else {
self.pane_name.to_owned()
}
}
}

impl PluginPane {
Expand Down
25 changes: 25 additions & 0 deletions zellij-server/src/panes/terminal_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,31 @@ impl Pane for TerminalPane {
fn set_title(&mut self, title: String) {
self.pane_title = title;
}
fn current_title(&self) -> String {
if self.pane_name.is_empty() {
self.grid
.title
.as_deref()
.unwrap_or(&self.pane_title)
.into()
} else {
self.pane_name.to_owned()
}
}
fn exit_status(&self) -> Option<i32> {
self.is_held
.as_ref()
.and_then(|(exit_status, _, _)| *exit_status)
}
fn is_held(&self) -> bool {
self.is_held.is_some()
}
fn exited(&self) -> bool {
match self.is_held {
Some((_, is_first_run, _)) => !is_first_run,
None => false,
}
}
}

impl TerminalPane {
Expand Down
17 changes: 15 additions & 2 deletions zellij-server/src/panes/tiled_panes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ use crate::{
output::Output,
panes::{ActivePanes, PaneId},
plugins::PluginInstruction,
tab::{Pane, MIN_TERMINAL_HEIGHT, MIN_TERMINAL_WIDTH},
tab::{pane_info_for_pane, Pane, MIN_TERMINAL_HEIGHT, MIN_TERMINAL_WIDTH},
thread_bus::ThreadSenders,
ui::boundaries::Boundaries,
ui::pane_contents_and_ui::PaneContentsAndUi,
ClientId,
};
use stacked_panes::StackedPanes;
use zellij_utils::{
data::{Direction, ModeInfo, ResizeStrategy, Style},
data::{Direction, ModeInfo, PaneInfo, ResizeStrategy, Style},
errors::prelude::*,
input::{
command::RunCommand,
Expand Down Expand Up @@ -1709,6 +1709,19 @@ impl TiledPanes {
.find(|(_id, s_p)| s_p.invoked_with() == &run)
.map(|(id, _)| *id)
}
pub fn pane_info(&self) -> Vec<PaneInfo> {
let mut pane_infos = vec![];
for (pane_id, pane) in self.panes.iter() {
let mut pane_info_for_pane = pane_info_for_pane(pane_id, pane);
let is_focused = self.active_panes.pane_id_is_focused(pane_id);
pane_info_for_pane.is_floating = false;
pane_info_for_pane.is_suppressed = false;
pane_info_for_pane.is_focused = is_focused;
pane_info_for_pane.is_fullscreen = is_focused && self.fullscreen_is_active();
pane_infos.push(pane_info_for_pane);
}
pane_infos
}
}

#[allow(clippy::borrowed_box)]
Expand Down
Loading

0 comments on commit bcbd940

Please sign in to comment.