cargo-copter 0.3.0

Test dependents against multiple versions of your crate (or your local WIP before publishing). Inspired by the cargo-crusader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
/// Console formatting module - Pure rendering concerns
///
/// This module handles all console output formatting including:
/// - Table layout and borders
/// - Color terminal output
/// - Text truncation and padding
/// - Error box rendering
///
/// It accepts pre-formatted data from the report module and renders it to the console.
///
/// ## Output Flexibility
///
/// This module supports writing to any `std::io::Write` destination:
/// - Console (stdout/stderr) with optional colors
/// - String buffers (for markdown/HTML)
/// - Files
/// - Any combination via `TableWriter`
use std::io::{self, Write};
use std::sync::OnceLock;
use term::color::Color;
use terminal_size::{Width, terminal_size};
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};

// Constants for terminal formatting
const DEFAULT_TERMINAL_WIDTH: usize = 120;

/// Writer for table output - configurable for color/plain text
pub struct TableWriter<W: Write> {
    writer: W,
    use_colors: bool,
}

impl<W: Write> TableWriter<W> {
    /// Create a new table writer
    pub fn new(writer: W, use_colors: bool) -> Self {
        Self { writer, use_colors }
    }

    /// Write formatted text, optionally with color
    fn write_colored(&mut self, text: &str, color: Color) -> io::Result<()> {
        if self.use_colors {
            // Use RGB for bright yellow (better Windows Terminal support)
            if color == term::color::BRIGHT_YELLOW {
                write!(self.writer, "\x1b[38;2;255;255;102m{}\x1b[0m", text)
            } else if let Some(ref mut t) = term::stdout() {
                let _ = t.fg(color);
                let _ = t.write_all(text.as_bytes());
                let _ = t.reset();
                Ok(())
            } else {
                write!(self.writer, "{}", text)
            }
        } else {
            write!(self.writer, "{}", text)
        }
    }

    /// Write a newline
    fn writeln(&mut self) -> io::Result<()> {
        writeln!(self.writer)
    }

    /// Write table header
    pub fn write_table_header(
        &mut self,
        crate_name: &str,
        display_version: &str,
        total_deps: usize,
        test_plan: Option<&str>,
        this_path: Option<&str>,
    ) -> io::Result<()> {
        write!(self.writer, "{}", format_table_header(crate_name, display_version, total_deps, test_plan, this_path))
    }

    /// Write table footer
    pub fn write_table_footer(&mut self) -> io::Result<()> {
        write!(self.writer, "{}", format_table_footer())
    }

    /// Write separator line between dependents
    pub fn write_separator_line(&mut self) -> io::Result<()> {
        let w = get_widths();
        writeln!(
            self.writer,
            "├{:─<width1$}┼{:─<width2$}┼{:─<width3$}┼{:─<width4$}┼{:─<width5$}┤",
            "",
            "",
            "",
            "",
            "",
            width1 = w.offered,
            width2 = w.spec,
            width3 = w.resolved,
            width4 = w.dependent,
            width5 = w.result
        )
    }

    /// Write a main 5-column row with proper formatting and color
    pub fn write_main_row(&mut self, cells: [&str; 5], color: Color) -> io::Result<()> {
        let w = get_widths();
        let displays: Vec<String> = cells
            .iter()
            .zip([w.offered, w.spec, w.resolved, w.dependent, w.result].iter())
            .map(|(cell, width)| truncate_with_padding(cell, width - 2))
            .collect();

        let row =
            format!("{}{}{}{}{}", displays[0], displays[1], displays[2], displays[3], displays[4]);
        self.write_colored(&row, color)?;
        self.writeln()
    }

