Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select.lua: add this script #14087

Merged
merged 7 commits into from
May 12, 2024
Merged

select.lua: add this script #14087

merged 7 commits into from
May 12, 2024

Conversation

guidocella
Copy link
Contributor

This adds script messages to select playlist entries, tracks, chapters and subtitle lines using the newly introduced mp.input.select().

This fully closes #13964.

Copy link

github-actions bot commented May 8, 2024

Download the artifacts for this pull request:

Windows
macOS

@Hrxn
Copy link
Contributor

Hrxn commented May 8, 2024

Is this meant to replace https://github.com/guidocella/mpv-console-select, for example?

@guidocella
Copy link
Contributor Author

Yeah I just ported the code of that script.

@kasper93
Copy link
Contributor

kasper93 commented May 9, 2024

I think we could extend it with "command palette" style input. That would list all defined keybinds/commands and allow to select one of them. With common ctrl+p binding.

Also we could have ctrl+shift+p to search in all of the properties and on selection send it to console as set foo and let user complete. Or something along those lines. Or allow fuzzy search in console itself, somehow.

Additional, I'm personally not a big fan of g-*, I prefer modifiers in such cases. We already have F8 and F9 so they could be extended to ctrl+F8 and ctrl+F9 for selection instead of display. But I don't like the use of function keys either, so probably this would be only alternative to main keys.

EDIT:

I think this selection should be bigger. Changing all console maybe is not best like #14088, but track selection and things like that should have the same size as F9 for example. It is impossible to see anything if you use it in HTPC setup.

@guidocella
Copy link
Contributor Author

Added listings of bindings and properties and separate font and border sizes.

Additional, I'm personally not a big fan of g-*, I prefer modifiers in such cases. We already have F8 and F9 so they could be extended to ctrl+F8 and ctrl+F9 for selection instead of display. But I don't like the use of function keys either, so probably this would be only alternative to main keys.

I prefer key sequences for being easier to press and allowing mnemonic groupings and use around 30 of them. I already find F8 and F9 bindings bad because they're arbitrary and therefore hard to remember, and we already have 4 ctrl+letter keybindings including ctrl+c and ctrl+s. It would be inconsistent to have e.g. playlist selection on ctrl but not chapter selection on ctrl+c and sub-seek on ctrl+s. We also already have 7 of these select keybindings and may add more so only g sequences guarantee us available keys, so I think it is the only sane option.

@guidocella guidocella force-pushed the select branch 2 times, most recently from a7ab0f8 to 5e6de1a Compare May 9, 2024 21:29
@guidocella guidocella force-pushed the select branch 6 times, most recently from d71eb63 to c06650b Compare May 10, 2024 19:34
DOCS/man/console.rst Outdated Show resolved Hide resolved
DOCS/man/mpv.rst Outdated
Select a chapter.

g-s
Select a subtitle line to seek to. This requires ``ffmpeg`` in PATH, or in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this option. All those external subprocesses to just get subtitle list looks like a hack to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should implement it as a property later to remove the ffmpeg dependency. It's been discussed in #12810

Copy link
Contributor

@kasper93 kasper93 May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't reject this change, because I recognize value of searching subtitle, but I feel unease about subprocess running like that. I know it is common in scripts, but first party integration should be smarter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed but this is the best we can do until someone is willing to implement a property.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do cache subtitle packets now so the information is there. Of course, it can get dropped because of a sub track switch, etc.

DOCS/man/mpv.rst Outdated Show resolved Hide resolved
@guidocella guidocella force-pushed the select branch 2 times, most recently from be00189 to 541392d Compare May 11, 2024 08:50
player/lua/select.lua Outdated Show resolved Hide resolved
player/lua/select.lua Outdated Show resolved Hide resolved
player/lua/select.lua Outdated Show resolved Hide resolved
@guidocella guidocella force-pushed the select branch 2 times, most recently from 4212d6d to f419c40 Compare May 11, 2024 17:41
player/lua/select.lua Outdated Show resolved Hide resolved
@guidocella guidocella force-pushed the select branch 4 times, most recently from fec0c91 to 34e2d0e Compare May 12, 2024 06:55
I misunderstood CogentRedTester's review in
mpv-player#10282 (comment) as
referring to the cursor_position in mp.input's arguments instead of the
one received by the closed callback.

The cursor_position passed to input.get doesn't need to be converted to
a number because it was already JSON, while the cursor_position received
by the closed callback is currently a string, and we need to pass JSON
in input-event script messages to keep it as an integer to work around
mpv converting integer script message arguments to string.

This is more noticeable after implementing mp.input.select(): its submit
argument currently receives the selected index as a string, and this
makes Lua error if you use it as an index of a numerical table, e.g.:

submit = function (id)
    mp.set_property(property, tracks[tonumber(id)].selected and "no"
                              or tracks[tonumber(id)].id)
    ...
end,

This commit avoids having to call tonumber(id).
Avoid messing up the max_log_lines calculation when mp.input.select() is
called with very long items.

