diff --git a/player/lua/console.lua b/player/lua/console.lua index e5136c8928..b39f9dc370 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -167,9 +167,8 @@ function format_table(list, width_max, rows_max) -- use as many columns as possible for columns = 2, list_size do - local old_row_count = row_count - local rows_lower_bound = math.ceil(list_size / columns) - local rows_upper_bound = math.min(list_size, math.ceil(list_size / (columns - 1) - 1)) + local rows_lower_bound = math.min(rows_max, math.ceil(list_size / columns)) + local rows_upper_bound = math.min(rows_max, list_size, math.ceil(list_size / (columns - 1) - 1)) for rows = rows_upper_bound, rows_lower_bound, -1 do cw = {} width_total = 0 @@ -200,7 +199,7 @@ function format_table(list, width_max, rows_max) break end end - if row_count == old_row_count then + if width_total + (columns - 1) * spaces_min > width_max then break end end @@ -210,8 +209,7 @@ function format_table(list, width_max, rows_max) local spacing = column_count > 1 and string.format('%' .. spaces .. 's', ' ') or '' local rows = {} - local rows_truncated = math.min(row_count, rows_max) - for row = 1, rows_truncated do + for row = 1, row_count do local columns = {} for column = 1, column_count do local i = row + (column - 1) * row_count @@ -221,9 +219,9 @@ function format_table(list, width_max, rows_max) columns[column] = string.format(format_string, list[i]) end -- first row is at the bottom - rows[rows_truncated - row + 1] = table.concat(columns, spacing) + rows[row_count - row + 1] = table.concat(columns, spacing) end - return table.concat(rows, '\n'), rows_truncated + return table.concat(rows, '\n'), row_count end local function print_to_terminal()