summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Heinrich <christoph.heinrich@student.tugraz.at>2023-08-28 22:43:29 +0200
committerKacper Michajłow <kasper93@gmail.com>2024-03-21 03:08:52 +0100
commit16a480375b77d88ea34e81c5452a07c20f4a8a6b (patch)
tree6c4fadb9f51c49399c058e3e78d1e8e486d4c9c5
parent2a08440afbe76548c583bd38ac9ae89300ed9d1d (diff)
downloadmpv-16a480375b77d88ea34e81c5452a07c20f4a8a6b.tar.bz2
mpv-16a480375b77d88ea34e81c5452a07c20f4a8a6b.tar.xz
stats.lua: refactor page 4 scrolling into function
This scrolling implementation will be used for other pages in future commits. The comment said it takes up 20 lines of the terminal, but in reality it was 22 lines.
-rw-r--r--player/lua/stats.lua34
1 files changed, 24 insertions, 10 deletions
diff --git a/player/lua/stats.lua b/player/lua/stats.lua
index e004272bcb..8d27ef183a 100644
--- a/player/lua/stats.lua
+++ b/player/lua/stats.lua
@@ -1006,6 +1006,25 @@ local function eval_ass_formatting()
end
+-- Composes the output with header and scrollable content
+-- Returns string of the finished page and the actually chosen offset
+--
+-- header : table of the header where each entry is one line
+-- content : table of the content where each entry is one line
+-- offset : the desired scroll offset of the content from the first line at the top
+local function compose_page(header, content, offset)
+ -- up to 22 lines for the terminal - so that mpv can also print
+ -- the status line without scrolling, and up to 40 lines for libass
+ -- because it can put a big performance toll on libass to process
+ -- many lines which end up outside (below) the screen.
+ local max_content_lines = (o.use_ass and 40 or 22) - #header
+ -- in the terminal the scrolling should stop once the last line is visible
+ local max_offset = o.use_ass and #content or #content - max_content_lines + 1
+ local from = max(1, min((offset or 1), max_offset))
+ local to = min(#content, from + max_content_lines - 1)
+ return table.concat(header) .. table.concat(content, "", from, to), from
+end
+
-- Returns an ASS string with "normal" stats
local function default_stats()
local stats = {}
@@ -1055,20 +1074,15 @@ local function keybinding_info(after_scroll)
append(header, "", {prefix=format("%s: {\\fs%s}%s{\\fs%s}", page.desc,
o.font_size * 0.66, "(hint: scroll with ↑↓)", o.font_size), nl="",
indent=""})
+ header = {table.concat(header)}
if not kbinfo_lines or not after_scroll then
kbinfo_lines = get_kbinfo_lines()
end
- -- up to 20 lines for the terminal - so that mpv can also print
- -- the status line without scrolling, and up to 40 lines for libass
- -- because it can put a big performance toll on libass to process
- -- many lines which end up outside (below) the screen.
- local term = not o.use_ass
- local nlines = #kbinfo_lines
- page.offset = max(1, min((page.offset or 1), term and nlines - 20 or nlines))
- local maxline = min(nlines, page.offset + (term and 20 or 40))
- return table.concat(header) ..
- table.concat(kbinfo_lines, "", page.offset, maxline)
+
+ local res = nil
+ res, page.offset = compose_page(header, kbinfo_lines, page.offset)
+ return res
end
local function perf_stats()