fix: clippy lint and multi-spacer distribution
- transcript.rs: use sort_by_key with Reverse instead of sort_by (clippy::unnecessary_sort_by) - flex.rs: distribute extra space proportionally among multiple spacers instead of picking a single winner - .gitignore: add .DS_Store entries Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
# bv (beads viewer) local config and caches
|
||||
.bv/
|
||||
target/
|
||||
.DS_Store
|
||||
src/.DS_Store
|
||||
|
||||
@@ -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<usize> = 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<usize> = 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);
|
||||
|
||||
@@ -125,7 +125,7 @@ pub fn parse_transcript(path: &Path, skip_lines: usize) -> Option<TranscriptStat
|
||||
|
||||
// Sort by count descending
|
||||
let mut sorted: Vec<(String, u64)> = 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)
|
||||
|
||||
Reference in New Issue
Block a user