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
When the choices array is empty, selection.Model.Init() sets an error and returns tea.Quit. The error state cannot be reliably reacted to in Update or View because there seems to be a race condition in BubbleTea where sometimes the program exits before Update or View is called.
It would be helpful if the following behaviors were described in the documentation on selection.New, selection.NewModel, and Model.Init():
Init() will return tea.Quit if choices is empty. This was very time consuming to track down.
The widget requires a non-empty array of choices.
In composed models where the set of choices might be empty, the lifecycle of the selection widget should not be managed via the Init() method of the parent model, unless early termination of the program is desirable.
Also, the program hangs forever if the model.selection field is changed from *selection.Model[string] to selection.Model[string]. This is surprising.
This program, run multiple times with debug build, demonstrates the race and the exit:
package main
import (
"fmt"
tea "github.com/charmbracelet/bubbletea""github.com/erikgeiser/promptkit/selection"
)
typemodelstruct {
selection*selection.Model[string]
}
func (mmodel) Init() tea.Cmd {
returnm.selection.Init() // Bug: this returns tea.Quit when .choices is empty array.
}
func (mmodel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
ifm.selection.Err!=nil {
panic(fmt.Sprintf("promptkit err: %v", m.selection.Err)) // race: sometimes enters this block
}
returnm.selection.Update(msg)
}
func (mmodel) View() string {
ifm.selection.Err!=nil {
returnfmt.Sprintf("promptkit err: %v", m.selection.Err) // never seems to enter this block
}
returnm.selection.View()
}
funcmain() {
mySelection:=selection.New("Prompt", []string{})
mySelectionModel:=selection.NewModel(mySelection)
myModel:=model{
selection: mySelectionModel,
}
p:=tea.NewProgram(myModel)
if_, err:=p.Run(); err!=nil {
panic(err)
}
}
Thanks!
The text was updated successfully, but these errors were encountered:
When the choices array is empty, selection.Model.Init() sets an error and returns tea.Quit. The error state cannot be reliably reacted to in Update or View because there seems to be a race condition in BubbleTea where sometimes the program exits before Update or View is called.
It would be helpful if the following behaviors were described in the documentation on selection.New, selection.NewModel, and Model.Init():
Also, the program hangs forever if the model.selection field is changed from
*selection.Model[string]
toselection.Model[string]
. This is surprising.This program, run multiple times with debug build, demonstrates the race and the exit:
Thanks!
The text was updated successfully, but these errors were encountered: