Builtin Library
README.md
preview
File preview pane — header, optional note line ("Size: 12345 bytes" /
"Truncated: ..."), separator, and the body. Body is monospace text
when text is non-nil, or a "(no preview)" line when nil. Stateless:
caller decides what text/note should be by reading the file (e.g.
via vfs.read).
Exports
preview(data: PreviewData?, opts: PreviewOpts?) -> WidgetNode— build the preview pane. When all threedatafields are nil, renders a "Select a file to preview." placeholder.
Types:
PreviewData = { name: string?, text: string?, note: string? }PreviewOpts = { id: string?, scrollHeight: number?, onCopyPath: string? }WidgetNode = { [string]: any }
Usage
local Z = require("@builtin::modules.zui")
return Z.fs.preview({
name = state.name,
text = state.text,
note = "Size: " .. tostring(state.size) .. " bytes",
}, {
id = "files-preview",
scrollHeight = 480,
onCopyPath = "files-copy",
})
Notes
- Stateless. Caller owns the file read and decides what
textandnoteshould be (truncation messaging, byte counts, hexdumps, etc. are all the caller's job). scrollHeightdefaults to 480; only applies whendata.textis non-nil (the body is wrapped in ascrollcontainer).- The copy-path button is only rendered when
opts.onCopyPathis set; the click emits that callback id verbatim so the caller routes it.