complete

package
v0.0.0-...-486954f Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: Apache-2.0 Imports: 11 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultKeyMap = KeyMap{
	KeyMap: list.KeyMap{
		CursorUp:             key.NewBinding(key.WithKeys("up", "ctrl+p"), key.WithHelp("C-p/↑", "prev entry")),
		CursorDown:           key.NewBinding(key.WithKeys("down", "ctrl+n"), key.WithHelp("C-n/↓", "next entry")),
		NextPage:             key.NewBinding(key.WithKeys("pgdown"), key.WithHelp("pgdown", "prev page/column")),
		PrevPage:             key.NewBinding(key.WithKeys("pgup"), key.WithHelp("pgup", "next page/column")),
		GoToStart:            key.NewBinding(key.WithKeys("ctrl+a", "home"), key.WithHelp("C-a/home", "start of column")),
		GoToEnd:              key.NewBinding(key.WithKeys("ctrl+e", "end"), key.WithHelp("C-e/end", "end of column")),
		Filter:               key.NewBinding(key.WithKeys("/", ""), key.WithHelp("/", "filter")),
		ClearFilter:          key.NewBinding(key.WithKeys("ctrl+g"), key.WithHelp("C-g", "clear/cancel")),
		CancelWhileFiltering: key.NewBinding(key.WithKeys("ctrl+g"), key.WithHelp("C-g", "clear/cancel")),
		AcceptWhileFiltering: key.NewBinding(key.WithKeys("enter", "ctrl+j"), key.WithHelp("C-j/enter", "accept filter")),
		ShowFullHelp:         key.NewBinding(key.WithKeys("alt+?"), key.WithHelp("M-?", "toggle key help")),
		CloseFullHelp:        key.NewBinding(key.WithKeys("alt+?"), key.WithHelp("M-?", "toggle key help")),
	},
	NextCompletions:  key.NewBinding(key.WithKeys("right", "alt+n"), key.WithHelp("→/M-n", "next column")),
	PrevCompletions:  key.NewBinding(key.WithKeys("left", "alt+p"), key.WithHelp("←/M-p", "prev column")),
	AcceptCompletion: key.NewBinding(key.WithKeys("enter", "tab", "ctrl+j"), key.WithHelp("C-j/enter/tab", "accept")),
	Abort:            key.NewBinding(key.WithKeys("ctrl+c"), key.WithHelp("C-c", "close/cancel")),
}

DefaultKeyMap is the default set of key bindings.

View Source
var DefaultStyles = func() (c Styles) {
	ls := list.DefaultStyles()
	subtle := lipgloss.AdaptiveColor{Light: "#D9DCCF", Dark: "#383838"}

	c.Item = lipgloss.NewStyle().PaddingLeft(1)
	c.SelectedItem = lipgloss.NewStyle().PaddingLeft(1).Foreground(lipgloss.Color("170"))

	c.FocusedTitleBar = lipgloss.NewStyle()
	c.BlurredTitleBar = lipgloss.NewStyle()
	c.FocusedTitle = lipgloss.NewStyle().Background(lipgloss.Color("62")).Foreground(lipgloss.Color("230"))
	c.BlurredTitle = c.FocusedTitle.Copy().Foreground(subtle)
	c.Spinner = ls.Spinner
	c.FilterPrompt = ls.FilterPrompt
	c.FilterCursor = ls.FilterCursor
	c.PaginationStyle = lipgloss.NewStyle()
	c.DefaultFilterCharacterMatch = ls.DefaultFilterCharacterMatch
	c.ActivePaginationDot = ls.ActivePaginationDot
	c.InactivePaginationDot = ls.InactivePaginationDot
	c.ArabicPagination = ls.ArabicPagination
	c.DividerDot = ls.DividerDot
	c.Description = lipgloss.NewStyle().Bold(true)
	c.PlaceholderDescription = lipgloss.NewStyle().Foreground(lipgloss.Color("240"))

	return c
}()

DefaultStyles returns a set of default style definitions for the completions component.

Functions

This section is empty.

Types

type Entry

type Entry interface {
	// Title is the main displayed text.
	Title() string

	// Description is the explanation for the entry.
	Description() string
}