    /// Write multi-version rows (for transitive dependencies)
    pub fn write_multi_version_rows(&mut self, rows: &[(String, String, String)]) -> io::Result<()> {
        if rows.is_empty() {
            return Ok(());
        }

        let w = get_widths();
        let last_idx = rows.len() - 1;

        for (i, (spec, resolved, dependent)) in rows.iter().enumerate() {
            let prefix = if i == last_idx { "└─" } else { "├─" };
            let spec_display = truncate_with_padding(&format!("{} {}", prefix, spec), w.spec - 2);
            let resolved_display = truncate_with_padding(&format!("{} {}", prefix, resolved), w.resolved - 2);
            let dependent_display = truncate_with_padding(&format!("{} {}", prefix, dependent), w.dependent - 2);

            writeln!(
                self.writer,
                "│{:width1$}│ {}{}{} │{:width5$}│",
                "",
                spec_display,
                resolved_display,
                dependent_display,
                "",
                width1 = w.offered,
                width5 = w.result
            )?;
        }
        Ok(())
    }

    /// Write error box top
    pub fn write_error_box_top(&mut self) -> io::Result<()> {
        let w = get_widths();
        let error_box_width = w.spec + w.resolved + w.dependent + 6 - 2;

        writeln!(
            self.writer,
            "│{:width1$}│ ╭{:─<error_width$}╮ │{:width5$}│",
            "",
            "",
            "",
            width1 = w.offered,
            error_width = error_box_width - 4,
            width5 = w.result
        )
    }

    /// Write error box line
    pub fn write_error_box_line(&mut self, line: &str) -> io::Result<()> {
        let w = get_widths();
        let error_box_width = w.spec + w.resolved + w.dependent + 6 - 2;
        let padded = truncate_with_padding(line, error_box_width - 6);

        writeln!(self.writer, "│{:width1$}│ │ {} │ │{:width5$}│", "", padded, "", width1 = w.offered, width5 = w.result)
    }

    /// Write error box bottom
    pub fn write_error_box_bottom(&mut self) -> io::Result<()> {
        let w = get_widths();
        let error_box_width = w.spec + w.resolved + w.dependent + 6 - 2;

        writeln!(
            self.writer,
            "│{:width1$}│ ╰{:─<error_width$}╯ │{:width5$}│",
            "",
            "",
            "",
            width1 = w.offered,
            error_width = error_box_width - 4,
            width5 = w.result
        )
    }

    /// Write comparison table
    pub fn write_comparison_table(&mut self, stats_list: &[ComparisonStats]) -> io::Result<()> {
        if stats_list.is_empty() {
            return Ok(());
        }

        // Calculate column widths
        let label_width = 26;
        let value_width = 16;
        let total_width = label_width + stats_list.len() * value_width;

        // Title
        writeln!(self.writer, "\nVersion Comparison:")?;

        // Headers
        write!(self.writer, "{:<label_width$}", "", label_width = label_width)?;
        for stats in stats_list {
            write!(self.writer, "{:>value_width$}", stats.version_label, value_width = value_width)?;
        }
        writeln!(self.writer)?;

        // Separator
        writeln!(self.writer, "{}", "".repeat(total_width))?;

        // Write each row
        self.write_simple_row("Total tested", stats_list, |s| s.total_tested)?;

        // Already broken (special case - shows "-" for non-baseline)
        write!(self.writer, "{:<26}", "Already broken")?;
        for stats in stats_list {
            write!(self.writer, "{:>16}", stats.already_broken.map_or("-".to_string(), |c| c.to_string()))?;
        }
        writeln!(self.writer)?;

        writeln!(self.writer, "{}", "".repeat(total_width))?;

        self.write_delta_row("Passed fetch", stats_list, |s| s.passed_fetch)?;
        self.write_delta_row("Passed check", stats_list, |s| s.passed_check)?;
        self.write_delta_row("Passed test", stats_list, |s| s.passed_test)?;

        writeln!(self.writer, "{}", "".repeat(total_width))?;

        self.write_delta_row("Fully passing", stats_list, |s| s.fully_passing)?;
        writeln!(self.writer)?;

        Ok(())
    }

    /// Helper to write a simple comparison row (no deltas)
    fn write_simple_row<F>(&mut self, label: &str, stats_list: &[ComparisonStats], get_val: F) -> io::Result<()>
    where
        F: Fn(&ComparisonStats) -> usize,
    {
        write!(self.writer, "{:<26}", label)?;
        for stats in stats_list {
            write!(self.writer, "{:>16}", get_val(stats))?;
        }
        writeln!(self.writer)
    }

    /// Helper to write a comparison row with delta calculation
    fn write_delta_row<F>(&mut self, label: &str, stats_list: &[ComparisonStats], get_val: F) -> io::Result<()>
    where
        F: Fn(&ComparisonStats) -> usize,
    {
        write!(self.writer, "{:<26}", label)?;
        for (i, stats) in stats_list.iter().enumerate() {
            let val = get_val(stats);
            if i == 0 {
                write!(self.writer, "{:>16}", val)?;
            } else {
                let prev = get_val(&stats_list[i - 1]);
                let fixed = val.saturating_sub(prev);
                let regressed = prev.saturating_sub(val);
                let delta_str = match (fixed, regressed) {
                    (0, 0) => format!("{}", val),
                    (f, 0) => format!("+{}{}", f, val),
                    (0, r) => format!("-{}{}", r, val),
                    (f, r) => format!("+{} -{}{}", f, r, val),
                };
                write!(self.writer, "{:>16}", delta_str)?;
            }
        }
        writeln!(self.writer)
    }
}

//
// Table Layout and Widths
//

/// Column widths for the 5-column table
#[derive(Clone, Copy)]
pub struct TableWidths {
    pub offered: usize,
    pub spec: usize,
    pub resolved: usize,
    pub dependent: usize,
    pub result: usize,
    pub total: usize, // Total table width including borders
}

impl TableWidths {
    pub fn new(terminal_width: usize) -> Self {
        Self::new_with_offered(terminal_width, None)
    }

    pub fn new_with_offered(terminal_width: usize, offered_width: Option<usize>) -> Self {
        // Borders: │ = 6 characters (1 before each column + 1 at end)
        let borders = 6;
        let available = terminal_width.saturating_sub(borders);

        // Use fixed widths for columns with known/predictable values
        // Offered: use provided width or default to 23
        let offered = offered_width.unwrap_or(23);
        // Spec: "^0.8.52" or "→ =this" max ~12 chars
        let spec = 12;
        // Resolved: "0.8.91-preview 📦" max ~18 chars
        let resolved = 18;
        // Result: "build failed ✓✗-  1.3s" fixed ~25 chars
        let result = 25;

        // Dependent gets remaining space (for long crate names)
        let fixed_total = offered + spec + resolved + result;
        let dependent = if available > fixed_total {
            available - fixed_total
        } else {
            20 // Minimum fallback
        };

        TableWidths { offered, spec, resolved, dependent, result, total: terminal_width }
    }

    /// Calculate minimum offered column width for given versions
    pub fn calculate_offered_width(versions: &[String], _display_version: &str, force_versions: bool) -> usize {
        let mut max_width = "- baseline".len(); // 10 chars

        // Forced marker is 2 chars: "→!"
        let forced_width = if force_versions { 2 } else { 0 };

        // Check all test versions
        for version in versions {
            // Format: "{icon} {resolution}{version}[→!]"
            // Icon (1) + space (1) + resolution (1) + version + optional forced marker
            let width = 1 + 1 + 1 + version.len() + forced_width;
            max_width = max_width.max(width);
        }

        // Add 2 for cell padding (accounts for the -2 when truncating)
        max_width + 2
    }
}

/// Get terminal width or default to DEFAULT_TERMINAL_WIDTH
fn get_terminal_width() -> usize {
    // Check if width override is set
    if let Ok(guard) = OVERRIDE_WIDTH.read()
        && let Some(width) = *guard
    {
        return width;
    }

    if let Some((Width(w), _)) = terminal_size() { w as usize } else { DEFAULT_TERMINAL_WIDTH }
}

