suggest

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package suggest is formula assistance, as in Sheets: while a function, range or sheet name is being typed, a list of matching functions, named ranges and other sheets drops down from the formula bar at the caret, and while the caret is inside a function's parentheses the context line shows its signature with the current argument marked. The list takes only the keys Sheets gives it (Up/Down, Tab, Enter, Esc) and only while it shows, so arrows after an operator still point at cells. It knows the UI only through Host.

Index

Constants

View Source
const ID = "assist"

ID identifies the list's box.

View Source
const Rows = 8

Rows is the most suggestions shown at once.

Variables

This section is empty.

Functions

func InTable

func InTable(buf []rune, pos int) (string, bool)

InTable reports the table whose brackets the caret is in, if any: buf is the formula as it's parsed (see Host.Stored).

func Signature

func Signature(th *theme.Theme, buf []rune, pos int, sep byte) (sig, desc string)

Signature renders the signature of the function around the caret, e.g. SUM(value1, [value2, ...]), with the current argument marked, and what the function does. It is "" outside a function. buf is the formula in the syntax it's parsed in (see Host.Stored); sep separates the arguments shown, ; in a locale with a decimal comma.

func SignatureLine

func SignatureLine(th *theme.Theme, width int, buf []rune, pos int, sep byte, hints string) (left, right string, ok bool)

SignatureLine puts the signature of the function around the caret on the context line, with what the function does and the keys that apply (hints) as room allows. It reports false outside a function.

func TableLine

func TableLine(th *theme.Theme, width int, sh *sheet.Sheet, buf []rune, pos int, hints string) (left, right string, ok bool)

TableLine puts the columns of the table whose brackets the caret is in on the context line, Sales[Region, Units, Amount], with the column being typed marked and the items after, and the keys that apply (hints) as room allows. It reports false outside a table's brackets or for a table formulas can't find.

Types

type Host

type Host interface {
	Theme() *theme.Theme
	Size() (width, height int)
	// Line is the edit line the entry is typed in.
	Line() *lineedit.Line
	// Typing reports whether a cell's entry is being typed with nothing
	// open over it, when the list may show.
	Typing() bool
	// EntrySheet is the sheet the entry is on: its named ranges and the
	// other sheets are offered.
	EntrySheet() *sheet.Sheet
	// Stored is typed text as the formula parser reads it, whatever the
	// workbook's locale.
	Stored(buf []rune) []rune
	// TextX is the screen column the formula bar's text starts at.
	TextX() int
}

Host is what the suggestions need of the UI.

type List

type List struct {
	// Active is set when the last key typed or deleted text; moving the
	// caret hides the list.
	Active bool
	// contains filtered or unexported fields
}

List is the suggestion list's state; the zero List is hidden.

func (*List) Box

func (l *List) Box(h Host) (overlay.Box, bool)

Box draws the list under the formula bar, its text aligned with the word being typed: the name, then the signature or range dimmed.

func (*List) Key

func (l *List) Key(h Host, key string) bool

Key handles the keys the list takes while it shows, and reports whether it took key.

func (*List) Mouse

func (l *List) Mouse(h Host, msg tea.MouseMsg) bool

Mouse lets the mouse hover and click suggestions and scroll the list. It reports false for events outside the list.

func (*List) Sel

func (l *List) Sel() int

Sel is the highlighted suggestion.

func (*List) Shown

func (l *List) Shown(h Host) ([]Suggestion, int)

Shown returns the list for the word at the caret, and where the word starts, or nothing when the list is hidden: outside an entry, in plain text, after the caret moved, or when the word already names a range exactly and nothing else matches.

func (*List) Status

func (l *List) Status(h Host) (desc, keys string, ok bool)

Status is the status line while the list shows: what the highlighted suggestion is, and the keys that apply.

type Suggestion

type Suggestion struct {
	Name   string // e.g. "SUM", "Sales" or "'Q3 plan'!"
	Detail string // the signature, the range a name stands for, or a sheet's cells
	Desc   string
	Fn     bool // a function: accepting it adds "("
	Column bool // a table's column or item: accepting it adds "]"
}

Suggestion is a function, named range or sheet offered for the word at the caret.

func For

func For(sh *sheet.Sheet, word string) []Suggestion

For lists the functions, named ranges, tables and sheets for word, typed on sh: those starting with it first (names, then tables, then sheets, then functions), then, from two letters on, those containing it, such as COUNTIFS for "ifs". A word that is already a cell reference only gets those that start with it, and a word in quotes ('Q3) only sheets.

Jump to

Keyboard shortcuts

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