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

feat: expose file creation API #2062

Closed

Conversation

hankertrix
Copy link
Contributor

Follow up to #1777.

I need some guidance on the last point regarding the file handler interoperating with other APIs. The code currently doesn't compile as I'm not really sure what to return or how to design this return value of the open function.

Closes #1709.

@hankertrix
Copy link
Contributor Author

hankertrix commented Dec 18, 2024

@sxyazi What do you think of the bit flags parameter as the options for the open function? Would you rather use a Lua table?

Also, the return value of the open function currently just returns a Yazi File object, as I am not sure how to design a separate structure to interop with the Command plugin API.

On second thought, would the open function be considered unnecessary? Lua already has an io.open function to create files which supports everything from OpenOptions except truncate mode.

I think the main thing for plugin developers is the ability to create directories, which is implemented in the create_dir function, as Lua doesn't implement any built-in method to create directories.

@sxyazi
Copy link
Owner

sxyazi commented Dec 19, 2024

Thanks for the PR!

On second thought, would the open function be considered unnecessary? Lua already has an io.open function to create files which supports everything from OpenOptions except truncate mode.

Yeah, Lua already provides io.open(), so reimplementing it in Yazi doesn't seem to be a high priority, how do you feel about separating the fs.open() part from this PR into a standalone one? That way, we can quickly merge fs.create_dir(), while I still have some details I want to discuss about fs.open(), I need to think more about the API design.

Or, if io.open() already meets your needs and fs.open() is no longer valuable to you, you can just discard it. I'll revisit how to add it when I have some time.

@hankertrix
Copy link
Contributor Author

Yeah, Lua already provides io.open(), so reimplementing it in Yazi doesn't seem to be a high priority, how do you feel about separating the fs.open() part from this PR into a standalone one?

Oh yeah, that would be great. I'll do that.

I need to think more about the API design.

Sure thing, no worries!

@hankertrix hankertrix changed the title feat: expose file and directory creation APIs feat: expose file creation API Dec 19, 2024
@hankertrix hankertrix force-pushed the expose-file-and-dir-creation branch from 88a44d5 to 30ceab7 Compare December 19, 2024 18:31
@hankertrix hankertrix closed this Dec 19, 2024
@hankertrix hankertrix deleted the expose-file-and-dir-creation branch December 19, 2024 18:33
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.

Expose file and directory creation to plugin developers as part of fs
2 participants