// Table widths - initialized once with actual version data (production), or resettable (tests)
static WIDTHS: OnceLock<TableWidths> = OnceLock::new();
static OVERRIDE_WIDTH: std::sync::RwLock<Option<usize>> = std::sync::RwLock::new(None);
static OVERRIDE_WIDTHS: std::sync::RwLock<Option<TableWidths>> = std::sync::RwLock::new(None);

/// Set console width override (for testing or CLI --console-width)
pub fn set_console_width(width: usize) {
    if let Ok(mut w) = OVERRIDE_WIDTH.write() {
        *w = Some(width);
    }
    // Also clear any cached widths so they get recalculated
    if let Ok(mut w) = OVERRIDE_WIDTHS.write() {
        *w = None;
    }
}

/// Clear console width override (for testing)
#[cfg(test)]
#[allow(dead_code)]
pub fn clear_console_width() {
    if let Ok(mut w) = OVERRIDE_WIDTH.write() {
        *w = None;
    }
    if let Ok(mut w) = OVERRIDE_WIDTHS.write() {
        *w = None;
    }
}

/// Initialize table widths based on versions being tested
pub fn init_table_widths(versions: &[String], display_version: &str, force_versions: bool) {
    let offered_width = TableWidths::calculate_offered_width(versions, display_version, force_versions);
    let widths = TableWidths::new_with_offered(get_terminal_width(), Some(offered_width));

    // For tests: use the resettable override
    if let Ok(mut w) = OVERRIDE_WIDTHS.write() {
        *w = Some(widths);
        return;
    }

    // For production: use the OnceLock (first initialization wins)
    let _ = WIDTHS.set(widths);
}

/// Get table widths (with fallback to defaults if not initialized)
pub fn get_widths() -> TableWidths {
    // Check override first (for tests or when width is dynamically set)
    if let Ok(guard) = OVERRIDE_WIDTHS.read()
        && let Some(widths) = *guard
    {
        return widths;
    }

    // Fall back to static widths
    *WIDTHS.get_or_init(|| TableWidths::new(get_terminal_width()))
}

//
// Text Formatting Utilities
//

/// Count the display width of a string, accounting for wide Unicode characters
pub fn display_width(s: &str) -> usize {
    // Use unicode-width crate for accurate width calculation
    UnicodeWidthStr::width(s)
}

/// Truncate and pad string to exact width (truncate from end, showing start)
pub fn truncate_with_padding(s: &str, width: usize) -> String {
    let display_w = display_width(s);

    if display_w > width {
        // Truncate
        let mut result = String::new();
        let mut current_width = 0;
        let chars: Vec<char> = s.chars().collect();

        // Reserve space for "..."
        let target_width = if width >= 3 { width - 3 } else { width };

        for c in chars.iter() {
            let c_width = UnicodeWidthChar::width(*c).unwrap_or(1);

            if current_width + c_width > target_width {
                break;
            }

            result.push(*c);
            current_width += c_width;
        }

        if width >= 3 {
            result.push_str("...");
            current_width += 3;
        }

        // Pad if needed
        if current_width < width {
            result.push_str(&" ".repeat(width - current_width));
        }

        result
    } else {
        // Pad with spaces to reach the width
        let padding = width - display_w;
        format!("{}{}", s, " ".repeat(padding))
    }
}

