#Making a bubbletea TUI View method generic for multiple inputs
18 messages · Page 1 of 1 (latest)
The different being what string is passed to it
So one possible solution is to use a slice of structs that are key/value
[{Title, View}, {Author, View}] etc
Sort of, yes
I did use slice intentionally, though, whereas dict would usually translate to map in go
Essentially, yes
So it might take a little restructuring on your part
But it would be something like
type Foo struct {
Label string
Input T // Where T is just some type that can use View()
}```
And then []Foo
Looks like model is some custom type anyways
so model.inputs would just be that slice type, possibly
Hmm
So looking at the example you sent, it looks like these are currently textinput.Models
You could always just use its Prompt field instead, maybe?
Hm?
You could ret += fmt.Sprintf("%s %s", prompt, view) or however that looks for your code
func Sprintf(format string, a ...any) string
Sprintf formats according to a format specifier and returns the resulting string.
Yeah, more or less. Not quite as nice as py interpolation, but not too bad