Skip to content

Commit

Permalink
feat(tabs): multiple formats for truncation marker
Browse files Browse the repository at this point in the history
  • Loading branch information
dj95 committed Aug 7, 2024
1 parent 05fe796 commit b035e27
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions plugin-dev-workspace.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ layout {
tab_sync_indicator "S"
tab_fullscreen_indicator "FS"
tab_display_count "3"
tab_truncate_start_format "#[fg=red,bg=$bg] < +{count} ..."
tab_truncate_end_format "#[fg=red,bg=$bg] ... +{count} >"
tab_truncate_start_format "#[fg=$blue,bg=$bg]#[bg=$blue,fg=black] +{count} ... #[fg=$bg,bg=$blue]"
tab_truncate_end_format "#[fg=red,bg=$bg] ... +{count} > #[bg=$yellow] "

command_0_command "echo \"平仮名, ひらがな 📦\""
command_0_clickaction "bash -c \"zellij --session zjstatus-dev pipe 'zjstatus::notify::hello world!' -n zjstatus\""
Expand Down
26 changes: 14 additions & 12 deletions src/widgets/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub struct TabsWidget {
floating_indicator: Option<String>,
sync_indicator: Option<String>,
tab_display_count: Option<usize>,
tab_truncate_start_format: Option<FormattedPart>,
tab_truncate_end_format: Option<FormattedPart>,
tab_truncate_start_format: Vec<FormattedPart>,
tab_truncate_end_format: Vec<FormattedPart>,
}

impl TabsWidget {
Expand Down Expand Up @@ -73,11 +73,13 @@ impl TabsWidget {

let tab_truncate_start_format = config
.get("tab_truncate_start_format")
.map(|form| FormattedPart::from_format_string(form, config));
.map(|form| FormattedPart::multiple_from_format_string(form, config))
.unwrap_or_default();

let tab_truncate_end_format = config
.get("tab_truncate_end_format")
.map(|form| FormattedPart::from_format_string(form, config));
.map(|form| FormattedPart::multiple_from_format_string(form, config))
.unwrap_or_default();

let separator = config
.get("tab_separator")
Expand Down Expand Up @@ -111,14 +113,14 @@ impl Widget for TabsWidget {
get_tab_window(&state.tabs, self.tab_display_count);

if truncated_start > 0 {
if let Some(f) = &self.tab_truncate_start_format {
for f in &self.tab_truncate_start_format {
let mut content = f.content.clone();

if content.contains("{count}") {
content = content.replace("{count}", (truncated_start).to_string().as_str());
}

output = format!("{}{output}", f.format_string(&content));
output = format!("{output}{}", f.format_string(&content));
}
}

Expand All @@ -136,7 +138,7 @@ impl Widget for TabsWidget {
}

if truncated_end > 0 {
if let Some(f) = &self.tab_truncate_end_format {
for f in &self.tab_truncate_end_format {
let mut content = f.content.clone();

if content.contains("{count}") {
Expand Down Expand Up @@ -166,14 +168,14 @@ impl Widget for TabsWidget {
+ 1;

if truncated_start > 0 {
if let Some(f) = &self.tab_truncate_start_format {
for f in &self.tab_truncate_start_format {
let mut content = f.content.clone();

if content.contains("{count}") {
content = content.replace("{count}", (truncated_end).to_string().as_str());
}

offset = console::measure_text_width(&f.format_string(&content));
offset += console::measure_text_width(&f.format_string(&content));

if pos <= offset {
switch_tab_to(active_pos.saturating_sub(1) as u32);
Expand Down Expand Up @@ -205,7 +207,7 @@ impl Widget for TabsWidget {
}

if truncated_end > 0 {
if let Some(f) = &self.tab_truncate_end_format {
for f in &self.tab_truncate_end_format {
let mut content = f.content.clone();

if content.contains("{count}") {
Expand Down Expand Up @@ -276,7 +278,7 @@ impl TabsWidget {

if content.contains("{floating_total_count}") {
let panes_for_tab: Vec<PaneInfo> =
panes.panes.get(&tab.position).cloned().unwrap_or(vec![]);
panes.panes.get(&tab.position).cloned().unwrap_or_default();

content = content.replace(
"{floating_total_count}",
Expand Down Expand Up @@ -318,7 +320,7 @@ impl TabsWidget {

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![]);
panes.panes.get(&tab.position).cloned().unwrap_or_default();

let is_floating = panes_for_tab.iter().any(|p| p.is_floating);

Expand Down

0 comments on commit b035e27

Please sign in to comment.