diff --git a/.gitignore b/.gitignore index 90998a9..090eb43 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ # bv (beads viewer) local config and caches .bv/ target/ +.DS_Store +src/.DS_Store diff --git a/src/layout/flex.rs b/src/layout/flex.rs index 0d5682d..c217751 100644 --- a/src/layout/flex.rs +++ b/src/layout/flex.rs @@ -2,11 +2,11 @@ use crate::format; use crate::layout::ActiveSection; use crate::section::{self, RenderContext}; -/// Expand the winning flex section to fill remaining terminal width. +/// Expand flex sections to fill remaining terminal width. /// /// Rules: -/// - Spacers take priority over non-spacer flex sections -/// - Only one flex section wins per line +/// - If multiple spacers exist, distribute extra space proportionally among them +/// - If only non-spacer flex sections exist, pick one winner (spacer > non-spacer) /// - Spacer: fill with spaces /// - context_bar: rebuild bar with wider width /// - Other: pad with trailing spaces @@ -18,7 +18,34 @@ pub fn flex_expand(active: &mut [ActiveSection], ctx: &RenderContext, separator: return; } - // Find winning flex section: spacer wins over non-spacer + let extra = term_width - current_width; + + // Collect all spacer indices + let spacer_indices: Vec = active + .iter() + .enumerate() + .filter(|(_, s)| s.is_spacer) + .map(|(i, _)| i) + .collect(); + + // If multiple spacers, distribute extra space among them + if spacer_indices.len() > 1 { + let per_spacer = extra / spacer_indices.len(); + let remainder = extra % spacer_indices.len(); + + for (i, &idx) in spacer_indices.iter().enumerate() { + // First spacers get +1 char from remainder + let this_width = per_spacer + if i < remainder { 1 } else { 0 } + 1; + let padding = " ".repeat(this_width); + active[idx].output = section::SectionOutput { + raw: padding.clone(), + ansi: padding, + }; + } + return; + } + + // Single spacer or non-spacer flex: find winning flex section let mut flex_idx: Option = None; for (i, sec) in active.iter().enumerate() { if !sec.is_flex { @@ -35,7 +62,6 @@ pub fn flex_expand(active: &mut [ActiveSection], ctx: &RenderContext, separator: } let Some(idx) = flex_idx else { return }; - let extra = term_width - current_width; if active[idx].is_spacer { let padding = " ".repeat(extra + 1); diff --git a/src/transcript.rs b/src/transcript.rs index d7aa528..e8d9fe3 100644 --- a/src/transcript.rs +++ b/src/transcript.rs @@ -125,7 +125,7 @@ pub fn parse_transcript(path: &Path, skip_lines: usize) -> Option = counts.into_iter().collect(); - sorted.sort_by(|a, b| b.1.cmp(&a.1)); + sorted.sort_by_key(|item| std::cmp::Reverse(item.1)); stats.tool_counts = sorted; Some(stats)