menu

package
v3.0.0-...-66753ca Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package menu displays a Terminal UI based text menu to choose boot options from.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtendedLabel

func ExtendedLabel(e Entry) string

ExtendedLabel calls Entry.String(), but falls back to Entry.Label(). Shortly before kexec, "Attempting to boot %s" is printed. This allows for multiple lines of information which would not otherwise fit in the menu.

func NewTerminal

func NewTerminal(f *os.File) *xterm

NewTerminal opens an xTerminal using the given file input. Note that the xterm is in raw mode. Write \r\n whenever you would write a \n. When testing in qemu, it might look fine because there might be another tty cooking the newlines. In for example minicom, the behavior is different. And you would see something like:

Select a boot option to edit:
                             >

Instead of:

Select a boot option to edit:
 >

func SetInitialTimeout

func SetInitialTimeout(timeout time.Duration)

SetInitialTimeout sets the initial timeout of the menu to the provided duration

Types

type Entry

type Entry interface {
	// Label is the string displayed to the user in the menu. It must be a
	// single line to fit in the menu.
	Label() string

	// Edit the kernel command line if possible. Must be called prior to
	// Load.
	Edit(func(cmdline string) string)

	// Load is called when the entry is chosen, but does not transfer
	// execution to another process or kernel.
	Load() error

	// Exec transfers execution to another process or kernel.
	//
	// Exec either returns an error or does not return at all.
	Exec() error

	// IsDefault indicates that this action should be run by default if the
	// user didn't make an entry choice.
	IsDefault() bool
}

Entry is a menu entry.

func Choose

func Choose(term MenuTerminal, allowEdit bool, entries ...Entry) Entry

Choose presents the user a menu on input to choose an entry from and returns that entry. Note: This call can block if MenuTerminal or the underlying os.File does

not support SetTimeout/SetDeadline.

func OSImages

func OSImages(verbose bool, imgs ...boot.OSImage) []Entry

OSImages returns menu entries for the given OSImages.

func ShowMenuAndLoad

func ShowMenuAndLoad(allowEdit bool, entries ...Entry) Entry

ShowMenuAndLoad calls showMenuAndLoadFromFile using the default tty. Use TTY because os.stdin does not support deadlines well.

type MenuTerminal interface {
	io.Writer
	ReadLine() (string, error)
	SetPrompt(string)
	SetEntryCallback(func())
	SetTimeout(time.Duration) error
	Close() error
}

type OSImageAction

type OSImageAction struct {
	boot.OSImage
	Verbose bool
}

OSImageAction is a menu.Entry that boots an OSImage.

func (OSImageAction) Exec

func (oia OSImageAction) Exec() error

Exec executes the loaded image.

func (OSImageAction) IsDefault

func (OSImageAction) IsDefault() bool

IsDefault returns true -- this action should be performed in order by default if the user did not choose a boot entry.

func (OSImageAction) Load

func (oia OSImageAction) Load() error

Load implements Entry.Load by loading the OS image into memory.

type Reboot

type Reboot struct{}

Reboot is a menu.Entry that reboots the machine.

func (Reboot) Edit

func (Reboot) Edit(func(cmdline string) string)

Edit does nothing.

func (Reboot) Exec

func (Reboot) Exec() error

Exec reboots the machine using sys_reboot.

func (Reboot) IsDefault

func (Reboot) IsDefault() bool

IsDefault indicates that this should not be run as a default action.

func (Reboot) Label

func (Reboot) Label() string

Label is the label to show to the user.

func (Reboot) Load

func (Reboot) Load() error

Load does nothing.

type StartShell

type StartShell struct{}

StartShell is a menu.Entry that starts a LinuxBoot shell.

func (StartShell) Edit

func (StartShell) Edit(func(cmdline string) string)

Edit does nothing.

func (StartShell) Exec

func (StartShell) Exec() error

Exec implements Entry.Exec by running /bin/defaultsh.

func (StartShell) IsDefault

func (StartShell) IsDefault() bool

IsDefault indicates that this should not be run as a default action.

func (StartShell) Label

func (StartShell) Label() string

Label is the label to show to the user.

func (StartShell) Load

func (StartShell) Load() error

Load does nothing.

Jump to

Keyboard shortcuts

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