Skip to content

Commit

Permalink
feat(frames): hide frame except for scroll
Browse files Browse the repository at this point in the history
fixes #116
  • Loading branch information
dj95 committed Jan 18, 2025
1 parent 78013c5 commit 94e6099
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/bin/zjframes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct State {
hide_frame_for_single_pane: bool,
hide_frame_except_for_search: bool,
hide_frame_except_for_fullscreen: bool,
hide_frame_except_for_scroll: bool,

err: Option<anyhow::Error>,
}
Expand Down Expand Up @@ -79,6 +80,11 @@ impl ZellijPlugin for State {
Some(toggle) => toggle == "true",
None => false,
};
self.hide_frame_except_for_scroll=
match configuration.get("hide_frame_except_for_scroll") {
Some(toggle) => toggle == "true",
None => false,
};

self.pending_events = Vec::new();
self.got_permissions = false;
Expand Down Expand Up @@ -140,6 +146,7 @@ impl State {
self.hide_frame_for_single_pane,
self.hide_frame_except_for_search,
self.hide_frame_except_for_fullscreen,
self.hide_frame_except_for_scroll,
),
&self.state.tabs,
&self.state.panes,
Expand All @@ -159,6 +166,7 @@ impl State {
self.hide_frame_for_single_pane,
self.hide_frame_except_for_search,
self.hide_frame_except_for_fullscreen,
self.hide_frame_except_for_scroll,
),
&self.state.tabs,
&self.state.panes,
Expand All @@ -184,6 +192,7 @@ impl State {
self.hide_frame_for_single_pane,
self.hide_frame_except_for_search,
self.hide_frame_except_for_fullscreen,
self.hide_frame_except_for_scroll,
),
&current_session.tabs,
&current_session.panes,
Expand Down
2 changes: 2 additions & 0 deletions src/bin/zjstatus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ impl State {
self.module_config.hide_frame_for_single_pane,
self.module_config.hide_frame_except_for_search,
self.module_config.hide_frame_except_for_fullscreen,
self.module_config.hide_frame_except_for_scroll,
),
&self.state.tabs,
&pane_info,
Expand Down Expand Up @@ -269,6 +270,7 @@ impl State {
self.module_config.hide_frame_for_single_pane,
self.module_config.hide_frame_except_for_search,
self.module_config.hide_frame_except_for_fullscreen,
self.module_config.hide_frame_except_for_scroll,
),
&current_session.tabs,
&current_session.panes,
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub struct ModuleConfig {
pub hide_frame_for_single_pane: bool,
pub hide_frame_except_for_search: bool,
pub hide_frame_except_for_fullscreen: bool,
pub hide_frame_except_for_scroll: bool,
pub border: BorderConfig,
pub format_precedence: Vec<Part>,
pub hide_on_overlength: bool,
Expand All @@ -105,6 +106,10 @@ impl ModuleConfig {
Some(toggle) => toggle == "true",
None => false,
};
let hide_frame_except_for_scroll = match config.get("hide_frame_except_for_scroll") {
Some(toggle) => toggle == "true",
None => false,
};

let left_parts_config = match config.get("format_left") {
Some(conf) => conf,
Expand Down Expand Up @@ -156,6 +161,7 @@ impl ModuleConfig {
hide_frame_for_single_pane,
hide_frame_except_for_search,
hide_frame_except_for_fullscreen,
hide_frame_except_for_scroll,
border: border_config,
format_precedence,
hide_on_overlength,
Expand Down
21 changes: 19 additions & 2 deletions src/frames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@ pub struct FrameConfig {
pub hide_frames_for_single_pane: bool,
pub hide_frames_except_for_search: bool,
pub hide_frames_except_for_fullscreen: bool,
pub hide_frames_except_for_scroll: bool,
}

impl FrameConfig {
pub fn new(
hide_frames_for_single_pane: bool,
hide_frames_except_for_search: bool,
hide_frames_except_for_fullscreen: bool,
hide_frames_except_for_scroll: bool,
) -> Self {
Self {
hide_frames_for_single_pane,
hide_frames_except_for_search,
hide_frames_except_for_fullscreen,
hide_frames_except_for_scroll,
}
}

pub fn is_disabled(&self) -> bool {
!self.hide_frames_for_single_pane
&& !self.hide_frames_except_for_search
&& !self.hide_frames_except_for_fullscreen
&& !self.hide_frames_except_for_scroll
}
}

Expand Down Expand Up @@ -67,16 +71,29 @@ pub fn hide_frames_conditionally(
config.hide_frames_except_for_fullscreen && should_show_frames_for_fullscreen(&panes);
let frames_for_single_pane = config.hide_frames_for_single_pane
&& should_show_frames_for_multiple_panes(mode_info, &panes);
let frames_for_scroll =
config.hide_frames_except_for_scroll && should_show_frames_for_scroll(mode_info);

if (frames_for_search || frames_for_fullscreen || frames_for_single_pane) && !frame_enabled {
if (frames_for_search || frames_for_fullscreen || frames_for_single_pane || frames_for_scroll)
&& !frame_enabled
{
toggle_pane_frames();
}

if (!frames_for_search && !frames_for_fullscreen && !frames_for_single_pane) && frame_enabled {
if (!frames_for_search
&& !frames_for_fullscreen
&& !frames_for_single_pane
&& !frames_for_scroll)
&& frame_enabled
{
toggle_pane_frames();
}
}

pub fn should_show_frames_for_scroll(mode_info: &ModeInfo) -> bool {
mode_info.mode == InputMode::Scroll
}

pub fn should_show_frames_for_search(mode_info: &ModeInfo) -> bool {
mode_info.mode == InputMode::EnterSearch || mode_info.mode == InputMode::Search
}
Expand Down
6 changes: 3 additions & 3 deletions tests/zjstatus/layout.kdl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
layout {
pane split_direction="vertical" {
pane borderless=true
pane command="nvim"
pane
}

pane size=2 borderless=true {
Expand Down Expand Up @@ -31,9 +30,10 @@ layout {
swap_layout_format "#[bg=blue,fg=#000000] {name} #[bg=red,fg=black] foo "
swap_layout_hide_if_empty "false"

hide_frame_for_single_pane "true"
hide_frame_for_single_pane "false"
hide_frame_except_for_search "false"
hide_frame_except_for_fullscreen "false"
hide_frame_except_for_scroll "true"

mode_normal "#[bg=$blue] #[bg=yellow] "
mode_tmux "#[bg=$yellow] "
Expand Down

0 comments on commit 94e6099

Please sign in to comment.