This doesn't work with Japanese characters because they are bigger.
selected_match can become 0 when pressing certain scrolling
keybindings without any match, and

for i = first_match_to_print, last_match_to_print do

in populate_log_with_matches() runs from 0 to 0 and accessing
matches[0].text crashes console.lua. Return early when it is 0.
With mp.input.select() these keybindings were both scrolling and moving
the cursor because of how the condition was written and
handle_pgup()/handle_pgdown() not returning a truthy value.
When you select an item, due to the submit handler being called
asynchronously, the default item list is redrawn before the console
closes, which is jarring. Fix this by always closing the console as soon
as enter is pressed, as keeping it open is unlikely to be useful with a
fuzzy selector (unlike with input.get() where it can be used e.g. to
implement a Lua REPL). If desired we can later add a close_on_submit
flag defaulting to true.

Also fix a crash when pressing enter without any match.
This adds script messages to select playlist entries, tracks, chapters,
subtitle lines, bindings and properties using the newly introduced
mp.input.select().

This fully closes mpv-player#13964.
Copy link
Contributor

@kasper93 kasper93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enough bikeshedding, let's get this in.

@kasper93 kasper93 merged commit 61f72bd into mpv-player:master May 12, 2024
19 checks passed
@guidocella guidocella deleted the select branch May 12, 2024 21:23
@verygoodlee
Copy link
Contributor

verygoodlee commented May 14, 2024

run script-binding select/* command in console takes no effect, you must write the console close command manually,
script-message-to console disable; script-binding select/select-playlist
I think we should auto close console.

@guidocella
Copy link
Contributor Author

This was shot down in #10282 (comment)

@Hrxn
Copy link
Contributor

Hrxn commented May 14, 2024

Just tested this a bit, works as described. I really like it so far.

But this is a feature change, should probably be mentioned somewhat prominently in the changelog. Alone for the fact that it uses a keybind (g) that was already bound by users (like me).

The chord-style input (g+..) works really well, though, definitely a good idea.

@verygoodlee
Copy link
Contributor

why is there no selected style in playlist, even though the current playing file is default item when opened, it's easy to forget which one is currently playing after searching and scrolling.

@Hrxn
Copy link
Contributor

Hrxn commented May 14, 2024

@verygoodlee What do you mean? The marked entry has been highlighted for me.

Which build are you using, exactly?

@verygoodlee
Copy link
Contributor

verygoodlee commented May 14, 2024

I mean this selected style
屏幕截图 2024-05-15 024647

In playlist I don't know which one is currently playing
image

@guidocella
Copy link
Contributor Author

It's a bit noisy to have circles everywhere when the playing entry is already preselected, and it wouldn't be helpful after searching because the original order is not restored if you delete the input string anyway (though this can be easily changed). More opinions are needed on whether we want to add the circles.

@verygoodlee
Copy link
Contributor

another question, is it necessary to observe property changes during menu opening.
example: during the track selection menu open, current file reached EOF and next file automatically plays, the track items are not updated, is it necessary to update it.

@guidocella
Copy link
Contributor Author

I don't think that's necessary.

guidocella added a commit to guidocella/mpv that referenced this pull request Oct 9, 2024
Requested in
mpv-player#14087 (comment) and
mpv-player#15031 (comment)

This is mainly useful to keep highlighting the current playlist entry
after moving the mouse.
@guidocella guidocella mentioned this pull request Oct 9, 2024
guidocella added a commit to guidocella/mpv that referenced this pull request Oct 9, 2024
Requested in
mpv-player#14087 (comment) and
mpv-player#15031 (comment)

This is mainly useful to keep highlighting the current playlist entry
after moving the mouse.
guidocella added a commit to guidocella/mpv that referenced this pull request Oct 9, 2024
Requested in
mpv-player#14087 (comment) and
mpv-player#15031 (comment)

This is mainly useful to keep highlighting the current playlist entry
after moving the mouse.
guidocella added a commit to guidocella/mpv that referenced this pull request Oct 9, 2024
Requested in
mpv-player#14087 (comment) and
mpv-player#15031 (comment)

This is mainly useful to keep highlighting the current playlist entry
after moving the mouse.
guidocella added a commit to guidocella/mpv that referenced this pull request Oct 10, 2024
Requested in
mpv-player#14087 (comment) and
mpv-player#15031 (comment)

This is mainly useful to keep highlighting the current playlist entry
after moving the mouse.
guidocella added a commit to guidocella/mpv that referenced this pull request Oct 11, 2024
Requested in
mpv-player#14087 (comment) and
mpv-player#15031 (comment)

This is mainly useful to keep highlighting the current playlist entry
after moving the mouse.
kasper93 pushed a commit that referenced this pull request Oct 14, 2024
Requested in
#14087 (comment) and
#15031 (comment)

This is mainly useful to keep highlighting the current playlist entry
after moving the mouse.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support built-in command palette script/API (a searchable menu)
6 participants