-
Notifications
You must be signed in to change notification settings - Fork 497
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
feat: add ya.clipboard()
Lua API
#980
Conversation
102f614
to
bd57bfc
Compare
Thank you! Please move the |
This needs to be done because we want to make it possible to use the clipboard in lua plugins. Before this change, the clipboard was only available in the yazi-core crate, which depends on yazi-plugin. The lua plugins are configured in the yazi-plugin crate, but it can't use anything from yazi-core, because it would create a circular dependency.
It allows accessing the clipboard content as well as setting it. ```lua -- get contents of the clipboard local content = ya.clipboard() -- set contents of the clipboard ya.clipboard("new clipboard content") ```
bd57bfc
to
c606e7f
Compare
Ok, that is now done. I'll try to write a test plugin to verify this works in lua, next. |
I was able to test setting the clipboard and that works fine. I had trouble testing getting the clipboard contents, however. I think I don't have a deep enough understanding of yazi plugins to solve this yet. Would you have the time to take a look? -- /Users/mikavilpas/.config/yazi/plugins/clipboard-test.yazi/init.lua
return {
entry = function(_, args)
-- test setting the clipboard
--
local input = ya.input({
title = "give me some input",
position = { "top-center", y = 3, w = 40 },
})
ya.clipboard(input)
-- test getting the clipboard
--
-- TODO this does not work as expected
ya.dbg("testing clipboard")
local contents = ya.clipboard()
ya.dbg("The clipboard contents are: " .. contents)
end,
} |
Just tested it, and it works great! 👍🏻 (Since it's an async function, so it needs to be ran in an async context, i.e. I think we can merge it now. |
ya.clipboard()
lua apiya.clipboard()
Lua API
Co-authored-by: sxyazi <[email protected]>
ya.clipboard()
Lua APIya.clipboard()
Lua API
Oh, I see. Do you think this case could be detected, and a warning could be logged, for example? |
Do you mean detecting when async functions are called in a sync context? If so it would throw an error that shows up in the log file. |
Ok, gotcha! I don't remember if I saw it in the log file or not, but I will keep my eyes on that in the future 🙂 |
Fixes #964
It allows accessing the clipboard content as well as setting it.
Note: I moved the clipboard to a different crate because of circular dependency issues. Here's the commit message:
I should still look into testing this with the lua plugin api, so I'll keep this as a draft for now.