Function calculate_column_width

Source
pub fn calculate_column_width(
    column: &[String],
    min_width: usize,
    max_width: usize,
) -> usize
Expand description

Calculates the optimal width for a column based on its content.

This function analyzes all strings in a column and determines the optimal width that accommodates the content while respecting minimum and maximum constraints. It uses Unicode width calculation to handle multi-byte characters correctly.

§Arguments

  • column - Vector of formatted strings representing the column
  • min_width - Minimum allowed column width
  • max_width - Maximum allowed column width

§Returns

The calculated optimal width for the column.

§Examples

use tidy_viewer::datatype::calculate_column_width;

let column = vec!["123".to_string(), "456.78".to_string(), "hello".to_string()];
let width = calculate_column_width(&column, 2, 20);

assert!(width >= 2 && width <= 20);