Skip to content

Commit

Permalink
feat: toggle hide format overlength
Browse files Browse the repository at this point in the history
  • Loading branch information
dj95 committed May 31, 2024
1 parent 725c3de commit ec98a29
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
11 changes: 6 additions & 5 deletions plugin-dev-workspace.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ layout {

pane size=2 borderless=true {
plugin location="file:target/wasm32-wasi/debug/zjstatus.wasm" {
format_left "{mode}#[fg=#89B4FA,bg=#181825,bold] {session} {tabs}"
format_center "{command_0} {command_1} {command_git_branch} {command_3}"
format_right "{tabs}{notifications}{swap_layout}{datetime}"
format_space "#[bg=#181825]"
format_precedence "lrc"
format_left "{mode}#[fg=#89B4FA,bg=#181825,bold] {session} {tabs}"
format_center "{command_0} {command_1} {command_git_branch} {command_3}"
format_right "{tabs}{notifications}{swap_layout}{datetime}"
format_space "#[bg=#181825]"
format_precedence "lrc"
format_hide_on_overlength "false"

notification_format_unread "#[fg=#89B4FA,bg=#181825,blink]  #[fg=#89B4FA,bg=#181825] {message} "
notification_format_no_notifications "#[fg=#89B4FA,bg=#181825,dim]  "
Expand Down
19 changes: 15 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub struct ModuleConfig {
pub hide_frame_for_single_pane: bool,
pub border: BorderConfig,
pub format_precedence: Vec<Part>,
pub hide_on_overlength: bool,
}

impl ModuleConfig {
Expand Down Expand Up @@ -125,6 +126,11 @@ impl ModuleConfig {
None => vec![Part::Left, Part::Center, Part::Right],
};

let hide_on_overlength = match config.get("format_hide_on_overlength") {
Some(opt) => opt == "true",
None => false,
};

let border_config = match parse_border_config(config.clone()) {
Some(bc) => bc,
None => BorderConfig::default(),
Expand All @@ -141,6 +147,7 @@ impl ModuleConfig {
hide_frame_for_single_pane,
border: border_config,
format_precedence,
hide_on_overlength,
})
}

Expand Down Expand Up @@ -189,8 +196,10 @@ impl ModuleConfig {
)
});

let (output_left, output_center, output_right) =
self.trim_output(&output_left, &output_center, &output_right, state.cols);
let (output_left, output_center, output_right) = match self.hide_on_overlength {
true => self.trim_output(&output_left, &output_center, &output_right, state.cols),
false => (output_left, output_center, output_right),
};

let mut offset = console::measure_text_width(&output_left);

Expand Down Expand Up @@ -318,8 +327,10 @@ impl ModuleConfig {
)
});

let (output_left, output_center, output_right) =
self.trim_output(&output_left, &output_center, &output_right, state.cols);
let (output_left, output_center, output_right) = match self.hide_on_overlength {
true => self.trim_output(&output_left, &output_center, &output_right, state.cols),
false => (output_left, output_center, output_right),
};

if self.border.enabled {
let mut border_top = "".to_owned();
Expand Down

0 comments on commit ec98a29

Please sign in to comment.