diff options
| author | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-09-21 20:28:38 +0200 |
|---|---|---|
| committer | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-09-21 20:28:38 +0200 |
| commit | bd5bd7804f6b4dbf88f64891d9f8bd1e6126a28c (patch) | |
| tree | b4de17a0a38ef47fafddf4e910d6b639607cdbea /src/widgets | |
| parent | chore: add new screenshot (diff) | |
| download | sl0pstatus-bd5bd7804f6b4dbf88f64891d9f8bd1e6126a28c.tar.gz sl0pstatus-bd5bd7804f6b4dbf88f64891d9f8bd1e6126a28c.tar.xz sl0pstatus-bd5bd7804f6b4dbf88f64891d9f8bd1e6126a28c.zip | |
fix: clickable tabs when using index in template
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/tabs.rs | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/widgets/tabs.rs b/src/widgets/tabs.rs index 78ac009..d302cd7 100644 --- a/src/widgets/tabs.rs +++ b/src/widgets/tabs.rs @@ -72,15 +72,7 @@ impl Widget for TabsWidget { for tab in state.tabs { let formatter = self.select_format(tab.clone()); - - let mut content = formatter.content.clone(); - if content.contains("{name}") { - content = content.replace("{name}", tab.name.as_str()); - } - - if content.contains("{index}") { - content = content.replace("{index}", (tab.position + 1).to_string().as_str()); - } + let content = self.render_tab(tab); output = format!("{}{}", output, formatter.format_string(content),); } @@ -94,12 +86,8 @@ impl Widget for TabsWidget { let mut offset = 0; let mut index = 1; for tab in state.tabs { - let formatter = self.select_format(tab.clone()); + let content = self.render_tab(tab); - let mut content = formatter.content.clone(); - if content.contains("{name}") { - content = content.replace("{name}", tab.name.as_str()); - } if pos > offset && pos < offset + content.len() { switch_tab_to(index); @@ -138,4 +126,19 @@ impl TabsWidget { self.normal_tab_format.clone() } + + fn render_tab(&self, tab: TabInfo) -> String { + let formatter = self.select_format(tab.clone()); + + let mut content = formatter.content.clone(); + if content.contains("{name}") { + content = content.replace("{name}", tab.name.as_str()); + } + + if content.contains("{index}") { + content = content.replace("{index}", (tab.position + 1).to_string().as_str()); + } + + content + } } |
