pencere

Components / Lists and data

u:palette

A palette: a field and under it the items that its query is in, the best first, the first one chosen.

A palette: a field and under it the items that its query is in, the best first, the first one chosen. A palette: a field and under it the items that its query is in, the best first, the first one chosen.

The code

local ui = require("@pencere/ui")

local commands = ui.commands({
	{ id = "open", title = "Open file", group = "File", keys = "mod+p" },
	{ id = "save", title = "Save", group = "File", keys = "mod+s" },
	{ id = "find", title = "Find in files", group = "Search", keys = "mod+shift+f" },
	{ id = "replace", title = "Replace in files", group = "Search", keys = "mod+shift+h" },
	{ id = "close_tab", title = "Close tab", group = "View", keys = "mod+w" },
	{ id = "split", title = "Split the pane", group = "View" },
})
local items = commands:items()
local state = { query = "", cursor = nil }

root:child(u:palette("palette", { items = items, state = state, label = "Command palette", hint = "Type a command",
	footer = { { keys = "enter", title = "Run" }, { keys = "escape", title = "Close" } } }))

What it does

A palette: a field and under it the items that its query is in (fuzzily: @pencere/fuzzy; with filter, a function (query, items) → items, the page's own way: its modes, its prefixes), the best first, the first one chosen. items are { key, title, hint, keys, enabled, icon } (commands, files …): pass the same table while they are the same (or version), or the search is made again at every frame. Over a few thousand items the search goes on a step to a frame while the person types. state is { query, cursor }: the page keeps it (a palette opened again has its query selected, so that typing replaces it) and puts the query in it to make one open on a word. The field has the keyboard: the arrow keys and page up and down move the cursor, enter picks (pick { item }), a click on a row picks it, escape and a click outside it give up (dismiss), and backspace in the empty field is back (the page leaves a mode). Each change of the query is query { text }. footer is the keys it says at its foot: { { keys = "enter", title = "Run" } }. rows is how many rows it shows at the most (8), height how tall a row is (32) and inset the points around the rows (4). On the cells of a terminal (pencere.draws().cells) a row is the theme's row, which is one, and there is no inset, unless the page says: a row of 32 points is two rows of cells, and four points are none.

kit/sandbox/library/ui/lists.luau, line 378