console.lua: truncate more characters with --msg-module and --msg-time

Fix the terminal width calculation for the select menu with these
options.
This commit is contained in:
Guido Cella 2024-09-15 09:12:54 +02:00 committed by Kacper Michajłow
parent b98d4fde0d
commit 8592206c75
1 changed files with 16 additions and 1 deletions

View File

@ -368,6 +368,21 @@ local function fuzzy_find(needle, haystacks)
return result
end
local function calculate_max_terminal_width()
local max_width = mp.get_property_native('term-size/w', 80)
-- The longest module name is vo/gpu-next/libplacebo.
if mp.get_property_native('msg-module') then
max_width = max_width - 24
end
if mp.get_property_native('msg-time') then
max_width = max_width - 13
end
return max_width
end
local function populate_log_with_matches(max_width)
if not selectable_items or selected_match == 0 then
return
@ -459,7 +474,7 @@ local function print_to_terminal()
return
end
populate_log_with_matches(mp.get_property_native('term-size/w', 80))
populate_log_with_matches(calculate_max_terminal_width())
local log = ''
for _, log_line in ipairs(log_buffers[id]) do