Documentation
¶
Overview ¶
Package preview renders remote images inside a terminal.
Index ¶
- Variables
- func ASCII(img image.Image, cols, rows int) string
- func BlockSize(src image.Rectangle, cols, rows int) (int, int)
- func Decode(r io.Reader) (image.Image, error)
- func Fit(src image.Rectangle, cols, rows int) (w, h int)
- func HalfBlocks(img image.Image, cols, rows int) string
- func Inline(img image.Image, mode Mode, cols, rows int) (s string, ok bool)
- func Render(img image.Image, mode Mode, cols, rows int) string
- func Resize(img image.Image, w, h int) *image.RGBA
- type Fetcher
- type Mode
Constants ¶
This section is empty.
Variables ¶
var Modes = []string{"auto", "iterm", "kitty", "blocks", "ascii", "none"}
Modes lists every accepted --preview value.
Functions ¶
func ASCII ¶
ASCII renders an image as monochrome characters, for terminals without 24-bit colour. One character is one pixel, so the source is squashed vertically to compensate for cells being about twice as tall as wide.
func BlockSize ¶
BlockSize reports the character grid HalfBlocks will actually produce, so callers can lay out around it without measuring escape codes.
func Fit ¶
Fit returns the pixel size that fits src into a cols x rows character grid, assuming half-block rendering (2 image rows per text row) and terminal cells roughly twice as tall as wide.
func HalfBlocks ¶
HalfBlocks renders an image as text using the upper-half-block character: the foreground colour is the top pixel and the background the bottom one, giving two vertical pixels per character cell. Works in any 24-bit-colour terminal, including inside a full-screen TUI, unlike inline image protocols.
func Inline ¶
Inline renders an image using a terminal graphics protocol. The returned string is a single escape sequence that draws at the cursor and occupies `cols` columns; ok is false when mode is not a graphics protocol.
Types ¶
type Fetcher ¶
type Fetcher struct {
Dir string // disk cache directory; empty disables it
Client *http.Client
// contains filtered or unexported fields
}
Fetcher downloads and decodes thumbnails, caching the bytes on disk and the decoded images in memory so scrolling a result list stays instant.
func NewFetcher ¶
NewFetcher returns a Fetcher caching into dir.
type Mode ¶
type Mode string
Mode is how a preview is drawn.