* Shrink all columns by shortening them one row each time (and adding * more columns along the way). Hopefully the longest cell will be * moved to the next column, column is shrunk so we have more space * for new columns. The process ends when the whole thing no longer * fits in data->total_width. */
| 73 | * fits in data->total_width. |
| 74 | */ |
| 75 | static void shrink_columns(struct column_data *data) |
| 76 | { |
| 77 | REALLOC_ARRAY(data->width, data->cols); |
| 78 | while (data->rows > 1) { |
| 79 | int x, total_width, cols, rows; |
| 80 | rows = data->rows; |
| 81 | cols = data->cols; |
| 82 | |
| 83 | data->rows--; |
| 84 | data->cols = DIV_ROUND_UP(data->list->nr, data->rows); |
| 85 | if (data->cols != cols) |
| 86 | REALLOC_ARRAY(data->width, data->cols); |
| 87 | compute_column_width(data); |
| 88 | |
| 89 | total_width = strlen(data->opts.indent); |
| 90 | for (x = 0; x < data->cols; x++) { |
| 91 | total_width += data->len[data->width[x]]; |
| 92 | total_width += data->opts.padding; |
| 93 | } |
| 94 | if (total_width > data->opts.width) { |
| 95 | data->rows = rows; |
| 96 | data->cols = cols; |
| 97 | break; |
| 98 | } |
| 99 | } |
| 100 | compute_column_width(data); |
| 101 | } |
| 102 | |
| 103 | /* Display without layout when not enabled */ |
| 104 | static void display_plain(const struct string_list *list, |
no test coverage detected