Entry is the interface to one completion candidate.

func StringEntry

func StringEntry(s string) Entry

StringEntry adds the Entry interface to a simple string. Its description part is empty.

type KeyMap

type KeyMap struct {
	list.KeyMap
	NextCompletions  key.Binding
	PrevCompletions  key.Binding
	AcceptCompletion key.Binding
	Abort            key.Binding
}

KeyMap defines keybindings for navigating the completions.

type Model

type Model struct {
	Err error

	// KeyMap is the key bindings for navigating the completions.
	KeyMap KeyMap

	// Styles is the styles to use for display.
	Styles Styles

	// AcceptedValue is the result of the selection.
	AcceptedValue Entry
	// contains filtered or unexported fields
}

Model is the model that implements the completion selector widget.

func New

func New() Model

func (*Model) Blur

func (m *Model) Blur()

Blur removes the focus from the completion editor.

func (*Model) Debug

func (m *Model) Debug() string

func (*Model) Focus

func (m *Model) Focus()

Focus places the focus on the completion editor.

func (*Model) FullHelp

func (m *Model) FullHelp() [][]key.Binding

FullHelp is part of the help.KeyMap interface.

func (*Model) GetHeight

func (m *Model) GetHeight() int

GetHeight retrieves the current height.

func (*Model) GetMaxHeight

func (m *Model) GetMaxHeight() int

GetHeight retrieves the maximum height.

func (*Model) Init

func (m *Model) Init() tea.Cmd

Init implements the tea.Model interface.

func (*Model) MatchesKey

func (m *Model) MatchesKey(msg tea.KeyMsg) bool

MatchesKeys returns true when the completion editor can use the given key message.

func (*Model) SetHeight

func (m *Model) SetHeight(height int)

SetHeight changes the height.

func (*Model) SetValues

func (m *Model) SetValues(values Values)

SetValues resets the values. It also recomputes the height.

func (*Model) SetWidth

func (m *Model) SetWidth(width int)

SetWidth changes the width.

func (*Model) ShortHelp

func (m *Model) ShortHelp() []key.Binding

ShortHelp is part of the help.KeyMap interface.

func (*Model) Update

func (m *Model) Update(imsg tea.Msg) (tea.Model, tea.Cmd)

Update implements the tea.Model interface.

func (*Model) View

func (m *Model) View() string

View implements the tea.Model interface.

type Styles

type Styles struct {
	FocusedTitleBar             lipgloss.Style
	FocusedTitle                lipgloss.Style
	BlurredTitleBar             lipgloss.Style
	BlurredTitle                lipgloss.Style
	Item                        lipgloss.Style
	SelectedItem                lipgloss.Style
	Spinner                     lipgloss.Style
	FilterPrompt                lipgloss.Style
	FilterCursor                lipgloss.Style
	PaginationStyle             lipgloss.Style
	DefaultFilterCharacterMatch lipgloss.Style
	ActivePaginationDot         lipgloss.Style
	InactivePaginationDot       lipgloss.Style
	ArabicPagination            lipgloss.Style
	DividerDot                  lipgloss.Style
	PlaceholderDescription      lipgloss.Style
	Description                 lipgloss.Style
}

Styles contain style definitions for the completions component.

type Values

type Values interface {
	// NumCategories returns the number of categories to display.
	NumCategories() int

	// CategoryTitle returns the title of a category.
	CategoryTitle(catIdx int) string

	// NumEntries returns the number of entries in a given category.
	NumEntries(catIdx int) int

	// Entry returns the entry in a category.
	Entry(catIdx, entryIdx int) Entry
}

Values is the interface to the values displayed by the completion bubble.

func MapValues

func MapValues(values interface{}, categories []string) Values

MapValues adds the Values interface to a map of entries.

In go 1.18, this function would be:

func MapValues[T Entry](values map[string][]T, categories []string)

Each of the map values should be a slice of objects implementing the Entry interface.

The categories string slice, if provided, selects a specific order for the categories. If nil is specified, the map keys are used in sorted order.

func StringValues

func StringValues(title string, entries []string) Values

StringValues adds the Values interface to a simple string slice. There is just one category.

Jump to

Keyboard shortcuts

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