MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / print_version_flags_row

Function print_version_flags_row

src/display.rs:249–294  ·  view source on GitHub ↗
(country_flags: &[String], inner_width: usize)

Source from the content-addressed store, hash-verified

247}
248
249fn print_version_flags_row(country_flags: &[String], inner_width: usize) {
250 let version = env!("CARGO_PKG_VERSION");
251 let title = format!(" TraceDecay v{version}");
252 let title_display_width = title.len();
253 let available = inner_width.saturating_sub(2);
254
255 if country_flags.is_empty() {
256 let pad = available.saturating_sub(title_display_width);
257 println!("│ {}{} │", title, " ".repeat(pad));
258 return;
259 }
260
261 // Shuffle on each render so a different sample is shown when the list is
262 // longer than `MAX_DISPLAY_FLAGS` and gets truncated by available width.
263 let shuffled = shuffle_flags(country_flags);
264 let capped = &shuffled[..shuffled.len().min(MAX_DISPLAY_FLAGS)];
265 let has_overflow = shuffled.len() > MAX_DISPLAY_FLAGS;
266 let mut flags_str = String::new();
267 let mut display_width = 0;
268 let flag_width = 2; // emoji flags are 2 columns wide
269 // Reserve space for title + at least 2 spaces gap
270 let max_flags_width = available.saturating_sub(title_display_width + 2);
271 for (i, flag) in capped.iter().enumerate() {
272 let needed = if i == 0 { flag_width } else { 1 + flag_width };
273 let more_coming = has_overflow || i + 1 < capped.len();
274 let reserve = if more_coming { 2 } else { 0 };
275 if display_width + needed + reserve > max_flags_width {
276 flags_str.push_str(" …");
277 display_width += 2;
278 break;
279 }
280 if i > 0 {
281 flags_str.push(' ');
282 display_width += 1;
283 }
284 flags_str.push_str(flag);
285 display_width += flag_width;
286 if i + 1 == capped.len() && has_overflow {
287 flags_str.push_str(" …");
288 display_width += 2;
289 }
290 }
291
292 let pad = available.saturating_sub(title_display_width + display_width);
293 println!("│ {}{}{} │", title, " ".repeat(pad), flags_str);
294}
295
296/// Print the second title row: token counts right-aligned in green.
297fn print_tokens_row(

Callers 2

print_status_headerFunction · 0.85
print_status_tableFunction · 0.85

Calls 3

shuffle_flagsFunction · 0.85
pushMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected