aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Jankowski <daniel.jankowski@rub.de>2023-09-01 18:56:32 +0200
committerDaniel Jankowski <daniel.jankowski@rub.de>2023-09-01 18:56:32 +0200
commit4be32282f13378dc060d43bc8802402c9bfbc295 (patch)
tree67f7d0083a91413be6cb87ff1746fbe50f2f25ce /src
parentchore: fix README (diff)
downloadsl0pstatus-4be32282f13378dc060d43bc8802402c9bfbc295.tar.gz
sl0pstatus-4be32282f13378dc060d43bc8802402c9bfbc295.tar.xz
sl0pstatus-4be32282f13378dc060d43bc8802402c9bfbc295.zip
feat: add hide frame for single pane
Diffstat (limited to 'src')
-rw-r--r--src/config.rs7
-rw-r--r--src/frames.rs26
-rw-r--r--src/main.rs10
-rw-r--r--src/widgets/datetime.rs2
-rw-r--r--src/widgets/session.rs3
5 files changed, 45 insertions, 3 deletions
diff --git a/src/config.rs b/src/config.rs
index db4b443..73dd926 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -7,6 +7,7 @@ pub struct ModuleConfig {
pub left_parts: Vec<FormattedPart>,
pub right_parts: Vec<FormattedPart>,
pub format_space: FormattedPart,
+ pub hide_frame_for_single_pane: bool,
}
#[derive(Clone, Debug)]
@@ -92,10 +93,16 @@ pub fn parse_format(config: BTreeMap<String, String>) -> ModuleConfig {
format_space_config = space_config;
}
+ let mut hide_frame_for_single_pane = false;
+ if let Some(toggle) = config.get("hide_frame_for_single_pane") {
+ hide_frame_for_single_pane = toggle == "true";
+ }
+
ModuleConfig {
left_parts: parts_from_config(config.get("format_left")),
right_parts: parts_from_config(config.get("format_right")),
format_space: FormattedPart::from_format_string(format_space_config.to_string()),
+ hide_frame_for_single_pane,
}
}
diff --git a/src/frames.rs b/src/frames.rs
new file mode 100644
index 0000000..2a4f56f
--- /dev/null
+++ b/src/frames.rs
@@ -0,0 +1,26 @@
+use zellij_tile::prelude::*;
+
+pub fn hide_frames_on_single_pane(tabs: Vec<TabInfo>, pane_info: PaneManifest) {
+ let active_tab = tabs.into_iter().find(|t| t.active);
+ if active_tab.is_none() {
+ return;
+ }
+
+ let active_tab_id = active_tab.unwrap().position;
+
+ let panes = pane_info.panes.get(&active_tab_id);
+ if panes.is_none() {
+ return;
+ }
+
+ let panes = panes.unwrap();
+ let panes: Vec<&PaneInfo> = panes.iter().filter(|p| !p.is_plugin).collect();
+
+ if panes.len() == 1 && panes.first().unwrap().pane_content_x == 1 {
+ toggle_pane_frames();
+ }
+
+ if panes.len() > 1 && panes.first().unwrap().pane_content_x == 0 {
+ toggle_pane_frames();
+ }
+}
diff --git a/src/main.rs b/src/main.rs
index 43550e9..9fc7681 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,6 +7,7 @@ use zellij_tile::prelude::*;
use std::{collections::BTreeMap, sync::Arc, u8, usize};
mod config;
+mod frames;
mod render;
mod widgets;
@@ -34,10 +35,12 @@ impl ZellijPlugin for State {
// we need the RunCommands permission to run "cargo test" in a floating window
request_permission(&[
PermissionType::ReadApplicationState,
+ PermissionType::ChangeApplicationState,
PermissionType::RunCommands,
]);
subscribe(&[
EventType::ModeUpdate,
+ EventType::PaneUpdate,
EventType::TabUpdate,
EventType::SessionUpdate,
]);
@@ -69,6 +72,13 @@ impl ZellijPlugin for State {
self.state.mode = mode_info;
should_render = true;
}
+ Event::PaneUpdate(pane_info) => {
+ if self.module_config.hide_frame_for_single_pane {
+ frames::hide_frames_on_single_pane(self.state.tabs.clone(), pane_info);
+
+ should_render = true;
+ }
+ }
Event::SessionUpdate(session_info) => {
self.state.sessions = session_info;
should_render = true;
diff --git a/src/widgets/datetime.rs b/src/widgets/datetime.rs
index 4332caa..0813ac6 100644
--- a/src/widgets/datetime.rs
+++ b/src/widgets/datetime.rs
@@ -50,7 +50,7 @@ impl Widget for DateTimeWidget {
let date = Local::now();
let mut tz = Tz::UTC;
- if let Some(t) = self.time_zone.clone() {
+ if let Some(t) = self.time_zone {
tz = t;
}
diff --git a/src/widgets/session.rs b/src/widgets/session.rs
index 1849edc..55cca56 100644
--- a/src/widgets/session.rs
+++ b/src/widgets/session.rs
@@ -15,8 +15,7 @@ impl Widget for SessionWidget {
let session = state
.sessions
.into_iter()
- .filter(|s| s.is_current_session)
- .next();
+ .find(|s| s.is_current_session);
match session {
Some(s) => s.name,