summaryrefslogtreecommitdiffstats
path: root/player/lua
diff options
context:
space:
mode:
authorChristoph Heinrich <christoph.heinrich@student.tugraz.at>2023-09-27 22:36:58 +0200
committerDudemanguy <random342@airmail.cc>2023-11-07 01:36:59 +0000
commitf41805081b2c4aee2b4d4519be1b2dbe62c689a0 (patch)
treea8a19b85275957b779520a5666d4088a8d07a451 /player/lua
parentff131d7a20c50a678f6af820adf8ab2e3493849d (diff)
downloadmpv-f41805081b2c4aee2b4d4519be1b2dbe62c689a0.tar.bz2
mpv-f41805081b2c4aee2b4d4519be1b2dbe62c689a0.tar.xz
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.
Diffstat (limited to 'player/lua')
-rw-r--r--player/lua/console.lua14
1 files changed, 6 insertions, 8 deletions
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()