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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址