autocomplete

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Completioner

type Completioner func(ctx context.Context, query string) ([]Suggestion, error)

Completioner is a function that provides suggestions for a query string.

type DoneMsg

type DoneMsg Suggestion

DoneMsg is a message indicating a suggestion was selected.

type ErrMsg

type ErrMsg error

ErrMsg is a message containing an error from the completioner.

type Model

type Model struct {
	Input     textinput.Model
	List      listbox.ListModel
	Selection *Suggestion
	Width     int
	Height    int
	// contains filtered or unexported fields
}

Model is the Bubble Tea model for the autocomplete widget.

func New

func New(completioner Completioner, width, height int) Model

New creates a new autocomplete model with the given completioner.

func (*Model) ApplyHighlighting

func (m *Model) ApplyHighlighting()

ApplyHighlighting applies highlighting to all suggestions in the list You should call this after setting items in the list if you want to display highlighted text

func (*Model) CustomizeStyles

func (m *Model) CustomizeStyles(pointer string)

CustomizeStyles allows modifying the list's pointer style

func (Model) Init

func (m Model) Init() tea.Cmd

Init initializes the model.

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles messages and updates the model accordingly.

func (Model) View

func (m Model) View() string

View renders the model.

type Span

type Span struct {
	Start, End int // rune offsets, half-open [Start,End)
}

Span represents a range of runes to highlight within a suggestion.

type Suggestion

type Suggestion struct {
	Id          string // Unique identifier
	Value       string // The actual value (for programmatic use)
	DisplayText string // The displayed value (for viewing)
	Submatches  []Span // Regions to highlight
}

Suggestion is a completion result with associated metadata and highlight regions.

func (Suggestion) Display

func (s Suggestion) Display() string

Display returns the display text of the suggestion (implements listbox.Item)

func (Suggestion) ID

func (s Suggestion) ID() string

ID returns the unique identifier of the suggestion (implements listbox.Item)

type SuggestionsMsg

type SuggestionsMsg []Suggestion

SuggestionsMsg is a message containing new completion suggestions.

Jump to

Keyboard shortcuts

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