Skip to content

Commit d743d4c

Browse files
unhappychoiceclaude
andcommitted
feat(render): add Bar.value_label for fetcher-formatted value columns
list_ranking printed Bar.value as a raw u64, so fetchers could not control the value column's unit. Add an optional value_label field to Bar: text-first renderers prefer it, visual renderers (chart_bar / chart_pie) keep ignoring it and consume only the numeric value. list_ranking now renders value_label when present and preserves the fetcher's bar order instead of re-sorting by value descending — sort is the fetcher's responsibility, matching chart_bar / chart_pie. max_items truncates from the head. All existing Bar call sites pass value_label: None (no behavior change); the lastfm_top_* / lastfm_charts bars carry their pluralised play-count unit so list_ranking shows "1.5k plays" instead of "1500". Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 1768208 commit d743d4c

38 files changed

Lines changed: 202 additions & 30 deletions

‎src/fetcher/basic/bars.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ impl RealtimeFetcher for BasicBars {
5959
Bar {
6060
label: "alice".into(),
6161
value: 12,
62+
value_label: None,
6263
},
6364
Bar {
6465
label: "bob".into(),
6566
value: 7,
67+
value_label: None,
6668
},
6769
],
6870
})
@@ -80,6 +82,7 @@ impl RealtimeFetcher for BasicBars {
8082
.map(|b| Bar {
8183
label: b.label,
8284
value: b.value,
85+
value_label: None,
8386
})
8487
.collect(),
8588
}))

‎src/fetcher/code/comments.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ fn render_body(totals: Totals, shape: Shape, limit: usize, unit: Unit) -> Body {
263263
.map(|(name, stat)| Bar {
264264
label: name.clone(),
265265
value: bar_value(stat, unit),
266+
value_label: None,
266267
})
267268
.collect(),
268269
}),

‎src/fetcher/code/files.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ fn bars_body(scan: Scan) -> Body {
170170
.top_level
171171
.into_iter()
172172
.take(TOP_LEVEL_LIMIT)
173-
.map(|(label, value)| Bar { label, value })
173+
.map(|(label, value)| Bar {
174+
label,
175+
value,
176+
value_label: None,
177+
})
174178
.collect(),
175179
})
176180
}

‎src/fetcher/code/largest_files.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ fn bars_body(scan: Scan, limit: usize) -> Body {
290290
.map(|(path, n)| Bar {
291291
label: path,
292292
value: n,
293+
value_label: None,
293294
})
294295
.collect(),
295296
})
@@ -516,14 +517,17 @@ mod tests {
516517
Bar {
517518
label: "src/render/mod.rs".into(),
518519
value: 1234,
520+
value_label: None
519521
},
520522
Bar {
521523
label: "src/fetcher/git/mod.rs".into(),
522524
value: 812,
525+
value_label: None
523526
},
524527
Bar {
525528
label: "src/payload.rs".into(),
526529
value: 640,
530+
value_label: None
527531
},
528532
],
529533
})

‎src/fetcher/code/loc.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ fn render_body(totals: Totals, shape: Shape, limit: usize, unit: Unit) -> Body {
268268
.map(|(lang, n)| Bar {
269269
label: lang,
270270
value: n,
271+
value_label: None,
271272
})
272273
.collect(),
273274
}),

‎src/fetcher/code/todos.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,11 @@ fn render_body(scan: ScanResult, shape: Shape, limit: usize) -> Body {
318318
.file_counts
319319
.into_iter()
320320
.take(limit)
321-
.map(|(p, c)| Bar { label: p, value: c })
321+
.map(|(p, c)| Bar {
322+
label: p,
323+
value: c,
324+
value_label: None,
325+
})
322326
.collect(),
323327
}),
324328
_ => text_summary(scan.total, scan.files_with_hits),
@@ -715,10 +719,12 @@ mod tests {
715719
Bar {
716720
label: "b.rs".into(),
717721
value: 2,
722+
value_label: None
718723
},
719724
Bar {
720725
label: "a.rs".into(),
721726
value: 1,
727+
value_label: None
722728
},
723729
]
724730
),

‎src/fetcher/crypto_trending.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ fn rank_bar(coin: &Coin) -> Bar {
351351
Bar {
352352
label: coin.display_label(),
353353
value: (MAX_COUNT as usize - coin.position).max(1) as u64,
354+
value_label: None,
354355
}
355356
}
356357

‎src/fetcher/crypto_watchlist.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ fn bars_body(snapshot: &Snapshot) -> Body {
419419
.map(|c| Bar {
420420
label: format!("{} {}", c.arrow(), c.symbol),
421421
value: (c.change_24h.abs() * PCT_TO_BP).round() as u64,
422+
value_label: None,
422423
})
423424
.collect(),
424425
})

‎src/fetcher/deal/common.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub(super) fn bars_body(rows: &[DealRow]) -> Body {
143143
.map(|r| Bar {
144144
label: truncate(&r.title, LABEL_MAX_CHARS),
145145
value: r.discount_pct.unwrap_or(0) as u64,
146+
value_label: None,
146147
})
147148
.collect(),
148149
})

‎src/fetcher/forge_items.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ fn render_bars(rows: &[ForgeRow]) -> Body {
179179
.map(|r| Bar {
180180
label: r.label.clone(),
181181
value: r.activity_count,
182+
value_label: None,
182183
})
183184
.collect(),
184185
})

0 commit comments

Comments
 (0)