console.lua: use terminal_display_width when picking longest menu item
Previously this function would just count bytes which was very easily broken by incantations like `Ő̶̧͍̹͔̮̮̦͌̈̌̂́̊͜K͖̮̼̯͖͆͋̓̀̕` which take up 52 bytes while being just 2 normal width characters visually. `terminal_display_width` correctly counts `Ő̶̧͍̹͔̮̮̦͌̈̌̂́̊͜K͖̮̼̯͖͆͋̓̀̕` as 2 visual characters. Note: GitHub strips all these in their web UI but there are many Unicode combining characters after each letter of the `OK`s above that produce a "cursed" text effect. Fixes #17772
This commit is contained in:
1 parent
c202be1efe
commit
ac3b6044d0
2 files changed
+9
-2
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ You should have received a copy of the GNU Lesser General Public
|
||||
License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
||||
]]
|
||||
|
||||
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
|
||||
|
||||
|
||||
Reference in new issue
Block a user