-
Notifications
You must be signed in to change notification settings - Fork 274
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
Initial loading of Filepicker isn't working #564
Comments
After some debugging and having to pull the filepicker into my own project I found that I can resolve this issue in my code base by up dated the WindowSize msg check case tea.WindowSizeMsg:
if m.AutoHeight {
m.Height = msg.Height - marginBottom
}
m.max = m.Height - 1
if len(m.files) == 0 {
return m, m.readDir(m.CurrentDirectory, m.ShowHidden)
} This does not feel like the right solution. Overall seems that the readDirMsg isn't getting picked up in time as my WindowSizeMsg is begin the first thing I pick up in my logs even though I can see the Init function firing in my logs. Not sure what would be the best fix without understanding how the underlining system is processing the messages |
I have similar behavior, but render depends on number of page in my app. If I set picker page as first view I see:
but if I go to picker page from business logic flow (from main app menu page) I got this:
When I start any actions I had to make a hack to render any file list in my app like this: type modelPicker struct {
filepicker filepicker.Model
selectedFile string
quitting bool
err error
nextPage func()
nonFirstRender bool
}
func (m modelPicker) Init() tea.Cmd {
return nil
}
func (m modelPicker) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if !m.nonFirstRender {
m.nonFirstRender = true
cmd := m.filepicker.Init()
return m, cmd
}
...
} Maybe in your situation, as in mine, initial updates are not enough while pages changing... |
Resolve this problem with using interface: type Sender interface {
Send(tea.Msg)
}
type App struct {
pages []Page
Sender
} And when changing page (view) call goroutine func main() {
m, err := views.NewApp()
fatal(err)
p := tea.NewProgram(m, func(pp *tea.Program) {
m.Sender = pp
})
_, err = p.Run()
fatal(err)
} Model looks like this: type modelPicker struct {
filepicker filepicker.Model
selectedFile string
quitting bool
err error
nextPage func()
is1stUpdate bool
}
func newModelPicker(nextPage func()) modelPicker {
fp := filepicker.New()
return modelPicker{
filepicker: fp,
nextPage: nextPage,
is1stUpdate: true,
}
}
func NewPage(nextPage func()) *PickerPage {
return &PickerPage{newModelPicker(nextPage), 0, 0}
}
func (m modelPicker) Init() tea.Cmd {
return m.filepicker.Init()
}
func (m modelPicker) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.is1stUpdate {
m.is1stUpdate = false
return m, m.Init()
}
...
} |
Describe the bug
Working on a tui http client Muninn and I'm using the filepicker bubble to find the
.http
files on my system. Well when the application initialize I get a "no files found" this isn't the same behaivor I get when working on the example you guys have built. I've rewritten the example using all the same steps I use in my code and it produces list of directory as expected but if I copy that code into my code base it still shows "no files found".Setup
Please complete the following information along with version numbers, if applicable.
To Reproduce
Steps to reproduce the behavior:
go run main.go
h
to go back a directory and see that the filepicker is working fine from thereSource Code
Please include source code if needed to reproduce the behavior.
muninn filepicker:
/internal/tui/filepicker_view.go
Minimal standalone file
Expected behavior
When my application starts I expect the files and directories to appear just like the minimal example
Screenshots
What my application renders
What I expect it to render in the first box
The text was updated successfully, but these errors were encountered: