menu

package
v0.0.0-...-b25b90c Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package menu renders the interactive boot-time chooser shown by cloud-boot-init before kexec. The menu lists every eligible plan target, prints a countdown, and reads a single line from the console. On timeout or empty input the default target wins.

Input grammar is deliberately tiny so the operator can pick a target with minimal typing on a serial console:

<empty>          → default
<number>         → 1-based index into the displayed options
<name>           → exact match against Target.Name (case-insensitive)
<name prefix>    → unambiguous prefix match against Target.Name

The menu does NOT manipulate the terminal mode (no raw / no-echo): line buffering plus Enter is good enough for an initramfs console, costs no portability surface, and lets the operator correct a typo with backspace.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Prompt

func Prompt(cfg Config) (string, error)

Prompt renders the menu and blocks until the operator picks an option or the timeout fires. The returned string is one of the Option.Name values.

Errors are reserved for "I/O on Out failed" — bad operator input loops back to the prompt rather than aborting the boot.

Types

type Config

type Config struct {
	Out     io.Writer
	In      io.Reader
	Prompt  string        // header line; defaults to "Select a boot target:"
	Timeout time.Duration // wall-clock budget before auto-selecting default
	Default string        // Option.Name returned on timeout/empty input
	Options []Option
	// contains filtered or unexported fields
}

Config bundles the runtime knobs of a single Prompt call. Out is where the header/countdown/options are written; In is where the operator's line is read. Timeout zero disables the auto-select branch and waits forever.

type Option

type Option struct {
	Name  string
	Label string
}

Option is one row shown to the operator. Name is the canonical identifier returned to the caller; Label is the optional pretty form used for display (falls back to Name when empty).

Jump to

Keyboard shortcuts

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