ui

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: Unlicense Imports: 5 Imported by: 0

README

ui

A minimal terminal UI library for Go — fuzzy menus, prompts, and multi-select, with no dependencies beyond golang.org/x/term.

Install

go get github.com/y-d-n-a/ui

Usage

Fuzzy Menu

Displays a searchable, single-select menu. Arrow keys navigate, typing filters, Enter confirms.

selected, err := ui.Run("Pick a fruit:", []ui.Option{
    {Label: "Apple", Value: "apple"},
    {Label: "Banana", Value: "banana"},
    {Label: "Cherry", Value: "cherry"},
})
if err != nil {
    log.Fatal(err)
}
fmt.Println(selected.Value)
Multi-Select Menu

Space toggles selection, Enter confirms. If nothing is toggled, Enter selects the current item.

selected, err := ui.RunMulti("Pick your toppings:", []ui.Option{
    {Label: "Cheese", Value: "cheese"},
    {Label: "Peppers", Value: "peppers"},
    {Label: "Olives", Value: "olives"},
})
if err != nil {
    log.Fatal(err)
}
for _, opt := range selected {
    fmt.Println(opt.Value)
}
Text Prompt
name, err := ui.Prompt("Your name:")
if err != nil {
    log.Fatal(err)
}
fmt.Println(name)
Secret Prompt

Input is masked with * characters.

pass, err := ui.PromptSecret("Password:")
if err != nil {
    log.Fatal(err)
}

API

type Option struct {
    Label string // displayed in the menu
    Value string // returned on selection
}

func Run(prompt string, options []Option) (Option, error)
func RunMulti(prompt string, options []Option) ([]Option, error)
func Prompt(label string) (string, error)
func PromptSecret(label string) (string, error)

Keybindings

Key Action
/ Move cursor
Type Filter options
Space Toggle (multi only)
Enter Confirm
Esc / Ctrl+C Cancel

Requirements

  • Go 1.19+
  • A real terminal (raw mode via golang.org/x/term)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Prompt

func Prompt(label string) (string, error)

Prompt asks the user to type a value with a label, returns the entered string.

func PromptSecret

func PromptSecret(label string) (string, error)

PromptSecret asks the user to type a value without echoing input to the terminal.

Types

type Option

type Option struct {
	Label string
	Value string
}

Option is a selectable menu item.

func Run

func Run(prompt string, options []Option) (Option, error)

Run displays an interactive fuzzy menu and returns the selected Option.

func RunMulti

func RunMulti(prompt string, options []Option) ([]Option, error)

RunMulti displays an interactive multi-select menu. The user toggles items with space and confirms with enter.

Jump to

Keyboard shortcuts

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