widget

package
v2.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package widget provides configurable prompt types used with [inquire.Query].

Configure widgets in the more callback passed to inquire.Session methods:

inquire.Query().Input(&name, "your name", func(w *widget.Input) {
    w.Valid(func(s string) string { ... })
})

Conditional prompts use Base.When with WhenEqual predicates.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompleteFrom added in v2.1.0

func CompleteFrom(candidates []string) func(prefix string) []string

CompleteFrom returns a prefix matcher over fixed candidates (case-insensitive).

func PollKey

func PollKey(ctx context.Context, scr *termui.Screen, band *termui.Band, repaint func()) (termui.Event, error)

PollKey waits for a key event, repainting the band after terminal resize.

func WhenEqual

func WhenEqual[T comparable](ptr *T, want T) func() bool

WhenEqual returns a predicate that is true when *ptr equals want. Use with Base.When or widget When methods:

w.When(WhenEqual(&quest, "nuts"))

Types

type AnyKey

type AnyKey struct {
	Base
	// contains filtered or unexported fields
}

AnyKey waits for any key before continuing.

func NewAnyKey

func NewAnyKey(message string) *AnyKey

NewAnyKey constructs an AnyKey prompt.

func (*AnyKey) Hint

func (w *AnyKey) Hint(h string) *AnyKey

Hint sets hint text shown beside the message.

func (*AnyKey) Run

func (w *AnyKey) Run(ctx context.Context, scr *termui.Screen) error

Run displays the message and continues on any key.

func (*AnyKey) When

func (w *AnyKey) When(fn func() bool) *AnyKey

When registers a skip predicate.

type Base

type Base struct {
	// contains filtered or unexported fields
}

Base holds shared widget configuration.

func (*Base) DoWhen

func (b *Base) DoWhen() bool

DoWhen reports whether this widget should run.

func (*Base) When

func (b *Base) When(fn func() bool)

When registers a predicate; the widget is skipped when DoWhen returns false.

type Editor

type Editor struct {
	// contains filtered or unexported fields
}

Editor is a rune-safe single-line text editor.

func NewEditor

func NewEditor() *Editor

NewEditor returns an empty editor.

func (*Editor) Backspace

func (e *Editor) Backspace()

Backspace removes the rune before the cursor.

func (*Editor) CursorCol

func (e *Editor) CursorCol(startX int) int

CursorCol returns the display column of the cursor relative to startX.

func (*Editor) DeleteForward

func (e *Editor) DeleteForward()

DeleteForward removes the rune at the cursor.

func (*Editor) Draw

func (e *Editor) Draw(band *termui.Band, y, startX int)

Draw paints the buffer and a reverse-video cursor at (y, startX).

func (*Editor) End

func (e *Editor) End()

End moves the cursor to the end.

func (*Editor) Home

func (e *Editor) Home()

Home moves the cursor to the start.

func (*Editor) Insert

func (e *Editor) Insert(r rune)

Insert adds a rune at the cursor.

func (*Editor) KillToEnd

func (e *Editor) KillToEnd()

KillToEnd removes text from the cursor through the end of the line.

func (*Editor) KillWordBackward

func (e *Editor) KillWordBackward()

KillWordBackward removes the word (readline-style) before the cursor.

func (*Editor) Left

func (e *Editor) Left()

Left moves the cursor one rune left.

func (*Editor) Right

func (e *Editor) Right()

Right moves the cursor one rune right.

func (*Editor) SetMask

func (e *Editor) SetMask(ch rune)

SetMask sets the echo character; zero disables masking.

func (*Editor) SetString

func (e *Editor) SetString(s string)

SetString replaces the buffer and parks the cursor at the end.

func (*Editor) String

func (e *Editor) String() string

String returns the edited text.

type Input

type Input struct {
	Base
	// contains filtered or unexported fields
}

Input is a single-line text prompt.

func NewInput

func NewInput(value *string, prompt string) *Input

NewInput constructs an Input bound to value.

func (*Input) Complete added in v2.1.0

func (w *Input) Complete(fn func(prefix string) []string) *Input

Complete registers tab-completion candidates for the text before the cursor. Ignored when MaskInput is set. Use CompleteFrom for a static candidate list.

func (*Input) Hint

func (w *Input) Hint(h string) *Input

Hint sets hint text shown beside the prompt.

func (*Input) MaskInput

func (w *Input) MaskInput(ch ...rune) *Input

MaskInput masks typed characters (password entry). Default mask is •.

func (*Input) Run

func (w *Input) Run(ctx context.Context, scr *termui.Screen) error

Run interactively collects text input.

func (*Input) Valid

func (w *Input) Valid(fn func(string) string) *Input

Valid registers a validation callback; non-empty return is shown as an error.

func (*Input) When

func (w *Input) When(fn func() bool) *Input

When registers a skip predicate.

type Menu struct {
	Base
	// contains filtered or unexported fields
}

Menu is a vertical single-select prompt.

func NewMenu

func NewMenu(value *string, prompt string) *Menu

NewMenu constructs a Menu bound to value.

func (w *Menu) Hint(h string) *Menu

Hint sets hint text shown beside the prompt.

func (w *Menu) Item(tag, name string)

Item appends a menu choice. tag is stored in value; name is displayed.

func (w *Menu) Run(ctx context.Context, scr *termui.Screen) error

Run interactively collects a menu selection.

func (w *Menu) When(fn func() bool) *Menu

When registers a skip predicate.

type Note

type Note struct {
	Base
	// contains filtered or unexported fields
}

Note is a non-interactive message printed before the next prompt.

func NewNote

func NewNote(text string) *Note

NewNote constructs a Note with the given text. Use embedded newlines for multiple lines.

func (*Note) Run

func (w *Note) Run(ctx context.Context, scr *termui.Screen) error

Run prints the note and continues immediately.

func (*Note) When

func (w *Note) When(fn func() bool) *Note

When registers a skip predicate.

type Runner

type Runner interface {
	DoWhen() bool
	Run(ctx context.Context, scr *termui.Screen) error
}

Runner is a prompt widget executed against a terminal screen.

type Select

type Select struct {
	Base
	// contains filtered or unexported fields
}

Select is a vertical multi-select checkbox prompt.

func NewSelect

func NewSelect(prompt string) *Select

NewSelect constructs a Select group.

func (*Select) Hint

func (w *Select) Hint(h string) *Select

Hint sets hint text shown beside the prompt.

func (*Select) Item

func (w *Select) Item(value *bool, name string)

Item appends a checkbox entry bound to value.

func (*Select) Run

func (w *Select) Run(ctx context.Context, scr *termui.Screen) error

Run interactively collects checkbox selections.

func (*Select) When

func (w *Select) When(fn func() bool) *Select

When registers a skip predicate.

type YesNo

type YesNo struct {
	Base
	// contains filtered or unexported fields
}

YesNo is a yes/no toggle prompt.

func NewYesNo

func NewYesNo(value *bool, prompt string) *YesNo

NewYesNo constructs a YesNo bound to value.

func (*YesNo) Hint

func (w *YesNo) Hint(h string) *YesNo

Hint sets hint text shown beside the prompt.

func (*YesNo) Run

func (w *YesNo) Run(ctx context.Context, scr *termui.Screen) error

Run interactively collects a yes/no answer.

func (*YesNo) When

func (w *YesNo) When(fn func() bool) *YesNo

When registers a skip predicate.

Jump to

Keyboard shortcuts

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