Skip to content

Commit

Permalink
feat: color blank space with config
Browse files Browse the repository at this point in the history
  • Loading branch information
dj95 committed Sep 1, 2023
1 parent 6a3aedc commit f90cabf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ layout {
plugin location="file:target/wasm32-wasi/debug/zjstatus.wasm" {
format_left "{mode} #[fg=#89B4FA,bold]{session} {tabs}"
format_right "{datetime}"
format_space ""
mode_normal "#[bg=#89B4FA] "
mode_tmux "#[bg=#ffc387] "
Expand All @@ -53,6 +54,7 @@ layout {

In order to start using zjstatus you need to specify the widgets you'd like to use under the `format_left` and/or `format_right`
configuration. Formatting can be done with `#[..]`, while widgets and properties are surrounded by `{..}`.
The blank space between the left and the right part can be colored with `format_space`.

### 🎨 Formatting and theming

Expand Down
1 change: 1 addition & 0 deletions plugin-dev-workspace.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ layout {
plugin location="file:target/wasm32-wasi/debug/zjstatus.wasm" {
format_left "{mode} #[fg=#89B4FA,bold]{session} {tabs}"
format_right "{datetime}"
format_space "#[bg=#181825]"

mode_normal "#[bg=#89B4FA] "
mode_tmux "#[bg=#ffc387] "
Expand Down
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use ansi_term::{Colour, Colour::Fixed, Colour::RGB};
pub struct ModuleConfig {
pub left_parts: Vec<FormattedPart>,
pub right_parts: Vec<FormattedPart>,
pub format_space: FormattedPart,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -86,9 +87,15 @@ impl Default for FormattedPart {
}

pub fn parse_format(config: BTreeMap<String, String>) -> ModuleConfig {
let mut format_space_config = "";
if let Some(space_config) = config.get("format_space") {
format_space_config = space_config;
}

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()),
}
}

Expand Down
23 changes: 19 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use widgets::{datetime::DateTimeWidget, mode::ModeWidget, tabs::TabsWidget, widget::Widget, session::SessionWidget};
use widgets::{
datetime::DateTimeWidget, mode::ModeWidget, session::SessionWidget, tabs::TabsWidget,
widget::Widget,
};
use zellij_tile::prelude::*;

use std::{collections::BTreeMap, sync::Arc, u8, usize};
Expand Down Expand Up @@ -35,7 +38,11 @@ impl ZellijPlugin for State {
PermissionType::ReadApplicationState,
PermissionType::RunCommands,
]);
subscribe(&[EventType::ModeUpdate, EventType::TabUpdate, EventType::SessionUpdate]);
subscribe(&[
EventType::ModeUpdate,
EventType::TabUpdate,
EventType::SessionUpdate,
]);

self.module_config = config::parse_format(configuration.clone());
self.widget_map = register_widgets(configuration);
Expand Down Expand Up @@ -96,7 +103,12 @@ impl ZellijPlugin for State {
space_count -= text_count;
}

print!("{}{}{}", output_left, " ".repeat(space_count), output_right);
let spaces = render::formatting(
self.module_config.format_space.clone(),
" ".repeat(space_count),
);

print!("{}{}{}", output_left, spaces, output_right);
}
}

Expand All @@ -111,7 +123,10 @@ fn register_widgets(configuration: BTreeMap<String, String>) -> BTreeMap<String,
"mode".to_string(),
Arc::new(ModeWidget::new(configuration.clone())),
);
widget_map.insert("session".to_string(), Arc::new(SessionWidget::new(configuration.clone())));
widget_map.insert(
"session".to_string(),
Arc::new(SessionWidget::new(configuration.clone())),
);
widget_map.insert("tabs".to_string(), Arc::new(TabsWidget::new(configuration)));

widget_map
Expand Down

0 comments on commit f90cabf

Please sign in to comment.