/// Truncate and pad string to exact width (truncate from start, showing end)
/// Used for columns where the end is more important (paths, package names, etc.)
pub fn truncate_from_start_with_padding(s: &str, width: usize) -> String {
    let display_w = display_width(s);

    if display_w > width {
        // Truncate from start
        let chars: Vec<char> = s.chars().collect();

        // Reserve space for "..."
        let target_width = if width >= 3 { width - 3 } else { width };

        // Calculate from the end
        let mut result_chars = Vec::new();
        let mut current_width = 0;

        for c in chars.iter().rev() {
            let c_width = UnicodeWidthChar::width(*c).unwrap_or(1);

            if current_width + c_width > target_width {
                break;
            }

            result_chars.push(*c);
            current_width += c_width;
        }

        // Reverse back to correct order
        result_chars.reverse();

        let mut result = if width >= 3 { String::from("...") } else { String::new() };

        result.extend(result_chars);
        current_width += if width >= 3 { 3 } else { 0 };

        // Pad if needed
        if current_width < width {
            result.push_str(&" ".repeat(width - current_width));
        }

        result
    } else {
        // Pad with spaces to reach the width
        let padding = width - display_w;
        format!("{}{}", s, " ".repeat(padding))
    }
}

//
// Table Header/Footer Rendering
//

/// Format table header as a string
pub fn format_table_header(
    crate_name: &str,
    display_version: &str,
    total_deps: usize,
    test_plan: Option<&str>,
    this_path: Option<&str>,
) -> String {
    let w = get_widths();

    let mut output = String::new();
    output.push('\n');

    // Show "Testing X dependencies" first
    output.push_str(&format!("Testing {} reverse dependencies of {}\n", total_deps, crate_name));

    // Include test plan if provided (dependents and versions lines)
    if let Some(plan) = test_plan {
        output.push_str(plan);
        output.push('\n');
    }

    // Format "this =" line with optional path
    let this_line = if let Some(path) = this_path {
        format!("  this = {} ({})", display_version, path)
    } else {
        format!("  this = {} (your work-in-progress version)", display_version)
    };
    output.push_str(&format!("{}\n", this_line));

    output.push('\n');

    output.push_str(&format!(
        "┌{:─<width1$}┬{:─<width2$}┬{:─<width3$}┬{:─<width4$}┬{:─<width5$}┐\n",
        "",
        "",
        "",
        "",
        "",
        width1 = w.offered,
        width2 = w.spec,
        width3 = w.resolved,
        width4 = w.dependent,
        width5 = w.result
    ));
    output.push_str(&format!(
        "│{:^width1$}│{:^width2$}│{:^width3$}│{:^width4$}│{:^width5$}│\n",
        "Offered",
        "Spec",
        "Resolved",
        "Dependent",
        "Result         Time",
        width1 = w.offered,
        width2 = w.spec,
        width3 = w.resolved,
        width4 = w.dependent,
        width5 = w.result
    ));
    output.push_str(&format!(
        "├{:─<width1$}┼{:─<width2$}┼{:─<width3$}┼{:─<width4$}┼{:─<width5$}┤\n",
        "",
        "",
        "",
        "",
        "",
        width1 = w.offered,
        width2 = w.spec,
        width3 = w.resolved,
        width4 = w.dependent,
        width5 = w.result
    ));

    output
}

/// Print table header to stdout with colors
pub fn print_table_header(
    crate_name: &str,
    display_version: &str,
    total_deps: usize,
    test_plan: Option<&str>,
    this_path: Option<&str>,
) {
    let mut writer = TableWriter::new(io::stdout(), false); // No colors for header
    let _ = writer.write_table_header(crate_name, display_version, total_deps, test_plan, this_path);
}

/// Format table footer as a string
pub fn format_table_footer() -> String {
    let w = get_widths();
    format!(
        "└{:─<width1$}┴{:─<width2$}┴{:─<width3$}┴{:─<width4$}┴{:─<width5$}┘\n",
        "",
        "",
        "",
        "",
        "",
        width1 = w.offered,
        width2 = w.spec,
        width3 = w.resolved,
        width4 = w.dependent,
        width5 = w.result
    )
}

/// Print table footer to stdout
pub fn print_table_footer() {
    let mut writer = TableWriter::new(io::stdout(), false);
    let _ = writer.write_table_footer();
}

