Skip to content
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

Using arrays or other data structures #198

Open
mikyll opened this issue Jan 8, 2022 · 0 comments
Open

Using arrays or other data structures #198

mikyll opened this issue Jan 8, 2022 · 0 comments

Comments

@mikyll
Copy link

mikyll commented Jan 8, 2022

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 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant