diff options
| author | Daniel Jankowski <daniel.jankowski@rub.de> | 2024-02-23 09:46:10 +0100 |
|---|---|---|
| committer | Daniel Jankowski <daniel.jankowski@rub.de> | 2024-02-23 09:46:10 +0100 |
| commit | 600dd593669907778fd2e95a5c4ea4ce211b1a43 (patch) | |
| tree | f97ce35554291111427f168274dbd98ffb425fbc | |
| parent | chore: update cargo deps (diff) | |
| download | sl0pstatus-600dd593669907778fd2e95a5c4ea4ce211b1a43.tar.gz sl0pstatus-600dd593669907778fd2e95a5c4ea4ce211b1a43.tar.xz sl0pstatus-600dd593669907778fd2e95a5c4ea4ce211b1a43.zip | |
feat(tabs): add configurable indicators for sync, fullscreen & floating
| -rw-r--r-- | README.md | 15 | ||||
| -rw-r--r-- | plugin-dev-workspace.kdl | 9 | ||||
| -rw-r--r-- | src/widgets/tabs.rs | 51 |
3 files changed, 68 insertions, 7 deletions
@@ -279,6 +279,10 @@ Print a list of current tabs. The name of the tab can be used with `{name}` in t default to the normal formatting, if not configured. With `{index}` the tab position can also be used. With `{floating_total_count}` you can print the total amount of floating panes. +In addition to separate formats for sync and fullscreen tabs, you can use `{sync_indicator}`, +`{fullscreen_indicator}` and `{floating_indicator}` in each format. It will be replaced with the respective +configuration from `tab_sync_indicator` and so on. Please be aware, that the indicators are only replaced +when they are configured. ```kdl # formatting for inactive tabs @@ -287,12 +291,17 @@ tab_normal_fullscreen "#[fg=#6C7086] {index} :: {name} [] " tab_normal_sync "#[fg=#6C7086] {index} :: {name} <> " # formatting for the current active tab -tab_active "#[fg=#9399B2,bold,italic] {name} " -tab_active_fullscreen "#[fg=#9399B2,bold,italic] {name} [] " -tab_active_sync "#[fg=#9399B2,bold,italic] {name} <> " +tab_active "#[fg=#9399B2,bold,italic] {name} {floating_indicator}" +tab_active_fullscreen "#[fg=#9399B2,bold,italic] {name} {fullscreen_indicator}" +tab_active_sync "#[fg=#9399B2,bold,italic] {name} {sync_indicator}" # separator between the tabs tab_separator "#[fg=#6C7086,bg=#181825] | " + +# indicators +tab_sync_indicator "<> " +tab_fullscreen_indicator "[] " +tab_float_indicator "⬚ " ``` ## 🚧 Development diff --git a/plugin-dev-workspace.kdl b/plugin-dev-workspace.kdl index 3f94edd..068aa15 100644 --- a/plugin-dev-workspace.kdl +++ b/plugin-dev-workspace.kdl @@ -21,13 +21,14 @@ layout { mode_tmux "#[bg=yellow] " mode_default_to_mode "tmux" - tab_normal "#[fg=#6C7086,bg=#181825] {index} {name} " + tab_normal "#[fg=#6C7086,bg=#181825] {index} {name} {floating_indicator} " tab_normal_fullscreen "#[fg=#6C7086,bg=#181825] {index} {name} [] " tab_normal_sync "#[fg=#6C7086,bg=#181825] {index} {name} <> " - tab_active "#[fg=#9399B2,bg=#181825,bold,italic] {index} {name} {floating_total_count}" - tab_active_fullscreen "#[fg=#9399B2,bg=#181825,bold,italic] {index} {name} [] " - tab_active_sync "#[fg=#9399B2,bg=#181825,bold,italic] {index} {name} <> " + tab_active "#[fg=#9399B2,bg=#181825,bold,italic] {index} {name} {floating_total_count} {floating_indicator} {sync_indicator} {fullscreen_indicator}" tab_separator "#[fg=#6C7086,bg=#181825] | " + tab_floating_indicator "F" + tab_sync_indicator "S" + tab_fullscreen_indicator "FS" command_0_command "echo \"平仮名, ひらがな 📦\"" command_0_format "#[fg=blue,bg=black] {exit_code} {stdout} " diff --git a/src/widgets/tabs.rs b/src/widgets/tabs.rs index 3cfdfbf..c1e7d13 100644 --- a/src/widgets/tabs.rs +++ b/src/widgets/tabs.rs @@ -17,6 +17,9 @@ pub struct TabsWidget { normal_tab_fullscreen_format: Vec<FormattedPart>, normal_tab_sync_format: Vec<FormattedPart>, separator: Option<FormattedPart>, + fullscreen_indicator: Option<String>, + floating_indicator: Option<String>, + sync_indicator: Option<String>, } impl TabsWidget { @@ -63,6 +66,9 @@ impl TabsWidget { active_tab_fullscreen_format, active_tab_sync_format, separator, + floating_indicator: config.get("tab_floating_indicator").cloned(), + sync_indicator: config.get("tab_sync_indicator").cloned(), + fullscreen_indicator: config.get("tab_fullscreen_indicator").cloned(), } } } @@ -168,9 +174,54 @@ impl TabsWidget { ); } + content = self.replace_indicators(content, tab, panes); + output = format!("{}{}", output, f.format_string(&content)); } output.to_owned() } + + fn replace_indicators(&self, content: String, tab: &TabInfo, panes: &PaneManifest) -> String { + let mut content = content; + if content.contains("{fullscreen_indicator}") && self.fullscreen_indicator.is_some() { + content = content.replace( + "{fullscreen_indicator}", + if tab.is_fullscreen_active { + self.fullscreen_indicator.as_ref().unwrap() + } else { + "" + }, + ); + } + + if content.contains("{sync_indicator}") && self.sync_indicator.is_some() { + content = content.replace( + "{sync_indicator}", + if tab.is_sync_panes_active { + self.sync_indicator.as_ref().unwrap() + } else { + "" + }, + ); + } + + if content.contains("{floating_indicator}") && self.floating_indicator.is_some() { + let panes_for_tab: Vec<PaneInfo> = + panes.panes.get(&tab.position).cloned().unwrap_or(vec![]); + + let is_floating = panes_for_tab.iter().any(|p| p.is_floating); + + content = content.replace( + "{floating_indicator}", + if is_floating { + self.floating_indicator.as_ref().unwrap() + } else { + "" + }, + ); + } + + content + } } |
