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: ? 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

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