gocliselect

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2024 License: MIT Imports: 5 Imported by: 0

README

Golang CLI Select

Fork of https://github.com/Nexidian/gocliselect

In this fork I implemented submenu options so the items can be in a nested structure + some configuration options for cursor and colors.

Examples

examples/simple/main.go

examples/advanced/main.go

Known issues

Text flickering

Happening in iterm2 only. My guess is codes clearing the content are the cause.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cursor = CursorConfig{
	ItemColor:        goterm.YELLOW,
	ItemPrompt:       ">",
	SubMenuColor:     goterm.YELLOW,
	SubMenuPrompt:    ">",
	Suffix:           "  ",
	IndentMultiplier: 4,
}

Functions

This section is empty.

Types

type CursorConfig

type CursorConfig struct {
	ItemColor        int
	ItemPrompt       string
	SubMenuColor     int
	SubMenuPrompt    string
	Suffix           string
	IndentMultiplier int
}
type Menu struct {
	Prompt     string
	CursorPos  int
	Level      int // TODO ideally this is computed on the fly
	MenuItems  []*MenuItem
	ParentMenu *Menu
}

func NewMenu

func NewMenu(prompt string, level int) *Menu
func (m *Menu) AddItem(option string, id string) *Menu

AddItem will add a new item

func (m *Menu) AddItemMenu(option string, id string, subMenu *Menu) *Menu

AddItemMenu will add a new item menu

func (m *Menu) Display(root *Menu) (*Menu, *MenuItem)

Display will display the given menu and awaits user selection It returns the users selected choice and the choice's menu

func (m *Menu) RenderMenu(root *Menu)
type MenuItem struct {
	Text    string
	ID      string
	SubMenu *Menu
}

Directories

Path Synopsis
examples
advanced command
simple command

Jump to

Keyboard shortcuts

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