manifoldco / promptui

Interactive prompt for command-line applications

Home Page:https://www.manifold.co

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using arrays or other data structures

mikyll opened this issue · comments

Hi! I'll start saying that your package is amazing and I found it pretty useful.

I was wondering: by any chance, is there a way to use a property of array type, inside the struct used for the items of the Select, and get a specific element from it?

Here's an example, extended from main.go:

type pepper struct {
	Name     string
	HeatUnit int
	Peppers  int
	ArrayValue [5]int  //<----- Array type property
}

func main() {
	[...]

	templates := &promptui.SelectTemplates{
		Label:    "{{ . }}?",
		Active:   "\U0001F336 {{ .Name | cyan }} ({{ .HeatUnit | red }})",
		Inactive: "  {{ .Name | cyan }} ({{ .HeatUnit | red }})",
		Selected: "\U0001F336 {{ .Name | red | cyan }}",
		Details: `
--------- Pepper ----------
{{ "Name:" | faint }}	{{ .Name }}
{{ "Heat Unit:" | faint }}	{{ .HeatUnit }}
{{ "Peppers:" | faint }}	{{ .Peppers }}`,
{{ "ArrayValueAt2:" | faint }}	{{ .ArrayValue[2] }}  //<----- something like this?
	}

	[...]
}

I searched a lot (even on text/template package), but couldn't find the answer. I also hope I've made it clear enough, my English isn't the best and I'm still learning 😅