Git Product home page Git Product logo

promptkit's People

Contributors

erikgeiser avatar felixonmars avatar fiws avatar nemith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

promptkit's Issues

Multiple Selections

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

Is README outdated on Windows support?

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?

Init page of paged choices are in a weird order

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)

}
Screen.Recording.2023-06-01.at.4.57.44.PM.mov

Integrate with bubbletea

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?

Tests fail with github.com/muesli/termenv v0.13.0

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.

Allow to browse suggestions in textinput

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.

Selection example not up-to-date

What?

The example code for the selection is not working anymore. selection.New() now takes a []*selection.Choice instead of the displayed []string.

Fix

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.

selection widget fails silently on empty choice list

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"
)

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!

can't use confirmation prompt as a bubbletea model

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,
	}
}

selection.New(selection.Choice[T]) doesn't work

case Choice[T]:
choice.String = i.String
case *Choice[T]:
choice.String = i.String

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:

  1. Change Choice to implement Stringer and get rid of these cases (breaking change).
  2. Introduce another method similar to selection.New to only accept Choices.
  3. Change selection.New to only accept Choices and export asChoices to help other cases (breaking change).
  4. Use reflection to identify when T is a Choice (not sure if this is possible in a non hacky way)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.