diff --git a/DOCS/interface-changes/stats-term-clip.txt b/DOCS/interface-changes/stats-term-clip.txt new file mode 100644 index 0000000000..8b3cdf47bd --- /dev/null +++ b/DOCS/interface-changes/stats-term-clip.txt @@ -0,0 +1,2 @@ +remove `stats-term_width_limit` script-opt +add `stats-term_clip` script-opt diff --git a/DOCS/man/stats.rst b/DOCS/man/stats.rst index 204c17f972..10933c0f38 100644 --- a/DOCS/man/stats.rst +++ b/DOCS/man/stats.rst @@ -115,11 +115,10 @@ Configurable Options Only show the first specified amount of file tags. -``term_width_limit`` - Default: -1 +``term_clip`` + Default: yes - Sets the terminal width. - A value of 0 means the width is infinite, -1 means it's automatic. + Whether to clip lines to the terminal width. ``term_height_limit`` Default: -1 @@ -259,10 +258,10 @@ string, and one should not expect documentation-level grouping accuracy, however, it should still be reasonably useful. Using ``--idle --script-opts-append=stats-bindlist=yes`` will print the list to -the terminal and quit immediately. By default long lines are shortened to 79 -chars, and terminal escape sequences are enabled. A different length limit can -be set by changing ``yes`` to a number (at least 40), and escape sequences can -be disabled by adding ``-`` before the value, e.g. ``...=-yes`` or ``...=-120``. +the terminal and quit immediately. Long lines are clipped to the terminal width +unless this is disabled with ``--script-opts-append=stats-term_clip=no``. Escape +sequences can be disabled by adding ``-`` before ``yes``, i.e. +``--script-opts-append=stats-bindlist=-yes``. Like with ``--input-test``, the list includes bindings from ``input.conf`` and from user scripts. Use ``--no-config`` to list only built-in bindings. diff --git a/player/lua/stats.lua b/player/lua/stats.lua index f53b76b81e..47a28ef0d7 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -35,7 +35,7 @@ local o = { file_tag_max_length = 128, -- only show file tags shorter than this length in bytes file_tag_max_count = 16, -- only show the first x file tags show_frame_info = false, -- whether to show the current frame info - term_width_limit = -1, -- overwrites the terminal width + term_clip = true, term_height_limit = -1, -- overwrites the terminal height debug = false, @@ -92,11 +92,7 @@ local o = { } options.read_options(o) -o.term_width_limit = tonumber(o.term_width_limit) or -1 o.term_height_limit = tonumber(o.term_height_limit) or -1 -if o.term_width_limit < 0 then - o.term_width_limit = nil -end if o.term_height_limit < 0 then o.term_height_limit = nil end @@ -1093,47 +1089,6 @@ local function eval_ass_formatting() end end --- assumptions: --- s is composed of SGR escape sequences and/or printable UTF8 sequences --- printable codepoints occupy one terminal cell (we don't have wcwidth) --- tabstops are 8, 16, 24..., and the output starts at 0 or a tabstop --- note: if maxwidth <= 2 and s doesn't fit: the result is "..." (more than 2) -local function term_ellipsis(s, maxwidth) - local TAB, ESC, SGR_END = 9, 27, ("m"):byte() - local width, ellipsis = 0, "..." - local fit_len, in_sgr - - for i = 1, #s do - local x = s:byte(i) - - if in_sgr then - in_sgr = x ~= SGR_END - elseif x == ESC then - in_sgr = true - ellipsis = "\27[0m..." -- ensure SGR reset - elseif x < 128 or x >= 192 then -- non UTF8-continuation - -- tab adds till the next stop, else add 1 - width = width + (x == TAB and 8 - width % 8 or 1) - - if fit_len == nil and width > maxwidth - 3 then - fit_len = i - 1 -- adding "..." still fits maxwidth - end - if width > maxwidth then - return s:sub(1, fit_len) .. ellipsis - end - end - end - - return s -end - -local function term_ellipsis_array(arr, from, to, max_width) - for i = from, to do - arr[i] = term_ellipsis(arr[i], max_width) - end - return arr -end - -- split str into a table -- example: local t = split(s, "\n") -- plain: whether pat is a plain string (default false - pat is a pattern) @@ -1156,7 +1111,6 @@ end -- apply_scroll: scroll the content local function finalize_page(header, content, apply_scroll) local term_size = mp.get_property_native("term-size", {}) - local term_width = o.term_width_limit or term_size.w or 80 local term_height = o.term_height_limit or term_size.h or 24 local from, to = 1, #content if apply_scroll and term_height > 0 then @@ -1171,10 +1125,10 @@ local function finalize_page(header, content, apply_scroll) pages[curr_page].offset = from end local output = table.concat(header) .. table.concat(content, "", from, to) - if not o.use_ass and term_width > 0 then + if not o.use_ass and o.term_clip then + local clip = mp.get_property("term-clip-cc") local t = split(output, "\n", true) - -- limit width for the terminal - output = table.concat(term_ellipsis_array(t, 1, #t, term_width), "\n") + output = clip .. table.concat(t, "\n" .. clip) end return output, from end @@ -1211,7 +1165,7 @@ local function keybinding_info(after_scroll, bindlist) header = {table.concat(header)} if not kbinfo_lines or not after_scroll then - kbinfo_lines = get_kbinfo_lines(o.term_width_limit) + kbinfo_lines = get_kbinfo_lines() end return finalize_page(header, kbinfo_lines, not bindlist) @@ -1793,7 +1747,6 @@ mp.register_event("video-reconfig", end end) --- --script-opts=stats-bindlist=[-]{yes|} if o.bindlist ~= "no" then -- This is a special mode to print key bindings to the terminal, -- Adjust the print format and level to make it print only the key bindings. @@ -1804,14 +1757,11 @@ if o.bindlist ~= "no" then -- wait for all other scripts to finish init mp.add_timeout(0, function() if o.bindlist:sub(1, 1) == "-" then - o.bindlist = o.bindlist:sub(2) o.no_ass_b0 = "" o.no_ass_b1 = "" end - local width = max(40, math.floor(tonumber(o.bindlist) or 79)) o.ass_formatting = false o.no_ass_indent = " " - o.term_size = { w = width , h = 0} mp.osd_message(keybinding_info(false, true)) -- wait for next tick to print status line and flush it without clearing mp.add_timeout(0, function()