Documentation
¶
Overview ¶
Package search is the launcher's search: one ranked list across providers (apps, windows, files, answers, ...), frecency that learns, levels you enter and leave, and the actions of a selected row. Pure logic and effects behind small interfaces, no widgets; the panel that shows it is shell/launcher's. Everything here runs on the session's engine goroutine or a provider's own, never on the UI loop.
Index ¶
- func FrecencyPath() (string, bool)
- func SkinToneName(tone modes.SkinTone) config.LauncherSkinTone
- func SkinToneOf(name config.LauncherSkinTone) modes.SkinTone
- type Action
- type ActionKey
- type Answerer
- type Apps
- type Bookmarks
- type BrowserIndex
- type Calculator
- type Cancel
- type Characters
- type Clipboard
- type Close
- type CloseThen
- type Control
- type ControlEffect
- type Controls
- type Copy
- type Deps
- type Emoji
- type Engine
- func (e *Engine) Activate(id string, action int)
- func (e *Engine) Back()
- func (e *Engine) Done() <-chan struct{}
- func (e *Engine) Recycle(rows []Row)
- func (e *Engine) SetQuery(text string, seq uint64)
- func (e *Engine) ShowActions(id string)
- func (e *Engine) Stop()
- func (e *Engine) Submit(text string)
- type Entry
- type Env
- type Files
- type FilesConfig
- type Found
- type Frame
- type Frecency
- type Immediate
- type Level
- func CharactersLevel(table func() (*charnames.Table, error)) *Level
- func EmojiLevel(load func() []modes.Emoji, tone modes.SkinTone, setTone func(modes.SkinTone)) *Level
- func ModeLevel(mode launcher.Mode, title string) *Level
- func NewRoot(cfg config.LauncherSearchConfig, power config.PowerConfig, d Deps, home string) *Level
- type Links
- type Outcome
- type PickerLevels
- type Pickers
- type Processes
- type Provider
- type Push
- type Reload
- type Replace
- type Row
- type RunNow
- type RunOnceClosed
- type Script
- type ScriptArg
- type ScriptOutput
- type Scripts
- type Searcher
- type Section
- type SetQuery
- type Settings
- type Shell
- type Sink
- type Sources
- type Spec
- type Stay
- type System
- type Type
- type VisitedPages
- type WatchFunc
- type Web
- type Windows
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SkinToneName ¶ added in v0.3.15
func SkinToneName(tone modes.SkinTone) config.LauncherSkinTone
SkinToneName is tone as the config spells it.
func SkinToneOf ¶ added in v0.3.15
func SkinToneOf(name config.LauncherSkinTone) modes.SkinTone
SkinToneOf is the config's skin tone as emoji take it.
Types ¶
type Action ¶
type Action struct {
// Title names it in the panel and the footer.
Title string
// Icon leads its row in the actions panel.
Icon string
// Key runs it straight from the list, without the actions panel.
Key ActionKey
// Run does it.
Run func(ctx context.Context) Outcome
}
Action is one thing to do with a row. Run happens on the engine goroutine: it may wait for the world, and the panel stays live.
type ActionKey ¶ added in v0.3.15
type ActionKey uint8
ActionKey is a key that runs a row's action from the list itself.
type Answerer ¶
Answerer is a provider whose rows answer the query rather than being searched through (a calculation, a web search). Answer runs on every query on the engine goroutine, so it must be quick.
type Apps ¶
type Apps struct {
// contains filtered or unexported fields
}
Apps offers the desktop entries, links included.
type Bookmarks ¶ added in v0.3.5
type Bookmarks struct {
// contains filtered or unexported fields
}
Bookmarks offers the browsers' bookmarks.
func NewBookmarks ¶ added in v0.3.5
func NewBookmarks(env Env, index *BrowserIndex) *Bookmarks
NewBookmarks offers the bookmarks index holds.
type BrowserIndex ¶ added in v0.3.5
type BrowserIndex struct {
// contains filtered or unexported fields
}
BrowserIndex reads the browsers' bookmarks and history, rereading a profile only when its files changed. It lives as long as the shell, so opening the panel costs a stat per file while nobody browses.
func NewBrowserIndex ¶ added in v0.3.5
func NewBrowserIndex(home, configHome, iconDir string) *BrowserIndex
NewBrowserIndex reads the known browsers' profiles under home and configHome, keeping their favicons in iconDir.
type Calculator ¶
type Calculator struct {
// contains filtered or unexported fields
}
Calculator answers arithmetic, unit and currency conversions, times across zones and date arithmetic inline.
func NewCalculator ¶ added in v0.3.15
func NewCalculator(rates *answer.Rates, currency answer.CurrencyParser, zones *answer.Zones, now func() time.Time) *Calculator
NewCalculator answers currencies over rates (nil answers none), reading "kr" and symbols with currency, placing times through zones, on now's calendar.
func (*Calculator) Actions ¶
func (*Calculator) Actions(e Entry) []Action
Actions implements Provider.
func (*Calculator) Answer ¶
func (c *Calculator) Answer(query string) []Entry
Answer implements Answerer.
type Characters ¶ added in v0.3.15
type Characters struct {
// contains filtered or unexported fields
}
Characters finds any character Unicode names. Its forty thousand names are never published as rows: it searches charnames' compact table itself and builds rows only for what shows.
func NewCharacters ¶ added in v0.3.15
func NewCharacters(table func() (*charnames.Table, error)) *Characters
NewCharacters searches table's names (charnames.Shared), read on the first search.
func (*Characters) Actions ¶ added in v0.3.15
func (*Characters) Actions(e Entry) []Action
Actions implements Provider.
func (*Characters) Load ¶ added in v0.3.15
func (*Characters) Load(context.Context, func([]Entry))
Load implements Provider: the table is read on the first search, not when the panel opens.
func (*Characters) Search ¶ added in v0.3.15
func (c *Characters) Search(q *launcher.FuzzyQuery, query string, limit int) []Found
Search implements Searcher.
func (*Characters) Spec ¶ added in v0.3.15
func (c *Characters) Spec() Spec
Spec implements Provider.
type Clipboard ¶
type Clipboard struct {
// contains filtered or unexported fields
}
Clipboard offers the clipboard history. Accepting a row puts it back under the mime it arrived with.
func NewClipboard ¶
func NewClipboard(history modes.ClipboardHistory, previews bool) *Clipboard
NewClipboard builds the root's section of history; nil (a compositor without data-control) offers nothing.
type CloseThen ¶ added in v0.3.5
type CloseThen struct{ Run func() }
CloseThen ends the session and runs Run on the UI loop once the panel has left the screen.
type Control ¶ added in v0.3.5
type Control struct {
// ID stays the same across states: "Turn On" and "Turn Off" are one
// control, so what is learned of it is kept.
ID string
Title, Subtitle, Keywords string
Icon string
Effect ControlEffect
}
Control is one thing the panel can switch or start in a service of the shell.
type ControlEffect ¶ added in v0.3.5
type ControlEffect interface {
// contains filtered or unexported methods
}
ControlEffect is what choosing a control does.
type Controls ¶ added in v0.3.5
type Controls struct {
// contains filtered or unexported fields
}
Controls offers rows of the shell's own services. Load reads their state each time the panel opens, as it decides what the rows say.
func NewControls ¶ added in v0.3.5
NewControls offers what load returns.
type Deps ¶
type Deps struct {
Env Env
// Clipboard is the history; nil without data-control.
Clipboard modes.ClipboardHistory
// Vault builds a vault level; nil without a vault.
Vault func() launcher.Mode
// SettingsPages asks lys-settings for its pages.
SettingsPages func(context.Context) ([]settingspage.Page, error)
// Windows is the compositor's; nil where none is known.
Windows modes.WindowBackend
// Browser reads the browsers' bookmarks and history; nil offers neither.
Browser *BrowserIndex
// Toggles, Media and Capture read the rows of the shell's services; a
// nil one offers none.
Toggles, Media, Capture func(ctx context.Context) []Control
// SkinTone is what person and hand emoji show in; SetSkinTone keeps a tone
// picked from an emoji's actions as the new default (nil keeps none).
SkinTone modes.SkinTone
SetSkinTone func(modes.SkinTone)
// Rates are the currency reference rates, kept across sessions; nil
// answers no currencies.
Rates *answer.Rates
// Sources keeps the stable sources' rows between sessions; nil loads
// every source in every session.
Sources *Sources
}
Deps are the shell services a search session draws on.
type Emoji ¶
type Emoji struct {
// contains filtered or unexported fields
}
Emoji offers the emoji table.
func NewEmoji ¶
NewEmoji offers load's emoji (modes.AvailableEmoji) in skin tone tone. Typing a tone picked from an emoji's actions hands it to setTone, which keeps it as the new default. Load decompresses a table, so it runs only on the provider's goroutine.
func (*Emoji) Actions ¶
Actions implements Provider: type and copy in the current tone, then, for an emoji that takes one, each of the five tones.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is one session's search, on its own goroutine: providers load beside it and publish into it, queries are answered in order, and a query already overtaken by a newer one is skipped, so typing fast costs one answer rather than one per key. Answering a query reuses its memory: only what a provider's answer or the query's own text needs is allocated.
func Start ¶
func Start(root *Level, openFrecency func() (*Frecency, error), sink Sink, deliver func(func())) *Engine
Start runs the engine over root. openFrecency runs on its goroutine, as it reads the disk; nil learns nothing. deliver hops onto the UI loop.
func (*Engine) Back ¶
func (e *Engine) Back()
Back leaves the current level; at the root it finishes with Cancel.
func (*Engine) Done ¶
func (e *Engine) Done() <-chan struct{}
Done closes once the engine and its providers have all returned.
func (*Engine) SetQuery ¶
SetQuery answers text; seq numbers the edit, so a frame can say which edits it has seen.
func (*Engine) ShowActions ¶
ShowActions enters the actions panel of the row with this id.
type Entry ¶
type Entry struct {
// ID identifies the row across queries, so the selection can follow
// it. Unique within its provider.
ID string
// Learn is the frecency key; "" never learns. Rows that are the same
// thing to the user share one (every window of an application).
Learn string
// Title is the row's main text, matched and highlighted.
Title string
// Subtitle is the dim text beside it, matched.
Subtitle string
// Keywords are matched and never shown.
Keywords string
// Icon leads the row; Glyph leads it instead when set (an emoji).
Icon launcher.Icon
Glyph string
// Completion is what Tab puts in the search field ("" opens the
// actions panel instead).
Completion string
// Hint is the dim text at the row's end, as an action's key.
Hint string
// Rank is added to the row's score: a recent file over one merely
// indexed.
Rank int
// Preview is the row's side pane.
Preview launcher.Preview
// Data is the provider's own, for Actions.
Data any
}
Entry is one row a provider offers.
type Env ¶
type Env struct {
// Spawn runs an argv detached; nothing waits for it.
Spawn func(argv []string)
// SpawnShell runs a shell line detached.
SpawnShell func(line string)
// Terminal is the terminal emulator command ("" autodetects).
Terminal string
}
Env is how providers reach out of the process: a seam, so a test's launches and opens land in a list instead of on the desktop.
type Files ¶
type Files struct {
// contains filtered or unexported fields
}
Files searches recent files and an index of the home directory, and answers a typed path with its directory's contents.
func (*Files) Answer ¶
Answer implements Answerer: a query that is a path lists its directory filtered by the name being typed. It is one directory read, on the engine goroutine.
type FilesConfig ¶
type FilesConfig struct {
// Roots are walked; a walk stays on each root's filesystem.
Roots []string
// Exclude are directory names to skip, on top of skippedDirs.
Exclude []string
// CachePath is the index's file.
CachePath string
// RecentPath is the desktop's recently-used.xbel.
RecentPath string
// Home abbreviates paths and resolves a leading ~.
Home string
// Previews asks for the side pane.
Previews bool
// Now is the clock (the index's age).
Now func() time.Time
}
FilesConfig bounds what Files reads.
type Found ¶ added in v0.3.15
Found is a row a Searcher built, its score, and its title as the matcher reads it, for highlights.
type Frame ¶
type Frame struct {
// Depth is how many levels sit under this one; 0 is the root.
Depth int
// Title, Placeholder, Message, Mask and SubmitTitle are the level's.
Title, Placeholder, Message string
Mask bool
SubmitTitle string
// CanSubmit is Enter accepting the typed text with no row selected.
CanSubmit bool
// Query is the text these rows answer.
Query string
// QuerySeq is the last edit of the field the engine had seen. A panel
// that has sent a later one keeps its text: what was typed since must
// not be overwritten by a frame that predates it.
QuerySeq uint64
// SetField asks the panel to put Field in the search field: a level
// was entered or left, or an action set the query.
SetField bool
Field string
// Late marks rows that arrived while the query stood still: the
// selection stays on the row it is on.
Late bool
// Rows are the list. They stay the receiver's until it hands them
// back with Engine.Recycle.
Rows []Row
}
Frame is everything the panel shows for one state of the search.
type Frecency ¶
type Frecency struct {
// contains filtered or unexported fields
}
Frecency learns what gets picked: every use adds one to a count that halves every two weeks, kept overall and for the query it was found by, so "f" comes to mean Firefox for someone who keeps choosing it. The file lives in the state directory and is replaced atomically. The shell keeps one for its lifetime, so a session closing and the next opening may use it at once.
func OpenFrecency ¶
OpenFrecency reads path. A missing file is an empty store; a corrupt one is an error, and a store that starts empty and replaces it on the next use (the launcher still has to open).
func (*Frecency) QueryBoostsInto ¶
QueryBoostsInto fills into, empty, with each key picked for query (or a query it starts with) and the score that adds, so typing what you typed last time finds what you chose last time. It reports whether it found any.
type Immediate ¶
type Immediate interface{ Immediate() }
Immediate marks a provider whose rows are already in memory: its Load runs as the level opens, so the level's first frame has them and the panel does not change height a moment later.
type Level ¶
type Level struct {
// Title is the breadcrumb beside the field; "" at the root.
Title string
// Placeholder is the empty field's text.
Placeholder string
// Message is shown above the rows.
Message string
// Mask shows the field as dots: the input is a secret.
Mask bool
// Providers are searched.
Providers []Provider
// Submit is Enter with no row selected: the typed text is the
// answer (a script's argument, a master password). Nil: nothing.
Submit func(ctx context.Context, text string) Outcome
// SubmitTitle names Submit in the footer.
SubmitTitle string
// Query is what the field starts with.
Query string
}
Level is one screen of the panel: the search field and what it searches. Esc goes back through levels, then closes.
func CharactersLevel ¶ added in v0.3.15
CharactersLevel searches every named character, as the Unicode Characters row and `-show unicode` open it.
func EmojiLevel ¶ added in v0.3.15
func EmojiLevel(load func() []modes.Emoji, tone modes.SkinTone, setTone func(modes.SkinTone)) *Level
EmojiLevel lists every emoji, as the Emoji Picker row opens it.
func ModeLevel ¶
ModeLevel hosts a rofi mode as a level, so what already works as a mode (the vault, with its unlock prompt and field picker) keeps one implementation. Its reloads swap the level; its masked prompts mask the field.
func NewRoot ¶
func NewRoot(cfg config.LauncherSearchConfig, power config.PowerConfig, d Deps, home string) *Level
NewRoot builds the root level from the configuration: one provider per enabled source, nothing loaded yet.
type Links ¶
type Links struct {
// contains filtered or unexported fields
}
Links offers the configured quick links and snippets. A link whose URL takes {query} completes to its keyword: "gh rust" answers with the filled URL.
func NewLinks ¶
func NewLinks(env Env, links []config.LauncherQuicklink, snippets []config.LauncherSnippet, previews bool) *Links
NewLinks offers links and snippets.
type Outcome ¶
type Outcome interface {
// contains filtered or unexported methods
}
Outcome is what the panel does after an action ran.
type PickerLevels ¶ added in v0.3.5
type PickerLevels struct {
Emoji, Characters, Vault, Bookmarks, Visited, Processes func() *Level
}
PickerLevels are the levels of the pickers with nothing to configure; a nil one leaves its row out.
type Pickers ¶
type Pickers struct {
// contains filtered or unexported fields
}
Pickers are root rows that open a whole list of their own: the full clipboard history, every emoji, the vault, every bookmark, the most visited pages, the running processes.
func NewPickers ¶
func NewPickers(history modes.ClipboardHistory, levels PickerLevels, previews bool) *Pickers
NewPickers builds the rows for what is available. A nil history leaves its row out, as does a nil level.
type Processes ¶ added in v0.3.5
type Processes struct {
// contains filtered or unexported fields
}
Processes lists the user's running processes to end one. It is only ever a picker's level: a search for an app should not offer to kill it.
type Provider ¶
type Provider interface {
Spec() Spec
Load(ctx context.Context, publish func([]Entry))
Actions(e Entry) []Action
}
Provider offers rows. Load runs once per level on its own goroutine: it reads the disk or a socket and calls publish with the rows it has, as often as it learns more, each call replacing the last; it returns when done or ctx ends. Actions lists a row's actions, the first the default; it must not wait for anything, as the panel calls it when the selection moves.
type Row ¶
type Row struct {
// Header is a heading's text; "" for an entry.
Header string
// Entry is the row; nil for a heading. It is never written after its
// provider published it.
Entry *Entry
// contains filtered or unexported fields
}
Row is one line of the list: a section heading (Header set) or an entry. It points at its entry rather than copying it, and a row of the list is 64 bytes, so a frame costs little whatever an entry holds.
func (Row) AppendHighlights ¶
func (r Row) AppendHighlights(dst []int, q *launcher.FuzzyQuery) []int
AppendHighlights appends the positions in the title, counted in grapheme clusters, of the characters q matched. It is computed when asked, so only rows on screen pay for it, on the reader's own q and buffer.
type RunNow ¶ added in v0.3.5
RunNow runs while the panel stays open, so a failure can be said in its footer. It closes on success.
type RunOnceClosed ¶ added in v0.3.5
type RunOnceClosed func()
RunOnceClosed runs on the UI loop after the panel has left the screen and given the keyboard back: what looks at the screen must not find the panel on it. It must not wait.
type Script ¶
type Script struct {
Path, Title, Subtitle, Keywords, Icon string
Output ScriptOutput
Args []ScriptArg
}
Script is one script command, as its header says.
func ParseScript ¶
ParseScript reads a script's directives from its leading comment lines. A file with no @lys.title is not a command; a directive it cannot read is an error naming the line, so a typo does not silently run the script differently.
type ScriptOutput ¶
type ScriptOutput uint8
ScriptOutput says what happens to a script's run.
const ( // ScriptSilent runs it detached; nobody reads its output. ScriptSilent ScriptOutput = iota // ScriptTerminal runs it in a terminal. ScriptTerminal // ScriptCopy waits for it and copies its stdout. ScriptCopy )
The script output modes.
type Scripts ¶
type Scripts struct {
// contains filtered or unexported fields
}
Scripts offers the executables of a directory as commands. The format is in docs/guide/launcher.md.
type Searcher ¶ added in v0.3.15
type Searcher interface {
Search(q *launcher.FuzzyQuery, query string, limit int) []Found
}
Searcher is a provider with too many rows to publish (every character Unicode names): it matches the query against a compact table of its own, on the engine goroutine, and returns at most limit rows with their scores, best first, building only those. An empty query lists its first rows.
type Section ¶
type Section uint8
Section is the heading a row sits under.
const ( SectionAnswer Section = iota // SectionRecent is what an empty query shows: what gets used. SectionRecent SectionApps SectionWindows SectionCommands SectionLinks SectionBrowser SectionSettings SectionFiles SectionClipboard SectionEmoji SectionCharacters SectionVault SectionWeb // SectionNone is a flat list: an actions panel or a picker. SectionNone )
The sections. Their order breaks ties between sections of equal rank.
type Settings ¶
type Settings struct {
// contains filtered or unexported fields
}
Settings offers lys-settings' pages.
func NewSettings ¶
NewSettings offers pages.
type Shell ¶
type Shell struct {
// contains filtered or unexported fields
}
Shell answers a query led by ">": run the rest as a command.
type Sink ¶
type Sink interface {
// Results is a new list.
Results(Frame)
// Finish ends the session: Close, Cancel or Copy.
Finish(Outcome)
// Notice says something in the footer without changing the list.
Notice(message string)
}
Sink receives the engine's results; both run through deliver, on the UI loop.
type Sources ¶ added in v0.3.13
type Sources struct {
// contains filtered or unexported fields
}
Sources keeps what the panel searches and rarely changes for the shell's lifetime: the rows of the apps, scripts, settings, files and emoji, and the frecency store. A session shows the rows kept from the last one in its first frame and loads a source again only once a watch saw its files change, so opening the panel reads nothing from the disk.
func NewSources ¶ added in v0.3.13
NewSources keeps rows refreshed through watch; nil watches nothing, so every session loads its sources again behind the rows it starts with.
type Spec ¶
type Spec struct {
Section Section
// MinQuery is the query length, in characters, below which its rows
// stay out: a one-letter query should not list every emoji.
MinQuery int
// Weight is added to its rows' score: a good app beats an equally
// good match in a file name.
Weight int
}
Spec says how a provider's rows take part in a list.
type Stay ¶
type Stay struct{ Message string }
Stay leaves everything as it is, Message shown when not empty (a failure said in the footer rather than swallowed).
type System ¶
type System struct {
// contains filtered or unexported fields
}
System offers the session commands, through the commands the power menu runs. Those that end what you are doing ask first: a fuzzy search and an Enter should not be enough to reboot.
func NewSystem ¶
func NewSystem(env Env, power config.PowerConfig) *System
NewSystem builds it over the power configuration.
type Type ¶ added in v0.3.3
type Type struct{ Text string }
Type ends the session and enters Text in the window it leaves focused.
type VisitedPages ¶ added in v0.3.5
type VisitedPages struct {
// contains filtered or unexported fields
}
VisitedPages offers the browsers' most visited pages.
func NewVisitedPages ¶ added in v0.3.5
func NewVisitedPages(env Env, index *BrowserIndex, hideBookmarked bool) *VisitedPages
NewVisitedPages offers the visited pages index holds; hideBookmarked leaves out those the bookmarks list too.
func (*VisitedPages) Actions ¶ added in v0.3.5
func (v *VisitedPages) Actions(e Entry) []Action
Actions implements Provider.
func (*VisitedPages) Load ¶ added in v0.3.5
func (v *VisitedPages) Load(ctx context.Context, publish func([]Entry))
Load implements Provider.
func (*VisitedPages) Spec ¶ added in v0.3.5
func (v *VisitedPages) Spec() Spec
Spec implements Provider.
type WatchFunc ¶ added in v0.3.13
WatchFunc calls fn when anything under paths changes (app.WatchFiles).
type Web ¶
type Web struct {
// contains filtered or unexported fields
}
Web is the fallback at the bottom of every list: search the web for what was typed. The template's {query} takes the escaped text.
type Windows ¶
type Windows struct {
// contains filtered or unexported fields
}
Windows offers the open windows to jump to, on whichever compositor the shell runs on. The focused window stays out: nothing to jump to.
func NewWindows ¶
func NewWindows(backend modes.WindowBackend) *Windows
NewWindows uses backend; nil (no compositor it knows) offers nothing.