Documentation
¶
Overview ¶
Package preview fetches a remote pCloud file and renders it for terminal display inside a bubbletea viewport.
Format detection is centralised in GetPreviewType (type.go). Renderers:
- PreviewMarkdown → goldmark + chroma (render_markdown.go)
- PreviewCode → chroma syntax highlight (render_code.go)
- PreviewText → raw string (text.go)
- PreviewPDF → ledongthuc/pdf text extraction (pdf.go)
- PreviewImage → image2ascii colored ASCII art (image.go)
- PreviewCSV → aligned text table (csv.go)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Render ¶
Render renders raw file bytes to a string for terminal display. name is used purely for format detection via GetPreviewType. width and height are the available viewport dimensions; a 2-column border offset is subtracted from width here so all renderers stay within bounds.
func RenderError ¶ added in v1.3.0
RenderError returns a styled terminal string for situations where a preview cannot be shown. The returned string is intended to be set as viewport content — callers should return it alongside a nil error.
func RenderFromURL ¶
RenderFromURL downloads the file at downloadURL and renders its content to a string suitable for display inside a bubbletea viewport. name is the original filename (used for format detection). width and height define the target terminal dimensions.
Types ¶
type PreviewType ¶ added in v1.3.0
type PreviewType string
PreviewType identifies which renderer handles a given file.
const ( PreviewText PreviewType = "text" PreviewMarkdown PreviewType = "markdown" PreviewCode PreviewType = "code" PreviewImage PreviewType = "image" PreviewPDF PreviewType = "pdf" PreviewCSV PreviewType = "csv" PreviewUnsupported PreviewType = "unsupported" )
func GetPreviewType ¶ added in v1.3.0
func GetPreviewType(name string) PreviewType
GetPreviewType returns the PreviewType for the given filename based on its extension. It is the single authoritative source for extension→renderer mapping, replacing both the old CanPreview function and the ext switch in Render.