Skip to content

Commit

Permalink
feat: add formats for swap layout
Browse files Browse the repository at this point in the history
  • Loading branch information
dj95 committed Apr 17, 2024
1 parent 582f585 commit 6207862
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
5 changes: 4 additions & 1 deletion plugin-dev-workspace.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ layout {
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 "{notifications}{datetime}"
format_right "{notifications}{swap_layout}{datetime}"
format_space "#[bg=#181825]"

notification_format_unread "#[fg=#89B4FA,bg=#181825,blink]  #[fg=#89B4FA,bg=#181825] {message} "
Expand All @@ -19,6 +19,9 @@ layout {
border_format "#[fg=#6C7086]{char}"
border_position "top"

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"

mode_normal "#[bg=blue] #[bg=yellow] "
Expand Down
47 changes: 43 additions & 4 deletions src/widgets/swap_layout.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
use std::collections::BTreeMap;
use zellij_tile::shim::next_swap_layout;

use crate::render::FormattedPart;
use crate::{config::ZellijState, widgets::widget::Widget};

pub struct SwapLayoutWidget {}
pub struct SwapLayoutWidget {
format: Vec<FormattedPart>,
hide_if_empty: bool,
}

impl SwapLayoutWidget {
pub fn new(_config: &BTreeMap<String, String>) -> Self {
Self {}
pub fn new(config: &BTreeMap<String, String>) -> Self {
let mut format: Vec<FormattedPart> = Vec::new();
if let Some(form) = config.get("swap_layout_format") {
format = FormattedPart::multiple_from_format_string(form);
}

let hide_if_empty = match config.get("swap_layout_hide_if_empty") {
Some(hide_if_empty) => hide_if_empty == "true",
None => false,
};

Self {
format,
hide_if_empty,
}
}
}

Expand All @@ -21,10 +38,32 @@ impl Widget for SwapLayoutWidget {

let active_tab = active_tab.unwrap();

match active_tab.active_swap_layout_name.clone() {
let name = match active_tab.active_swap_layout_name.clone() {
Some(n) => n,
None => "".to_owned(),
};

if name.is_empty() && self.hide_if_empty {
return "".to_owned();
}

if self.format.is_empty() {
return name;
}

let mut output = "".to_owned();

for f in &self.format {
let mut content = f.content.clone();

if content.contains("{name}") {
content = content.replace("{name}", &name);
}

output = format!("{}{}", output, f.format_string(&content));
}

output
}

fn process_click(&self, _state: &ZellijState, _pos: usize) {
Expand Down

0 comments on commit 6207862

Please sign in to comment.