mirror of https://github.com/mpv-player/mpv
console: wrap rows at the top
The previous commit was already a big improvement, but it was still somewhat slow on the lua interpreter. By wrapping the table at the top we loose the consistent placement of items while resizing (at least as long as the column count didn't change), but we avoid taking all the off screen items into account. The fewer items fit on screen the faster this becomes.
This commit is contained in:
parent
ff131d7a20
commit
f41805081b
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue