Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdd348ac6c3

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 three data fields 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 text and note should be (truncation messaging, byte counts, hexdumps, etc. are all the caller's job).
  • scrollHeight defaults to 480; only applies when data.text is non-nil (the body is wrapped in a scroll container).
  • The copy-path button is only rendered when opts.onCopyPath is set; the click emits that callback id verbatim so the caller routes it.