aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Jankowski <daniel.jankowski@rub.de>2023-12-17 15:18:04 +0100
committerDaniel Jankowski <daniel.jankowski@rub.de>2023-12-17 15:18:04 +0100
commitffad61acab9fa3ec771a911de462fa686bea1d67 (patch)
treeabb2b9f437c9f3ba0997532eeb1fa2960f1f04e5 /src
parentchore: update cargo deps (diff)
downloadsl0pstatus-ffad61acab9fa3ec771a911de462fa686bea1d67.tar.gz
sl0pstatus-ffad61acab9fa3ec771a911de462fa686bea1d67.tar.xz
sl0pstatus-ffad61acab9fa3ec771a911de462fa686bea1d67.zip
chore: move from to_string to to_owned
Diffstat (limited to 'src')
-rw-r--r--src/bin/zjstatus.rs14
-rw-r--r--src/border.rs6
-rw-r--r--src/config.rs28
-rw-r--r--src/render.rs8
-rw-r--r--src/widgets/command.rs16
-rw-r--r--src/widgets/datetime.rs4
-rw-r--r--src/widgets/mode.rs30
-rw-r--r--src/widgets/session.rs4
-rw-r--r--src/widgets/swap_layout.rs4
-rw-r--r--src/widgets/tabs.rs20
10 files changed, 69 insertions, 65 deletions
diff --git a/src/bin/zjstatus.rs b/src/bin/zjstatus.rs
index 15b9d06..801c0cc 100644
--- a/src/bin/zjstatus.rs
+++ b/src/bin/zjstatus.rs
@@ -126,7 +126,7 @@ impl ZellijPlugin for State {
};
self.state.command_results.insert(
- name.to_string(),
+ name.to_owned(),
CommandResult {
exit_code,
stdout,
@@ -186,26 +186,26 @@ fn register_widgets(configuration: BTreeMap<String, String>) -> BTreeMap<String,
let mut widget_map = BTreeMap::<String, Arc<dyn Widget>>::new();
widget_map.insert(
- "command".to_string(),
+ "command".to_owned(),
Arc::new(CommandWidget::new(configuration.clone())),
);
widget_map.insert(
- "datetime".to_string(),
+ "datetime".to_owned(),
Arc::new(DateTimeWidget::new(configuration.clone())),
);
widget_map.insert(
- "swap_layout".to_string(),
+ "swap_layout".to_owned(),
Arc::new(SwapLayoutWidget::new(configuration.clone())),
);
widget_map.insert(
- "mode".to_string(),
+ "mode".to_owned(),
Arc::new(ModeWidget::new(configuration.clone())),
);
widget_map.insert(
- "session".to_string(),
+ "session".to_owned(),
Arc::new(SessionWidget::new(configuration.clone())),
);
- widget_map.insert("tabs".to_string(), Arc::new(TabsWidget::new(configuration)));
+ widget_map.insert("tabs".to_owned(), Arc::new(TabsWidget::new(configuration)));
widget_map
}
diff --git a/src/border.rs b/src/border.rs
index 3b2d612..e517b12 100644
--- a/src/border.rs
+++ b/src/border.rs
@@ -22,7 +22,7 @@ impl Default for BorderConfig {
fn default() -> Self {
Self {
enabled: false,
- char: DEFAULT_CHAR.to_string(),
+ char: DEFAULT_CHAR.to_owned(),
format: FormattedPart::default(),
position: BorderPosition::default(),
}
@@ -63,8 +63,8 @@ pub fn parse_border_config(config: BTreeMap<String, String>) -> Option<BorderCon
Some(BorderConfig {
enabled,
- char: char.to_string(),
- format: FormattedPart::from_format_string(format.to_string()),
+ char: char.to_owned(),
+ format: FormattedPart::from_format_string(format.to_owned()),
position,
})
}
diff --git a/src/config.rs b/src/config.rs
index 46f20fe..584898b 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -60,11 +60,11 @@ impl ModuleConfig {
};
Self {
- left_parts_config: left_parts_config.to_string(),
- left_parts: parts_from_config(Some(&left_parts_config.to_string())),
- right_parts_config: right_parts_config.to_string(),
- right_parts: parts_from_config(Some(&right_parts_config.to_string())),
- format_space: FormattedPart::from_format_string(format_space_config.to_string()),
+ left_parts_config: left_parts_config.to_owned(),
+ left_parts: parts_from_config(Some(&left_parts_config.to_owned())),
+ right_parts_config: right_parts_config.to_owned(),
+ right_parts: parts_from_config(Some(&right_parts_config.to_owned())),
+ format_space: FormattedPart::from_format_string(format_space_config.to_owned()),
hide_frame_for_single_pane,
border: border_config,
}
@@ -103,7 +103,7 @@ impl ModuleConfig {
return;
}
- let output_right = self.right_parts.iter().fold("".to_string(), |acc, part| {
+ let output_right = self.right_parts.iter().fold("".to_owned(), |acc, part| {
format!(
"{}{}",
acc,
@@ -147,7 +147,7 @@ impl ModuleConfig {
let widgets_regex = Regex::new("(\\{[a-z_]+\\})").unwrap();
for widget in widgets_regex.captures_iter(widget_string.as_str()) {
let match_name = widget.get(0).unwrap().as_str();
- if !tokens.contains(&match_name.to_string()) {
+ if !tokens.contains(&match_name.to_owned()) {
continue;
}
@@ -177,26 +177,26 @@ impl ModuleConfig {
}
pub fn render_bar(&self, state: ZellijState, widget_map: BTreeMap<String, Arc<dyn Widget>>) {
- let output_left = self.left_parts.iter().fold("".to_string(), |acc, part| {
+ let output_left = self.left_parts.iter().fold("".to_owned(), |acc, part| {
format!(
"{acc}{}",
part.format_string_with_widgets(&widget_map, &state)
)
});
- let output_right = self.right_parts.iter().fold("".to_string(), |acc, part| {
+ let output_right = self.right_parts.iter().fold("".to_owned(), |acc, part| {
format!(
"{acc}{}",
part.format_string_with_widgets(&widget_map, &state)
)
});
- let mut border_top = "".to_string();
+ let mut border_top = "".to_owned();
if self.border.enabled && self.border.position == BorderPosition::Top {
border_top = format!("{}\n", self.border.draw(state.cols));
}
- let mut border_bottom = "".to_string();
+ let mut border_bottom = "".to_owned();
if self.border.enabled && self.border.position == BorderPosition::Bottom {
border_bottom = format!("\n{}", self.border.draw(state.cols));
}
@@ -227,7 +227,7 @@ fn parts_from_config(format: Option<&String>) -> Vec<FormattedPart> {
match format {
Some(format) => format
.split("#[")
- .map(|f| FormattedPart::from_format_string(f.to_string()))
+ .map(|f| FormattedPart::from_format_string(f.to_owned()))
.collect(),
None => vec![],
}
@@ -242,7 +242,7 @@ mod test {
fn test_formatted_part_from_string() {
let input = "#[fg=#ff0000,bg=#00ff00,bold,italic]foo";
- let part = FormattedPart::from_format_string(input.to_string());
+ let part = FormattedPart::from_format_string(input.to_owned());
assert_eq!(
part,
@@ -251,7 +251,7 @@ mod test {
bg: Some(RgbColor(0, 255, 0).into()),
bold: true,
italic: true,
- content: "foo".to_string(),
+ content: "foo".to_owned(),
},
)
}
diff --git a/src/render.rs b/src/render.rs
index 370b01d..4c2c74f 100644
--- a/src/render.rs
+++ b/src/render.rs
@@ -24,13 +24,13 @@ impl FormattedPart {
pub fn multiple_from_format_string(config: String) -> Vec<Self> {
config
.split("#[")
- .map(|c| FormattedPart::from_format_string(c.to_string()))
+ .map(|c| FormattedPart::from_format_string(c.to_owned()))
.collect()
}
pub fn from_format_string(format: String) -> Self {
let format = match format.starts_with("#[") {
- true => format.strip_prefix("#[").unwrap().to_string(),
+ true => format.strip_prefix("#[").unwrap().to_owned(),
false => format,
};
@@ -114,7 +114,7 @@ impl FormattedPart {
match_name.trim_matches(|c| c == '{' || c == '}'),
state,
),
- None => "Use of uninitialized widget".to_string(),
+ None => "Use of uninitialized widget".to_owned(),
};
output = output.replace(match_name, &result);
@@ -131,7 +131,7 @@ impl Default for FormattedPart {
bg: None,
bold: false,
italic: false,
- content: "".to_string(),
+ content: "".to_owned(),
}
}
}
diff --git a/src/widgets/command.rs b/src/widgets/command.rs
index 9d50b50..c7df9b7 100644
--- a/src/widgets/command.rs
+++ b/src/widgets/command.rs
@@ -1,3 +1,4 @@
+use lazy_static::lazy_static;
use std::{
collections::BTreeMap,
fs::{remove_file, File},
@@ -15,6 +16,10 @@ use crate::{config::ZellijState, widgets::widget::Widget};
const TIMESTAMP_FORMAT: &str = "%s";
+lazy_static! {
+ static ref COMMAND_REGEX: Regex = Regex::new("_[a-zA-Z0-9]+$").unwrap();
+}
+
#[derive(Clone, Debug)]
struct CommandConfig {
command: String,
@@ -47,7 +52,7 @@ impl Widget for CommandWidget {
let command_config = match self.config.get(name) {
Some(cc) => cc,
None => {
- return "".to_string();
+ return "".to_owned();
}
};
@@ -56,7 +61,7 @@ impl Widget for CommandWidget {
let command_result = match state.command_results.get(name) {
Some(cr) => cr,
None => {
- return "".to_string();
+ return "".to_owned();
}
};
@@ -124,9 +129,8 @@ fn parse_config(zj_conf: BTreeMap<String, String>) -> BTreeMap<String, CommandCo
let mut config: BTreeMap<String, CommandConfig> = BTreeMap::new();
- let key_name_regex = Regex::new("_[a-zA-Z0-9]+$").unwrap();
for key in keys {
- let command_name = key_name_regex.replace(&key, "").to_string();
+ let command_name = COMMAND_REGEX.replace(&key, "").to_string();
let mut command_conf = CommandConfig {
command: "".to_owned(),
@@ -139,12 +143,12 @@ fn parse_config(zj_conf: BTreeMap<String, String>) -> BTreeMap<String, CommandCo
}
if key.ends_with("command") {
- command_conf.command = zj_conf.get(&key).unwrap().to_string().clone();
+ command_conf.command = zj_conf.get(&key).unwrap().to_owned().clone();
}
if key.ends_with("format") {
command_conf.format =
- FormattedPart::from_format_string(zj_conf.get(&key).unwrap().to_string().clone());
+ FormattedPart::from_format_string(zj_conf.get(&key).unwrap().to_owned().clone());
}
if key.ends_with("interval") {
diff --git a/src/widgets/datetime.rs b/src/widgets/datetime.rs
index b6a1193..ef2fbee 100644
--- a/src/widgets/datetime.rs
+++ b/src/widgets/datetime.rs
@@ -36,8 +36,8 @@ impl DateTimeWidget {
}
Self {
- format: format.to_string(),
- color_format: FormattedPart::from_format_string(color_format.to_string()),
+ format: format.to_owned(),
+ color_format: FormattedPart::from_format_string(color_format.to_owned()),
time_zone,
}
}
diff --git a/src/widgets/mode.rs b/src/widgets/mode.rs
index 61dda75..0cd68ac 100644
--- a/src/widgets/mode.rs
+++ b/src/widgets/mode.rs
@@ -27,72 +27,72 @@ pub struct ModeWidget {
impl ModeWidget {
pub fn new(config: BTreeMap<String, String>) -> Self {
let normal_format = match config.get("mode_normal") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => vec![],
};
let locked_format = match config.get("mode_locked") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => normal_format.clone(),
};
let resize_format = match config.get("mode_resize") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => normal_format.clone(),
};
let pane_format = match config.get("mode_pane") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => normal_format.clone(),
};
let tab_format = match config.get("mode_tab") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => normal_format.clone(),
};
let scroll_format = match config.get("mode_scroll") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => normal_format.clone(),
};
let enter_search_format = match config.get("mode_enter_search") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => normal_format.clone(),
};
let search_format = match config.get("mode_search") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => normal_format.clone(),
};
let rename_tab_format = match config.get("mode_rename_tab") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => normal_format.clone(),
};
let rename_pane_format = match config.get("mode_rename_pane") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => normal_format.clone(),
};
let session_format = match config.get("mode_session") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => normal_format.clone(),
};
let move_format = match config.get("mode_move") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => normal_format.clone(),
};
let prompt_format = match config.get("mode_prompt") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => normal_format.clone(),
};
let tmux_format = match config.get("mode_tmux") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => normal_format.clone(),
};
@@ -130,7 +130,7 @@ impl Widget for ModeWidget {
(f, content)
})
- .fold("".to_string(), |acc, (f, content)| {
+ .fold("".to_owned(), |acc, (f, content)| {
format!("{acc}{}", f.format_string(&content))
})
}
diff --git a/src/widgets/session.rs b/src/widgets/session.rs
index 2e75289..4d2ebf0 100644
--- a/src/widgets/session.rs
+++ b/src/widgets/session.rs
@@ -13,8 +13,8 @@ impl SessionWidget {
impl Widget for SessionWidget {
fn process(&self, _name: &str, state: &ZellijState) -> String {
match &state.mode.session_name {
- Some(name) => name.to_string(),
- None => "".to_string(),
+ Some(name) => name.to_owned(),
+ None => "".to_owned(),
}
}
diff --git a/src/widgets/swap_layout.rs b/src/widgets/swap_layout.rs
index 9b771ca..9b4dda6 100644
--- a/src/widgets/swap_layout.rs
+++ b/src/widgets/swap_layout.rs
@@ -16,14 +16,14 @@ impl Widget for SwapLayoutWidget {
let active_tab = state.tabs.iter().find(|t| t.active);
if active_tab.is_none() {
- return "".to_string();
+ return "".to_owned();
}
let active_tab = active_tab.unwrap();
match active_tab.active_swap_layout_name.clone() {
Some(n) => n,
- None => "".to_string(),
+ None => "".to_owned(),
}
}
diff --git a/src/widgets/tabs.rs b/src/widgets/tabs.rs
index 569519e..cefd124 100644
--- a/src/widgets/tabs.rs
+++ b/src/widgets/tabs.rs
@@ -19,31 +19,31 @@ impl TabsWidget {
pub fn new(config: BTreeMap<String, String>) -> Self {
let mut normal_tab_format: Vec<FormattedPart> = Vec::new();
if let Some(form) = config.get("tab_normal") {
- normal_tab_format = FormattedPart::multiple_from_format_string(form.to_string());
+ normal_tab_format = FormattedPart::multiple_from_format_string(form.to_owned());
}
let normal_tab_fullscreen_format = match config.get("tab_normal_fullscreen") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => normal_tab_format.clone(),
};
let normal_tab_sync_format = match config.get("tab_normal_sync") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => normal_tab_format.clone(),
};
let mut active_tab_format = normal_tab_format.clone();
if let Some(form) = config.get("tab_active") {
- active_tab_format = FormattedPart::multiple_from_format_string(form.to_string());
+ active_tab_format = FormattedPart::multiple_from_format_string(form.to_owned());
}
let active_tab_fullscreen_format = match config.get("tab_active_fullscreen") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => active_tab_format.clone(),
};
let active_tab_sync_format = match config.get("tab_active_sync") {
- Some(form) => FormattedPart::multiple_from_format_string(form.to_string()),
+ Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()),
None => active_tab_format.clone(),
};
@@ -60,7 +60,7 @@ impl TabsWidget {
impl Widget for TabsWidget {
fn process(&self, _name: &str, state: &ZellijState) -> String {
- let mut output = "".to_string();
+ let mut output = "".to_owned();
for tab in &state.tabs {
let content = self.render_tab(tab);
@@ -72,7 +72,7 @@ impl Widget for TabsWidget {
}
fn process_click(&self, state: &ZellijState, pos: usize) {
- let mut output = "".to_string();
+ let mut output = "".to_owned();
let mut offset = 0;
let mut index = 1;
@@ -120,7 +120,7 @@ impl TabsWidget {
fn render_tab(&self, tab: &TabInfo) -> String {
let formatters = self.select_format(tab);
- let mut output = "".to_string();
+ let mut output = "".to_owned();
for f in formatters.iter() {
let mut content = f.content.clone();
@@ -136,6 +136,6 @@ impl TabsWidget {
output = format!("{}{}", output, f.format_string(&content));
}
- output.to_string()
+ output.to_owned()
}
}