pub fn render_grid(files: &[RenderedFile], columns: usize)Expand description
Renders files in responsive grid layout.
Arranges files horizontally in columns, printing them row by row. Each file occupies one column, with rows printed until all files are displayed. Handles variable line counts by padding short files with empty lines.
§Algorithm
- If single column: print each file vertically
- Calculate column width (max file width)
- Process files in chunks of
columnssize - For each chunk:
- Find max line count
- Print each row across all columns
- Pad columns to align properly
§Arguments
files- Slice of rendered files to displaycolumns- Number of columns to use (fromcalculate_columns)
§Performance
- Single allocation per output line
- Pre-calculates maximum line count per chunk
- Uses padding with pre-calculated widths
§Examples
use cargo_quality::differ::display::{grid::render_grid, types::RenderedFile};
let file1 = RenderedFile {
lines: vec!["Line 1".to_string(), "Line 2".to_string()],
width: 40
};
let file2 = RenderedFile {
lines: vec!["Other 1".to_string(), "Other 2".to_string()],
width: 40
};
render_grid(&[file1, file2], 2);