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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions addons/find.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

local msg = require "mp.msg"
local fb = require "file-browser"
local input = require "user-input-module"
local input_loaded, input = pcall(require, "mp.input")
local user_input_loaded, user_input = pcall(require, "user-input-module")

local find = {
version = "1.3.0"
version = "1.4.0"
}
local latest_coroutine = nil
local global_fb_state = getmetatable(fb.get_state()).__original
Expand All @@ -35,9 +36,21 @@ local function main(key, state, co)
if key.name == "find/find" then text = "Find: enter search string"
else text = "Find: enter advanced search string" end

local query, error = coroutine.yield(
input.get_user_input( fb.coroutine.callback(), { text = text, id = "find", replace = true } )
)
local query, error = nil, nil
if input_loaded then
query = coroutine.yield(
input.get({
prompt = text .. "\n>",
id = "find",
submit = fb.coroutine.callback(),
})
)
input.terminate()
elseif user_input_loaded then
query, error = coroutine.yield(
user_input.get_user_input( fb.coroutine.callback(), { text = text, id = "find", replace = true } )
)
end

if not query then return msg.debug(error) end

Expand Down
18 changes: 15 additions & 3 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ local script_messages = require 'modules.script-messages'

-- setting the package paths
package.path = mp.command_native({"expand-path", o.module_directory}).."/?.lua;"..package.path
local user_input_loaded, input = pcall(require, "user-input-module")
local input_loaded, input = pcall(require, "mp.input")
local user_input_loaded, user_input = pcall(require, "user-input-module")


-- root and addon setup
setup.root()
Expand Down Expand Up @@ -51,8 +53,18 @@ mp.register_script_message("get-directory-contents", script_messages.get_directo
mp.add_key_binding('MENU','browse-files', controls.toggle)
mp.add_key_binding('Ctrl+o','open-browser', controls.open)

if user_input_loaded then
if input_loaded then
mp.add_key_binding("Alt+o", "browse-directory/get-user-input", function()
input.get({
prompt = "open directory:",
submit = function(text)
controls.browse_directory(text)
input.terminate()
end
})
end)
elseif user_input_loaded then
mp.add_key_binding("Alt+o", "browse-directory/get-user-input", function()
input.get_user_input(controls.browse_directory, {request_text = "open directory:"})
user_input.get_user_input(controls.browse_directory, {request_text = "open directory:"})
end)
end