`input.select()` menu items with leading spaces cause the end of menu items to be cut off
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 37k
- Forks
- 3.5k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 22
Description
mpv Information
mpv v0.40.0-dirty Copyright © 2000-2025 mpv/MPlayer/mplayer2 projects
built on Jul 29 2025 22:35:55
libplacebo version: v7.351.0
FFmpeg version: n7.1.1
FFmpeg library versions:
libavcodec 61.19.101
libavdevice 61.3.100
libavfilter 10.4.100
libavformat 61.7.100
libavutil 59.39.100
libswresample 5.3.100
libswscale 8.3.100
Other Information
- Linux version: EndeavourOS
- Source of mpv: https://archlinux.org/packages/extra/x86_64/mpv/
Reproduction Steps
Note: I initially created a discussion (Issues with presentation of items passed to input.select) and based on responses, I thought that it was more correct to raise this as an issue. The discussion does include some additional context for testing that has been done.
I don't know if this issue is OS-dependent, but if it's using the internal scripts, I assume this issue would be OS-agnostic.
The key issue noted in the discussion shows that testing with a basic input.select script where spaces are used at the start of lines as an alignment mechanism, part of the end of the text of menu items is being cut-off. Opening the menu via a binding from the following code:
local input = require "mp.input"
mp.add_key_binding(nil, "testmenu", function ()
input.select({
prompt = "",
items = {" Test", " Test this"},
})
end)
Results in text being cutoff visually:
A possible fix was provided by @verygoodlee in the discussion (https://github.com/mpv-player/mpv/discussions/16275#discussioncomment-12976082) with a suggested change to console.lua specifically the calculate_max_item_width() function, adding an underline when calculating the width (diff hunk header adjusted for master):
@@ -337,7 +337,7 @@ local function calculate_max_item_width()
width_overlay.res_x = osd_w
width_overlay.res_y = osd_h
width_overlay.data = "{\\fs" .. opts.font_size ..
- (font and "\\fn" .. font or "") .. "\\q2}" ..
+ (font and "\\fn" .. font or "") .. "\\q2\\u1}" ..
ass_escape(longest_item)
local result = width_overlay:update()
max_item_width = math.min(result.x1 - result.x0,
I've tested this by patching mpv myself (based on the distro-provided build files) and it works as expected, with the menu items showing correctly and my current workaround of adding extra characters at the end of the menu items no longer being required.
I wanted to check if this is the correct approach to fix this issue or if there are likely to be any unintended side-effects of doing this.
Expected Behavior
Menu items are not cut off.
Actual Behavior
Menu items are cut off.
Log File
N/A
Sample Files
N/A
I carefully read all instruction and confirm that I did the following:
- I tested with the latest mpv version to validate that the issue is not already fixed.
- I provided all required information including system and mpv version.
- I produced the log file with the exact same set of files, parameters, and conditions used in "Reproduction Steps", with the addition of
--log-file=output.txt. - I produced the log file while the behaviors described in "Actual Behavior" were actively observed.
- I attached the full, untruncated log file.
- I attached the backtrace in the case of a crash.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in console.lua at calculate_max_item_width(), then reproduce the issue with the provided input.select Lua script and menu items with leading spaces. Check how the overlay measures the longest item and verify that the completed change displays the full menu-item text without requiring trailing padding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100