Skip to content

Commit

Permalink
chore: refactor border rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
dj95 committed Oct 25, 2023
1 parent cb4ab30 commit 17d76ba
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zjstatus"
version = "0.7.0"
version = "0.8.0"
authors = ["Daniel Jankowski"]
edition = "2018"

Expand Down
15 changes: 2 additions & 13 deletions src/border.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,8 @@ impl Default for BorderConfig {
}

impl BorderConfig {
pub fn draw_if_enabled(&self, cols: usize) {
if !self.enabled {
return;
}

let output = self.char.repeat(cols);

let mut newline = "";
if self.position == BorderPosition::Top {
newline = "\n";
}

print!("{}{}", self.format.format_string(output), newline);
pub fn draw(&self, cols: usize) -> String {
self.format.format_string(self.char.repeat(cols))
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,23 @@ impl ModuleConfig {
);
}

let mut newline = "";
let mut border_top = "".to_string();
if self.border.enabled && self.border.position == BorderPosition::Top {
border_top = format!("{}\n", self.border.draw(state.cols));
}

let mut border_bottom = "".to_string();
if self.border.enabled && self.border.position == BorderPosition::Bottom {
newline = "\n";
border_bottom = format!("\n{}", self.border.draw(state.cols));
}

print!(
"{}{}{}{}",
"{}{}{}{}{}",
border_top,
output_left,
self.get_spacer(output_left.clone(), output_right.clone(), state.cols),
output_right,
newline,
border_bottom,
);
}

Expand Down
9 changes: 0 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use border::BorderPosition;
use config::ModuleConfig;
use widgets::{
datetime::DateTimeWidget, mode::ModeWidget, session::SessionWidget,
Expand Down Expand Up @@ -121,16 +120,8 @@ impl ZellijPlugin for State {
fn render(&mut self, _rows: usize, cols: usize) {
self.state.cols = cols;

if self.module_config.border.position == BorderPosition::Top {
self.module_config.border.draw_if_enabled(cols);
}

self.module_config
.render_bar(self.state.clone(), self.widget_map.clone());

if self.module_config.border.position == BorderPosition::Bottom {
self.module_config.border.draw_if_enabled(cols);
}
}
}

Expand Down

0 comments on commit 17d76ba

Please sign in to comment.