goprettycli

package module
v0.0.0-...-255528c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2023 License: MIT Imports: 2 Imported by: 0

README

go-pretty-cli

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Choice

func Choice(choices []ChoiceStruct) string

**SINGLE CHOICE**

let the user select one choice with the arrow keys confirm with enter

Returns the id of the selected choice as a string

Example: selected := Choice(

[]ChoiceStruct{
	{
		choice: "Choice 1",
		id:     "1",
	},
	{
		choice: "Choice 2",
		id:     "2",
	},
	{
		choice: "Choice 3",
		id:     "3",
	},
},

)

fmt.Println(selected) // ["1"]

func MultipleChoice

func MultipleChoice(choices []MultipleChoiceStruct, forceResult bool) []string

**MULTIPLE CHOICE**

lets the user select multiple choices with the spacebar confirm with enter

Returns a slice of the selected choices Example: selected := Choice(

[]ChoiceStruct{
	{
		choice: "Choice 1",
		id:     "1",
	},
	{
		choice: "Choice 2",
		id:     "2",
	},
	{
		choice: "Choice 3",
		id:     "3",
	},
},

// forceResult
// if true, the user has to select at least one choice, otherwise it won't return
false,

)

fmt.Println(selected) // ["1", "3"]

Types

type ChoiceStruct

type ChoiceStruct struct {
	// choice is the text that will be displayed
	Choice string

	// id is the value that will be returned
	// its also used to run the function, make sure its unique
	Id string
}

type MultipleChoiceStruct

type MultipleChoiceStruct struct {
	// choice is the text that will be displayed
	Choice string

	// id is the value that will be returned
	// its also used to run the function, make sure its unique
	Id string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL