diff options
| author | Daniel Jankowski <daniel.jankowski@rub.de> | 2024-10-05 17:19:41 +0200 |
|---|---|---|
| committer | Daniel Jankowski <daniel.jankowski@rub.de> | 2024-10-05 17:19:41 +0200 |
| commit | 6d13e481aceacd3efe583fb6c442f30e8909f555 (patch) | |
| tree | 6dd791834a35a4977bc6ce96a70fa589b805c990 /src | |
| parent | chore: update cargo deps (diff) | |
| download | sl0pstatus-6d13e481aceacd3efe583fb6c442f30e8909f555.tar.gz sl0pstatus-6d13e481aceacd3efe583fb6c442f30e8909f555.tar.xz sl0pstatus-6d13e481aceacd3efe583fb6c442f30e8909f555.zip | |
feat: hide frames except on search
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/zjstatus.rs | 36 | ||||
| -rw-r--r-- | src/config.rs | 6 | ||||
| -rw-r--r-- | src/frames.rs | 49 |
3 files changed, 66 insertions, 25 deletions
diff --git a/src/bin/zjstatus.rs b/src/bin/zjstatus.rs index ed7feb6..3ef57cc 100644 --- a/src/bin/zjstatus.rs +++ b/src/bin/zjstatus.rs @@ -199,14 +199,14 @@ impl State { tracing::Span::current().record("event_type", "Event::PaneUpdate"); tracing::debug!(pane_count = ?pane_info.panes.len()); - if self.module_config.hide_frame_for_single_pane { - frames::hide_frames_on_single_pane( - self.state.tabs.clone(), - &pane_info, - &self.state.mode, - get_plugin_ids(), - ); - } + frames::hide_frames_conditionally( + self.module_config.hide_frame_for_single_pane, + self.module_config.hide_frame_except_for_search, + &self.state.tabs, + &pane_info, + &self.state.mode, + get_plugin_ids(), + ); self.state.panes = pane_info; self.state.cache_mask = UpdateEventMask::Tab as u8; @@ -254,17 +254,17 @@ impl State { Event::SessionUpdate(session_info, _) => { tracing::Span::current().record("event_type", "Event::SessionUpdate"); - if self.module_config.hide_frame_for_single_pane { - let current_session = session_info.iter().find(|s| s.is_current_session); + let current_session = session_info.iter().find(|s| s.is_current_session); - if let Some(current_session) = current_session { - frames::hide_frames_on_single_pane( - current_session.clone().tabs, - ¤t_session.panes, - &self.state.mode, - get_plugin_ids(), - ); - } + if let Some(current_session) = current_session { + frames::hide_frames_conditionally( + self.module_config.hide_frame_for_single_pane, + self.module_config.hide_frame_except_for_search, + ¤t_session.tabs, + ¤t_session.panes, + &self.state.mode, + get_plugin_ids(), + ); } self.state.sessions = session_info; diff --git a/src/config.rs b/src/config.rs index 1e51ceb..c13328c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -77,6 +77,7 @@ pub struct ModuleConfig { pub right_parts: Vec<FormattedPart>, pub format_space: FormattedPart, pub hide_frame_for_single_pane: bool, + pub hide_frame_except_for_search: bool, pub border: BorderConfig, pub format_precedence: Vec<Part>, pub hide_on_overlength: bool, @@ -93,6 +94,10 @@ impl ModuleConfig { Some(toggle) => toggle == "true", None => false, }; + let hide_frame_except_for_search = match config.get("hide_frame_except_for_search") { + Some(toggle) => toggle == "true", + None => false, + }; let left_parts_config = match config.get("format_left") { Some(conf) => conf, @@ -142,6 +147,7 @@ impl ModuleConfig { right_parts: parts_from_config(Some(&right_parts_config.to_owned()), config), format_space: FormattedPart::from_format_string(format_space_config, config), hide_frame_for_single_pane, + hide_frame_except_for_search, border: border_config, format_precedence, hide_on_overlength, diff --git a/src/frames.rs b/src/frames.rs index 7954755..40e8caf 100644 --- a/src/frames.rs +++ b/src/frames.rs @@ -1,13 +1,15 @@ use zellij_tile::prelude::*; #[tracing::instrument(skip_all)] -pub fn hide_frames_on_single_pane( - tabs: Vec<TabInfo>, +pub fn hide_frames_conditionally( + cfg_hide_frames_for_single_pane: bool, + cfg_hide_frames_except_for_search: bool, + tabs: &[TabInfo], pane_info: &PaneManifest, mode_info: &ModeInfo, plugin_pane_id: PluginIds, ) { - let panes = match get_current_panes(&tabs, pane_info) { + let panes = match get_current_panes(tabs, pane_info) { Some(panes) => panes, None => return, }; @@ -19,23 +21,54 @@ pub fn hide_frames_on_single_pane( return; } - tracing::debug!("panes {:?}", panes); - let panes: Vec<&PaneInfo> = panes .iter() .filter(|p| !p.is_plugin && !p.is_floating) .collect(); - // frame is enabled, when content does no start at [0, 0]. With default frames - // it's [1, 1] let frame_enabled = panes.iter().any(|p| p.pane_content_x - p.pane_x > 0); + if cfg_hide_frames_except_for_search { + hide_frames_except_for_search(frame_enabled, mode_info); + + return; + } + + if cfg_hide_frames_for_single_pane { + hide_frames_on_single_pane(frame_enabled, mode_info, panes); + } +} + +pub fn hide_frames_except_for_search(frame_enabled: bool, mode_info: &ModeInfo) { + match mode_info.mode { + InputMode::EnterSearch => { + if !frame_enabled { + tracing::debug!("toggle cause search"); + toggle_pane_frames(); + } + } + _ => { + if frame_enabled { + tracing::debug!("toggle cause not search"); + toggle_pane_frames(); + } + } + } +} + +#[tracing::instrument(skip_all)] +pub fn hide_frames_on_single_pane( + frame_enabled: bool, + mode_info: &ModeInfo, + panes: Vec<&PaneInfo>, +) { tracing::debug!("mode: {:?}", mode_info.mode); if mode_info.mode == InputMode::RenamePane || mode_info.mode == InputMode::Search || mode_info.mode == InputMode::EnterSearch { if !frame_enabled { + tracing::debug!("toggle cause of mode"); toggle_pane_frames(); } @@ -43,10 +76,12 @@ pub fn hide_frames_on_single_pane( } if panes.len() == 1 && frame_enabled { + tracing::debug!("toggle enabled"); toggle_pane_frames(); } if panes.len() > 1 && !frame_enabled { + tracing::debug!("toggle not enabled"); toggle_pane_frames(); } } |
