-
I have answered my own question by looking through the github page and the website. The solution is at the bottom.. Hello, I'm trying to make a plugin in yazi using lua. I want to get input from the user and loop over all selected files (marked with space or any other method). This was my attempt: local M = {}
function M:entry()
local value, event = ya.input {
title = "Tag file",
position = { "center", w = 50 },
}
if event == 1 then
for idx, url in pairs(cx.yanked) do
ya.notify {
title = "you",
content = url.name,
timeout = 2,
}
end
end
end
return M But it can't run the loop after
What I actually want to do is for each selected file create a symlink using Edit: I got one step further! local M = {}
local tag_files = ya.sync(function(state)
local h = cx.active.current.hovered
if h then
ya.notify {
title = "tagged",
content = tostring(h.url),
timeout = 2,
}
end
for idx, url in pairs(cx.yanked) do
ya.notify {
title = "tagged",
content = tostring(url),
timeout = 2,
}
end
end)
function M:entry()
local value, event = ya.input {
title = "Tag file",
position = { "center", w = 50 },
}
if event == 1 then
tag_files()
end
end
return M This now works for the currently hovered file but not the selected files, but now I noticed that Edit2: I figured it out after viewing this, local folder = Folder:by_kind(Folder.CURRENT)
if not folder then
return
end
for i, f in ipairs(folder.window) do
local marker = File:marker(f)
if marker ~= 0 then
ya.notify {
title = "tagged",
content = tostring(f.url),
timeout = 2,
}
end
end |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It is not recommended to use
They both need to be used in a sync context. |
Beta Was this translation helpful? Give feedback.
It is not recommended to use
ipairs(folder.window)
since it needs to iterate over all files, which is inefficient and can only get the visible files in the window.cx.active.selected
cx.yanked
They both need to be used in a sync context.