You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
OS: Pop-os
Shell: Fish
Terminal Emulator: Alacritty
Terminal Multiplexer: Zellij
Locale: en_US.UTF-8
To Reproduce
Steps to reproduce the behavior:
Clone Muninn
Start muninn go run main.go
Notice that it shows the filepicker is empty
Hit h to go back a directory and see that the filepicker is working fine from there
Source Code
Please include source code if needed to reproduce the behavior.
muninn filepicker: /internal/tui/filepicker_view.go
package tui
import (
"errors""strings""time""github.com/charmbracelet/bubbles/filepicker"
tea "github.com/charmbracelet/bubbletea"
)
typeclearErrorMsgstruct{}
funcclearErrorAfter(t time.Duration) tea.Cmd {
returntea.Tick(t, func(_ time.Time) tea.Msg {
returnclearErrorMsg{}
})
}
typefilepickerModelstruct {
picker filepicker.Modelselectedstringquittingboolerrerror
}
funcinitFilepicker(pathstring) filepickerModel {
fp:=filepicker.New()
fp.AllowedTypes= []string{".http"}
fp.CurrentDirectory=pathfp.ShowPermissions=falsefp.ShowSize=falsefp.AutoHeight=falsereturnfilepickerModel{
picker: fp,
}
}
func (mfilepickerModel) Init() tea.Cmd {
returnm.picker.Init()
}
func (mfilepickerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switchmsg:=msg.(type) {
case tea.WindowSizeMsg:
m.picker.Height=msg.Height/4case tea.KeyMsg:
switchmsg.String() {
case"ctrl+c", "q":
m.quitting=truereturnm, tea.Quit
}
caseclearErrorMsg:
m.err=nil
}
varcmd tea.Cmdm.picker, cmd=m.picker.Update(msg)
// Did the user select a file?ifdidSelect, path:=m.picker.DidSelectFile(msg); didSelect {
// Get the path of the selected file.m.selected=path
}
// Did the user select a disabled file?// This is only necessary to display an error to the user.ifdidSelect, path:=m.picker.DidSelectDisabledFile(msg); didSelect {
// Let's clear the selectedFile and display an error.m.err=errors.New(path+" is not valid.")
m.selected=""returnm, tea.Batch(cmd, clearErrorAfter(2*time.Second))
}
returnm, cmd
}
func (mfilepickerModel) View() string {
ifm.quitting {
return""
}
vars strings.Builders.WriteString("\n ")
ifm.err!=nil {
s.WriteString(m.picker.Styles.DisabledFile.Render(m.err.Error()))
} elseifm.selected=="" {
s.WriteString("Pick a file:")
} else {
s.WriteString("Selected file: "+m.picker.Styles.Selected.Render(m.selected))
}
s.WriteString("\n\n"+m.picker.View() +"\n")
returns.String()
}
Minimal standalone file
package main
import (
"errors""fmt""os""strings""time""github.com/charmbracelet/bubbles/filepicker"
tea "github.com/charmbracelet/bubbletea"
)
typemodelstruct {
filepicker filepicker.ModelselectedFilestringquittingboolerrerror
}
typeclearErrorMsgstruct{}
funcclearErrorAfter(t time.Duration) tea.Cmd {
returntea.Tick(t, func(_ time.Time) tea.Msg {
returnclearErrorMsg{}
})
}
func (mmodel) Init() tea.Cmd {
returnm.filepicker.Init()
}
func (mmodel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switchmsg:=msg.(type) {
case tea.WindowSizeMsg:
m.filepicker.Height=msg.Height/4case tea.KeyMsg:
switchmsg.String() {
case"ctrl+c", "q":
m.quitting=truereturnm, tea.Quit
}
caseclearErrorMsg:
m.err=nil
}
varcmd tea.Cmdm.filepicker, cmd=m.filepicker.Update(msg)
// Did the user select a file?ifdidSelect, path:=m.filepicker.DidSelectFile(msg); didSelect {
// Get the path of the selected file.m.selectedFile=path
}
// Did the user select a disabled file?// This is only necessary to display an error to the user.ifdidSelect, path:=m.filepicker.DidSelectDisabledFile(msg); didSelect {
// Let's clear the selectedFile and display an error.m.err=errors.New(path+" is not valid.")
m.selectedFile=""returnm, tea.Batch(cmd, clearErrorAfter(2*time.Second))
}
returnm, cmd
}
func (mmodel) View() string {
ifm.quitting {
return""
}
vars strings.Builders.WriteString("\n ")
ifm.err!=nil {
s.WriteString(m.filepicker.Styles.DisabledFile.Render(m.err.Error()))
} elseifm.selectedFile=="" {
s.WriteString("Pick a file:")
} else {
s.WriteString("Selected file: "+m.filepicker.Styles.Selected.Render(m.selectedFile))
}
s.WriteString("\n\n"+m.filepicker.View() +"\n")
returns.String()
}
funcmain() {
fp:=filepicker.New()
path, _:=os.UserHomeDir()
fp.AllowedTypes= []string{".http"}
fp.CurrentDirectory=pathfp.ShowPermissions=falsefp.ShowSize=falsefp.AutoHeight=falsem:=model{
filepicker: fp,
}
tm, _:=tea.NewProgram(&m).Run()
mm:=tm.(model)
fmt.Println("\n You selected: "+m.filepicker.Styles.Selected.Render(mm.selectedFile) +"\n")
}
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:
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
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
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: