Skip to content

feat(filepicker): add support for abstracted filesystem io/fs.FS#759

Closed
dolmen wants to merge 1 commit into
charmbracelet:masterfrom
dolmen-go:filepicker-add-support-for-fs.FS
Closed

feat(filepicker): add support for abstracted filesystem io/fs.FS#759
dolmen wants to merge 1 commit into
charmbracelet:masterfrom
dolmen-go:filepicker-add-support-for-fs.FS

Conversation

@dolmen
Copy link
Copy Markdown

@dolmen dolmen commented Mar 26, 2025

Add an optional io/fs.FS to filepicker's model to allow to browse an abstracted filesystem as an alternative to the full filesystem exposed by the os package.

The filepicker API is extended (and generalized thanks to io/fs.FS), without any breaking change.

This allows for example to browse limited a subdirectory by using os.Root (go1.24+):

fp := filepicker.New()
root, _ := os.OpenRoot(dir)
fp.FS = root.FS()

Note that Go 1.25 will add io/fs.ReadLink, but we can't use it yet. So we implement symlink resolution here.

By the way, references to os types and constants which are aliases to same symbols in io/fs are replaced: os.Mode*, os.DirEntry.

Example

See package github.com/dolmen-go/iofs-shell.

Runnable example:

$ go run github.com/dolmen-go/iofs-shell/examples/browse-zip <file>.zip

@dolmen dolmen requested a review from bashbunni as a code owner March 26, 2025 00:48
@dolmen dolmen changed the title filepicker: add support for abstracted filesystem io/fs.FS feat(filepicker): add support for abstracted filesystem io/fs.FS Mar 26, 2025
@dolmen dolmen force-pushed the filepicker-add-support-for-fs.FS branch from 5646902 to a0d6cf8 Compare March 26, 2025 00:57
dolmen added a commit to dolmen-go/iofs-shell that referenced this pull request Apr 1, 2025
This requires so far my fork of bubbles/filepicker that allows to browse
an io/fs.FS (see charmbracelet/bubbles#759).
@dolmen
Copy link
Copy Markdown
Author

dolmen commented Apr 1, 2025

Cc: @maaslalani (filepicker original author) for review

@dolmen
Copy link
Copy Markdown
Author

dolmen commented May 26, 2025

Cc: @meowgorithm for review

Add an optional io/fs.FS to filepicker's model to allow to browse an
abstracted filesystem instead of the full filesystem exposed by the 'os'
package.

Note that Go 1.25 will add io/fs.ReadLink, but we can't use it yet. So
we implement symlink resolution here.

By the way, references to os types and constants which are aliases to
same symbols in io/fs are replaced: os.Mode*, os.DirEntry.
@dolmen dolmen force-pushed the filepicker-add-support-for-fs.FS branch from a0d6cf8 to 2d5bdfa Compare April 13, 2026 10:24
dolmen added a commit to dolmen-go/bubbles.fork that referenced this pull request Apr 13, 2026
Add an optional io/fs.FS to filepicker's model to allow to browse an
abstracted filesystem instead of the full filesystem exposed by the 'os'
package.

To resolve symlinks we use io/fs.ReadLink introduced with Go 1.25, but
fallback to an internal implementation if the FS doesn't implement it.

By the way, references to os types and constants (which nowadays are
aliases to same symbols in io/fs) are replaced: os.Mode*, os.DirEntry.

Fixes charmbracelet#815.
Replaces charmbracelet#759.
dolmen added a commit to dolmen-go/bubbles.fork that referenced this pull request Apr 13, 2026
Add an optional io/fs.FS to filepicker's model to allow to browse an
abstracted filesystem instead of the full filesystem exposed by the 'os'
package.

To resolve symlinks we use io/fs.ReadLink introduced with Go 1.25, but
fallback to an internal implementation if the FS doesn't implement it.

By the way, references to os types and constants (which nowadays are
aliases to same symbols in io/fs) are replaced: os.Mode*, os.DirEntry.

Fixes charmbracelet#815.
Replaces charmbracelet#759.
@dolmen
Copy link
Copy Markdown
Author

dolmen commented Apr 13, 2026

Closing because replaced by #954 upgraded to v2 API.

@dolmen dolmen closed this Apr 13, 2026
dolmen added a commit to dolmen-go/bubbles.fork that referenced this pull request May 11, 2026
Add an optional io/fs.FS to filepicker's model to allow to browse an
abstracted filesystem instead of the full filesystem exposed by the 'os'
package.

To resolve symlinks we use io/fs.ReadLink introduced with Go 1.25, but
fallback to an internal implementation if the FS doesn't implement it.

By the way, references to os types and constants (which nowadays are
aliases to same symbols in io/fs) are replaced: os.Mode*, os.DirEntry.

Fixes charmbracelet#815.
Replaces charmbracelet#759.
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.

1 participant