erikgeiser / promptkit Goto Github PK
View Code? Open in Web Editor NEWGo prompt library
License: MIT License
Go prompt library
License: MIT License
Just a fanciful idea that would work so well for my personal project. I was wondering if you would be keen to consider that a possibility in the near future or if itβs possible to implement with what currently exists? π Thanks anyways
Thanks for this library. The README says:
Windows is currently not explicitly supported because input events are dropped when running multiple prompts sequentially due to a bug in bubbletea. See charmbracelet/bubbletea#140 and charmbracelet/bubbletea#121 for more information.
But it seems these issues have been resolved in bubbletea. Does that mean that Windows is now supported and the README should be updated? Or perhaps the bubbletea dependency needs a version bump?
I have a program with a large list of items and the initial list of choices shown is in a odd order. It corrects itself if I apply a filter or start arrowing through (however only the items that have been selected are fixed)
Here is my sample program and a video of the issue.
package main
import (
"fmt"
"log"
"strconv"
"github.com/erikgeiser/promptkit/selection"
)
func main() {
var choices []string
for i := 0; i < 100; i++ {
choices = append(choices, strconv.Itoa(i))
}
sel := selection.New("Select thingy:", choices)
choice, err := sel.RunPrompt()
if err != nil {
log.Fatal(err)
}
fmt.Println(choice)
}
Hello there
This library is listed as additional bubble here. This makes me wonder, is it possible to integrate promptkit in a bubbletea based application?
All tests in confirmation
and textinput
fail with newer termenv release.
termenv 0.13.0 is a dependency on newer bubbletea.
I noticed this while packaging prompkit for Fedora, as Fedora uses available dependency versions rather than versions declared in go.mod.
It would be nice to have a way to browse suggestions when AutoComplete
is used.
The autocomplete key binding could be used to browse through multiple suggestions and show them as possible values. One inspiration could be zsh where tabbing again will start to browse through possible suggestions.
Or a list could be shown below the input with cursor keys up/down scrolling through the results and enter accepting a suggestion as the current input.
when using windows older version like windows 10 2012
The example code for the selection is not working anymore. selection.New()
now takes a []*selection.Choice
instead of the displayed []string
.
I would suggest adjusting the selector example to:
choices := selection.Choices([]string{"Horse", "Car", "Plane", "Bike"})
sp := selection.New("What do you pick?", choices)
// ...
Thanks to you for creating this repo! It is very easy to use and opens the world for newbies to bubble tea. If needed, I can quickly create a PR.
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]
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"
)
type model struct {
selection *selection.Model[string]
}
func (m model) Init() tea.Cmd {
return m.selection.Init() // Bug: this returns tea.Quit when .choices is empty array.
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.selection.Err != nil {
panic(fmt.Sprintf("promptkit err: %v", m.selection.Err)) // race: sometimes enters this block
}
return m.selection.Update(msg)
}
func (m model) View() string {
if m.selection.Err != nil {
return fmt.Sprintf("promptkit err: %v", m.selection.Err) // never seems to enter this block
}
return m.selection.View()
}
func main() {
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!
How can I use the confirmation prompt as a bubbletea model?
Specifically, can confirmation.New()
return a tea.model?
Alternatively, I tried to do something like the following in my code but, validateKeyMap
is not exported.
type Model struct {
model *confirmation.Confirmation
result bool
err error
}
func NewConfirmationPrompt(prompt string) Model {
err := validateKeyMap(c.KeyMap)
if err != nil {
return false, fmt.Errorf("insufficient key map: %w", err)
}
m := NewModel(c)
return Model{
model: model,
err: nil,
}
}
Using this example
promptkit/examples/selection/main.go
Line 11 in 1f33bc7
I get
example.go:70:43: cannot use []string{β¦} (value of type []string) as type []*selection.Choice in argument to selection.New
request: add the text area component from the bubble tea examples
https://github.com/charmbracelet/bubbletea/blob/master/examples/textarea/main.go
charmbracelet/bubbles#341 leads to
β go run main.go
# github.com/erikgeiser/promptkit/selection
../../../go/pkg/mod/github.com/erikgeiser/[email protected]/selection/model.go:144:14: filterInput.BackgroundStyle undefined (type textinput.Model has no field or method BackgroundStyle)
Lines 27 to 30 in ac5b8e3
This snippet is checking for wrong types (T itself would be Choice[V] / *Choice[V] in this case, so we're effectively checking for Choice[Choice[V]], which I don't think was the intention). Return type of selection.RunPrompt is also similarly broken, which is again Choice[V] and not V, although that's not much of a problem in practice (an extra .Value).
Few possibilities to fix this off the top of my head:
The preview screen casts in the README.md
are not quite up to date and should be redone.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.