aboutsummaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorDaniel Jankowski <daniel.jankowski@rub.de>2023-12-17 11:04:14 +0100
committerDaniel Jankowski <daniel.jankowski@rub.de>2023-12-17 11:04:14 +0100
commitf8f6c145149c327c022d58abcf558d6139fa2566 (patch)
tree2253071a6bad838726cdf7d3ab8fe2b2236da111 /src/widgets
parentchore: refactor config with more idiomatic rust (diff)
downloadsl0pstatus-f8f6c145149c327c022d58abcf558d6139fa2566.tar.gz
sl0pstatus-f8f6c145149c327c022d58abcf558d6139fa2566.tar.xz
sl0pstatus-f8f6c145149c327c022d58abcf558d6139fa2566.zip
chore: refactor mode with more idiomatic rust
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/mode.rs33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/widgets/mode.rs b/src/widgets/mode.rs
index e042765..957ad4f 100644
--- a/src/widgets/mode.rs
+++ b/src/widgets/mode.rs
@@ -26,10 +26,10 @@ pub struct ModeWidget {
impl ModeWidget {
pub fn new(config: BTreeMap<String, String>) -> Self {
- let mut normal_format = Vec::new();
- if let Some(form) = config.get("mode_normal") {
- normal_format = FormattedPart::multiple_from_format_string(form.to_string());
- }
+ let normal_format = match config.get("mode_normal") {
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ None => vec![],
+ };
let locked_format = match config.get("mode_locked") {
Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
@@ -117,19 +117,20 @@ impl ModeWidget {
impl Widget for ModeWidget {
fn process(&self, _name: &str, state: ZellijState) -> String {
- let formatters = self.select_format(state.mode.mode);
- let mut output = "".to_string();
-
- for f in formatters.iter() {
- let mut content = f.content.clone();
- if content.contains("{name}") {
- content = content.replace("{name}", format!("{:?}", state.mode.mode).as_str());
- }
-
- output = format!("{}{}", output, f.format_string(content));
- }
+ self.select_format(state.mode.mode)
+ .iter_mut()
+ .map(|f| {
+ if f.content.contains("{name}") {
+ f.content = f
+ .content
+ .replace("{name}", format!("{:?}", state.mode.mode).as_str());
+ }
- output
+ f
+ })
+ .fold("".to_string(), |acc, f| {
+ format!("{acc}{}", f.format_string(f.content.clone()))
+ })
}
fn process_click(&self, _state: ZellijState, _pos: usize) {}