create_match_table

Function create_match_table 

Source
pub fn create_match_table(rows: Vec<MatchDisplayRow>) -> String
Expand description

Create a formatted table string from match operation results.

Transforms a collection of match display rows into a beautifully formatted table string suitable for terminal display. The table uses consistent styling with rounded borders and proper column alignment for optimal readability.

§Table Features

  • Rounded borders: Modern, visually appealing table style
  • Left alignment: Consistent text alignment for all content rows
  • Auto-sizing: Columns automatically adjust to content width
  • Header styling: Clear distinction between headers and data
  • Unicode support: Proper handling of Chinese characters and symbols

§Arguments

  • rows - Vector of MatchDisplayRow structures to be displayed

§Returns

A formatted table string ready for printing to the terminal

§Examples

use subx_cli::cli::table::{MatchDisplayRow, create_match_table};

// Multi-line display of multiple match results
let results = vec![
    MatchDisplayRow { file_type: "Video 1".to_string(), file_path: "Movie.mp4".to_string() },
    MatchDisplayRow { file_type: "Subtitle 1".to_string(), file_path: "sub123.srt".to_string() },
    MatchDisplayRow { file_type: "New name 1".to_string(), file_path: "Movie.srt".to_string() },
    MatchDisplayRow { file_type: "Video 2".to_string(), file_path: "Episode.mkv".to_string() },
    MatchDisplayRow { file_type: "Subtitle 2".to_string(), file_path: "unknown.srt".to_string() },
    MatchDisplayRow { file_type: "New name 2".to_string(), file_path: "Episode.srt".to_string() },
];

let table = create_match_table(results);
println!("{}", table);

§Output Example

╭──────┬──────────────┬──────────────┬──────────────╮
│ Status │ Video File     │ Subtitle File     │ New Name       │
├──────┼──────────────┼──────────────┼──────────────┤
│ ✓    │ Movie.mp4    │ sub123.srt   │ Movie.srt    │
│ ⚠    │ Episode.mkv  │ unknown.srt  │ Episode.srt  │
╰──────┴──────────────┴──────────────┴──────────────╯

§Empty Input Handling

If an empty vector is provided, returns a table with only headers, indicating no results to display.