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

add support for mpv internal mp.input function #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dyphire
Copy link
Contributor

@dyphire dyphire commented Sep 8, 2024

ref #111

addons/find.lua Outdated Show resolved Hide resolved
addons/find.lua Outdated Show resolved Hide resolved
addons/find.lua Outdated
input.get_user_input( fb.coroutine.callback(), { text = text, id = "find", replace = true } )
)
elseif input then
query, error = coroutine.yield(
Copy link
Owner

Choose a reason for hiding this comment

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

Call input.terminate() before this to ensure there is not another input already active. If another input is active, then console.lua will abort the input.get request without any feedback. That means our coroutine would never be resumed, causing a memory leak.

Copy link
Owner

@CogentRedTester CogentRedTester Sep 14, 2024

Choose a reason for hiding this comment

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

Alternatively, you could use the new coroutine.callback() behaviour I'm adding in #113:

    input.get({
        prompt = text .. "\n>",
        id = "find",
        opened = fb.coroutine.callback(1.5),
        submit = fb.coroutine.callback(),
    })

    local console_opened = coroutine.yield()
    if not console_opened then return msg.warn('failed to open mp.input') end
    local query = coroutine.yield()
    input.terminate()

Copy link
Owner

Choose a reason for hiding this comment

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

Upon inspecting the mp.input code it appears that mp.input discards all the old callbacks when a new input.get request is created. This should discard the callback, which should discard the reference to the coroutine, and hence mean no memory leak. But you may still want to add a timeout to opened to provide a useful error message.

addons/find.lua Outdated Show resolved Hide resolved
main.lua Outdated Show resolved Hide resolved
main.lua Outdated Show resolved Hide resolved
main.lua Outdated Show resolved Hide resolved
Comment on lines 13 to 16
local success, input = pcall(require, 'mp.input')
if not success then
user_input_loaded, input = pcall(require, "user-input-module")
end
Copy link
Owner

Choose a reason for hiding this comment

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

This breaks the keybind expressions that use the input field because they won't know which module is being used. The run-statement example would break for instance. I'm happy for you to replace input in the expressions with the new mpv.input for future compatibility, but mpv-user-input still needs to be provided, perhaps through a user_input variable instead (here). The documentation will also need to be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't notice this usage before, undo change.

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.

2 participants