/// Print separator line between dependents to stdout
pub fn print_separator_line() {
    let mut writer = TableWriter::new(io::stdout(), false);
    let _ = writer.write_separator_line();
}

//
// Row Rendering
//

/// Print a main 5-column row with proper formatting and color to stdout
pub fn print_main_row(cells: [&str; 5], color: Color) {
    let mut writer = TableWriter::new(io::stdout(), true); // Enable colors
    let _ = writer.write_main_row(cells, color);
}

/// Print multi-version dependency rows to stdout
pub fn print_multi_version_rows(rows: &[(String, String, String)]) {
    let mut writer = TableWriter::new(io::stdout(), false);
    let _ = writer.write_multi_version_rows(rows);
}

//
// Error Box Rendering
//

/// Helper to print error box top border
pub fn print_error_box_top() {
    let w = get_widths();
    let shortened_offered = 4;
    let corner0_width = if shortened_offered != w.offered { w.offered - shortened_offered - 1 } else { 0 };

    if corner0_width > 0 {
        println!(
            "│{:shortened$}┌{:─<c0$}┴{:─<c1$}┘{:padding$}└{:─<c2$}┘{:result$}│",
            "",
            "",
            "",
            "",
            "",
            "",
            shortened = shortened_offered,
            c0 = corner0_width,
            c1 = w.spec,
            padding = w.resolved,
            c2 = w.dependent,
            result = w.result
        );
    } else {
        println!(
            "│{:offered$}├{:─<spec$}┘{:padding$}└{:─<dep$}┘{:result$}│",
            "",
            "",
            "",
            "",
            "",
            offered = w.offered,
            spec = w.spec,
            padding = w.resolved,
            dep = w.dependent,
            result = w.result
        );
    }
}

/// Helper to print error box content line
pub fn print_error_box_line(line: &str) {
    let w = get_widths();
    let shortened_offered = 4;
    let error_text_width = w.total - 1 - shortened_offered - 1 - 1 - 1 - 1;
    let truncated = truncate_with_padding(line, error_text_width);
    println!("│{:shortened$}│ {}", "", truncated, shortened = shortened_offered);
}

/// Helper to print error box bottom border (transitioning back to main table)
pub fn print_error_box_bottom() {
    let w = get_widths();
    let shortened_offered = 4;
    let corner0_width = if shortened_offered != w.offered { w.offered - shortened_offered - 1 } else { 0 };

    if corner0_width > 0 {
        println!(
            "│{:shortened$}└{:─<c0$}┬{:─<c1$}┬{:─<c2$}┬{:─<c3$}┬{:─<c4$}┤",
            "",
            "",
            "",
            "",
            "",
            "",
            shortened = shortened_offered,
            c0 = corner0_width,
            c1 = w.spec,
            c2 = w.resolved,
            c3 = w.dependent,
            c4 = w.result
        );
    } else {
        println!(
            "│{:offered$}├{:─<spec$}┬{:─<resolved$}┬{:─<dep$}┬{:─<result$}┤",
            "",
            "",
            "",
            "",
            "",
            offered = w.offered,
            spec = w.spec,
            resolved = w.resolved,
            dep = w.dependent,
            result = w.result
        );
    }
}

//
// Comparison Table Rendering
//

/// Statistics for comparison table
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ComparisonStats {
    pub version_label: String, // "Default" or version number
    pub total_tested: usize,
    pub already_broken: Option<usize>, // Only for baseline
    pub passed_fetch: usize,
    pub passed_check: usize,
    pub passed_test: usize,
    pub fully_passing: usize,
    pub regressions: Vec<String>, // List of "dependent:version" that regressed
}

/// Print comparison table to stdout
pub fn print_comparison_table(stats_list: &[ComparisonStats]) {
    let mut writer = TableWriter::new(io::stdout(), false);
    let _ = writer.write_comparison_table(stats_list);
}

#[cfg(test)]
#[path = "console_format_test.rs"]
mod console_format_test;