inputbox

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAborted = errors.New("aborted")

ErrAborted is returned by Result when input was cancelled via Ctrl+C.

Functions

This section is empty.

Types

type Completer added in v0.0.24

type Completer func(
	line string,
) (head string, completions []string, tail string)

Completer returns completions for the entire line. It receives the line and returns the head (portion before completions), the candidates, and the tail (portion after completions).

type Handler

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

Handler implements a multi-line text input handler with wrapping, text selection, word-wise cursor movement, history navigation, reverse search, and tab completion. Note that text selection is limited by your terminal's ability to handle shift+arrow keys.

func New

func New(opts ...Option) *Handler

New creates and initializes a new input box with default attributes.

func (*Handler) AppendHistory added in v0.0.24

func (ib *Handler) AppendHistory(item string)

AppendHistory adds an item to the history.

func (*Handler) Clear

func (ib *Handler) Clear()

Clear resets the input box to empty state.

func (*Handler) ClearHighlight added in v0.0.27

func (ib *Handler) ClearHighlight()

ClearHighlight removes any active highlight range.

func (*Handler) ClearHistory added in v0.0.24

func (ib *Handler) ClearHistory()

ClearHistory removes all history entries.

func (*Handler) Cursor

func (ib *Handler) Cursor() (term.Coordinates, term.CursorStyle, bool)

Cursor satisfies tui.Handler

func (*Handler) Dimensions added in v0.0.35

func (ib *Handler) Dimensions() (int, int)

Dimensions satisfies component.Floating. It returns the width needed to render the entire input box content on a single line (height is always 1).

func (*Handler) Draw

func (ib *Handler) Draw(w term.Writer)

Draw satisfies tui.Component.

func (*Handler) Handle

func (ib *Handler) Handle(ev term.Event) (exit, handled bool)

Handle satisfies tui.Handler

func (*Handler) Height

func (ib *Handler) Height(width int) int

Height satisfies Responsive. Returns the number of lines needed to display all text content and cursor given the specified width.

func (*Handler) Reset added in v0.0.24

func (ib *Handler) Reset()

Reset clears the exit state for the next prompt.

func (*Handler) Resize

func (ib *Handler) Resize(width, height int)

Resize satisfies tui.Handler

func (*Handler) Result added in v0.0.24

func (ib *Handler) Result() (string, error)

Result returns the input text or an error if input was aborted or reached EOF.

func (*Handler) Selection

func (ib *Handler) Selection() (string, bool)

Selection satisfies tui.Handler

func (*Handler) SetAttr

func (ib *Handler) SetAttr(attr term.Attributes) (ret term.Attributes)

SetAttr satisfies WithAttributes.

func (*Handler) SetHighlight added in v0.0.27

func (ib *Handler) SetHighlight(start, end int, attr term.Attributes)

SetHighlight applies attr to the text range [start, end). The prompt and characters outside the range are unaffected.

func (*Handler) SetHistory added in v0.0.24

func (ib *Handler) SetHistory(items []string)

SetHistory replaces the history with items.

func (*Handler) Text

func (ib *Handler) Text() string

Text returns the current text content of the input box.

type Option added in v0.0.9

type Option func(*Handler)

Option configures a Handler.

func WithAttributes added in v0.0.9

func WithAttributes(attr term.Attributes) Option

WithAttributes defines the default input text attributes.

func WithCompleter added in v0.0.24

func WithCompleter(c Completer) Option

WithCompleter sets a line completer for tab completion.

func WithCtrlCAborts added in v0.0.24

func WithCtrlCAborts() Option

WithCtrlCAborts makes Ctrl+C abort the input (returning ErrAborted) instead of clearing the line.

func WithHistory added in v0.0.24

func WithHistory(items []string) Option

WithHistory pre-populates the history.

func WithPlaceholder added in v0.0.9

func WithPlaceholder(text string, cfg component.StringResponsiveConfig) Option

WithPlaceholder adds a placeholder when there's no text in the input box. The placeholder uses the provided StringResponsiveConfig for styling.

func WithPlaceholderText added in v0.0.9

func WithPlaceholderText(text string) Option

WithPlaceholderText adds a placeholder with default gray styling.

func WithPrompt added in v0.0.24

func WithPrompt(prompt string) Option

WithPrompt sets the prompt string displayed before the input text on the first line.

func WithRedact added in v0.0.71

func WithRedact(redact bool) Option

WithRedact enables redacted rendering: each character of the buffer is drawn as the default redaction glyph ('*'). The underlying buffer is kept intact: Text(), Result() and Selection() still return the real content. Useful for password / secret prompts.

Use WithRedactRune to override the glyph.

func WithRedactRune added in v0.0.71

func WithRedactRune(r rune) Option

WithRedactRune sets the rune used when redact rendering is enabled. Implies WithRedact(true). The zero rune resets to the default ('*').

func WithTabStyle added in v0.0.24

func WithTabStyle(style TabStyle) Option

WithTabStyle sets the tab completion style.

func WithText added in v0.0.24

func WithText(text string) Option

WithText pre-populates the input text and places the cursor at the end.

func WithWordCompleter added in v0.0.24

func WithWordCompleter(c WordCompleter) Option

WithWordCompleter sets a word completer for tab completion.

type TabStyle added in v0.0.24

type TabStyle int

TabStyle determines how tab completion candidates are presented.

const (
	// TabCircular cycles through candidates inline.
	// This is the zero value, making it the default
	// tab completion style.
	TabCircular TabStyle = iota
	// TabPrints shows all candidates in a grid below
	// the input line on the second tab press.
	TabPrints
)

type WordCompleter added in v0.0.24

type WordCompleter func(
	line string, pos int,
) (head string, completions []string, tail string)

WordCompleter returns completions for the word at the cursor. It receives the line and cursor position and returns the head, candidates, and tail.

Jump to

Keyboard shortcuts

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