-
-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interaction with bubbletea #178
Comments
Thanks for the suggestion, @flowchartsman! It sounds interesting. How, specifically, do you think the |
So, thinking on it some more, the template execution solution is maybe a bit too "clever"; the mean idea is around inputs and template integration, where maybe you have something functions like Then you could do something like: newSource := InputForm("source",
inputStr("name", "Source Name"),
inputStr("topic", "Output Topic"),
inputSelect("sourcetype", "Source Type", "option1", "option2"))
script.Exec("pulsar-admin sources create --name {{form source name}} --destination-topic {{form source topic}} --type {{form source sourcetype}}").WriteFile("create_"+newSource["name"]+".log) Where user input can be accessed both through the You could even conceivably shorten the template portions by tracking a map of named inputs and creating a list of functions for accessing them on template execution so that it becomes script.Exec("pulsar-admin sources create --name {{source name}} --destination-topic {{source topic}} --type {{source sourcetype}}").WriteFile("create_"+newSource["name"]+".log) |
Yet another option would be a two-stage approach with multiple delimiter types, if you wanted to keep user inputs visually separate like: script.Exec("pulsar-admin sources create --name ${source name} --destination-topic ${source topic} --type ${source sourcetype}").WriteFile("create_"+newSource["name"]+".log) |
I think you could do something like your first example in three steps:
That's actually more general and flexible than prompting the user for inputs on the fly, isn't it—because then the data for the template could come from many different sources, of which interactive forms might be just one. One thing I'm having difficulty with is seeing where this interactive form-filling fits in with everything else that |
Yes, I think the template angle fits a bit more naturally for the "anywhere in the pipe" situation, though it's less in keeping with the functional-style shell pipe analogy, since it introduces side-effects. I'm am trying to think of any good examples from unixland where steps in a pipeline break out to ask for input, but I'm not actually coming up with any, which might be a good argument to have it apart from the pipeline. Having said that, if you think of this as a library that wants to provide a clean API to do things users might otherwise want to do with shell scripts, then interactivity is still useful to provide, since it's something a lot of users want to have in scripts, but avoid because the boilerplate to do it in a script is kind of a pain. In fact, when I was filing this issue, I was actually inpspired in part by the gum tool, which tries to bridge that gap, and lets script writers do things like So, while it might not have a home as a pipeline component (other than a source maybe?), interaction could find a place at initialization or between steps as a way to guide the flow of the "script".
It could certainly work as an add-on, but for my part I'd be more inclined to just wrap the package into one of my own to give me access to all of the tools at once, so that I could have a go-to dependency for most of the tasks of this type that I want to write. |
the other inspiration is that I wrote a tool recently to fill a similar niche to Then something in my memory clicked, and I remembered that Edit: I also wanted to add that I definitely see your point regarding the general pipeline nature of the library and keeping that core lean. So if you don't think this kind of extension has a place, no harm no foul. If anything, it can help clarify the mission statement about what is and what is not viable for the package. |
It seems clear that there's a fairly common general requirement for 'getting user input as part of a pipeline', even if that's as simple as 'press any key to continue', or as complex as 'select from the following interactive menu'. I'd like to invite some specific design proposals for this, from whoever's interested or has ideas. The best way to do this is probably to comment with a |
So I've been doing some Pulsar work recently, and one of the things I wanted to do was to select a list of pulsar connectors to download locally, from the archive site, first by selecting from the available versions, then by selecting from the available connector files. With a goquery PR, which I've been kicking around, that might look something like: const (
archiveURL = `https://archive.apache.org/dist/pulsar/`
connectorPfx = `https://archive.apache.org/dist/pulsar/pulsar-{{.}}/connectors/`
)
func main() {
pVersions := regexp.MustCompile(`pulsar-(?P<pversion>\d+\.\d+.\d+)/`)
script.Get(archiveURL).GoQuery(`a`).MatchRegexp(pVersions).ChooseOneFrom("{{.pversion}}").
Get(connectorPfx).GoQuery(`a`).ChooseAnyFrom("{{.}}").ExecForEach("curl -sLO {{.}}").Stdout()
} |
Sounds interesting! Perhaps we could prototype this with |
I'm absolutely down to give it a shot. Will probably need a couple weeks before some time frees up for OS work, but I'm happy to prototype an implementation! |
Perhaps similar in spirit to some aspects of #116, I think you could provide a set of simple, interactive inputs using TUI elements provided by bubbletea and bubbles. There are a couple of different approaches that you could take, or combine. A compelling one is a technique I saw used in chezmoi where templates receive a funcmap that provides functions which, when executed, create a bubbles widget on the fly and interpolate its value. Here's a quick (and dirty) prototype.
Example input/output
The text was updated successfully, but these errors were encountered: