diff --git a/player/lua/console.lua b/player/lua/console.lua index d290fb5900..eeffc0b3ee 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -348,9 +348,12 @@ local function calculate_max_item_width() end local longest_item = prompt .. ("a"):rep(9) + local longest_item_width = utils.terminal_display_width(longest_item) for _, item in pairs(selectable_items) do - if #item > #longest_item then + local item_width = utils.terminal_display_width(item) + if item_width > longest_item_width then longest_item = item + longest_item_width = item_width end end diff --git a/player/lua/context_menu.lua b/player/lua/context_menu.lua index bdefe1713c..42de36cd12 100644 --- a/player/lua/context_menu.lua +++ b/player/lua/context_menu.lua @@ -15,6 +15,7 @@ You should have received a copy of the GNU Lesser General Public License along with mpv. If not, see . ]] +local utils = require "mp.utils" local assdraw = require "mp.assdraw" local options = { @@ -157,9 +158,12 @@ local function calculate_width(menu_items, osd_w, osd_h, checkbox) end local longest = "" + local longest_width = 0 for _, title in pairs(titles) do - if #title > #longest then + local title_width = utils.terminal_display_width(title) + if title_width > longest_width then longest = title + longest_width = title_width end end