Documentation ¶
Overview ¶
Package termimg provides functionality to render images in terminal emulators that support inline image protocols, specifically the iTerm2 Inline Images Protocol and the Kitty Terminal Graphics Protocol.
This package automatically detects which protocol is supported by the current terminal and renders images accordingly. It supports PNG, JPEG, and WebP image formats.
Main features:
- Automatic detection of supported terminal image protocols
- Support for iTerm2 and Kitty image protocols
- Rendering of PNG, JPEG, and WebP images
- Simple API for rendering images in the terminal
Usage:
To use this package, simply call the RenderImage function with the path to your image:
ti, err := termimg.Open("path/to/your/image.png") if err != nil { log.Fatal(err) } imgstr, err := ti.Render() if err != nil { log.Fatal(err) } fmt.Println(imgstr)
The package will automatically detect the supported protocol and render the image using the appropriate method.
Note that this package requires a terminal that supports either the iTerm2 Inline Images Protocol or the Kitty Terminal Graphics Protocol. If neither protocol is supported, an error will be returned.
For more advanced usage, you can also use the DetectProtocol function to check which protocol is supported:
protocol := termimg.DetectProtocol() switch protocol { case termimg.ITerm2: fmt.Println("iTerm2 protocol supported") case termimg.Kitty: fmt.Println("Kitty protocol supported") default: fmt.Println("No supported protocol detected") }
This package is designed to make it easy to add image rendering capabilities to terminal-based Go applications.
Index ¶
Constants ¶
const ( DATA_RGBA_32_BIT = ",f=32" // default DATA_RGBA_24_BIT = ",f=24" DATA_PNG = ",f=100" COMPRESS_ZLIB = ",0=z" TRANSFER_DIRECT = ",t=d" TRANSFER_FILE = ",t=f" TRANSFER_TEMP = ",t=t" TRANSFER_SHARED = ",t=s" SUPPRESS_OK = ",q=1" SUPPRESS_ERR = ",q=2" )
const ESC_ERASE_DISPLAY = "\x1b[2J\x1b[0;0H"
Variables ¶
var ( ESCAPE = "" START = "" CLOSE = "" )
var ErrEmptyResponse = fmt.Errorf("empty response")
Functions ¶
This section is empty.
Types ¶
type KittyResponse ¶ added in v0.1.14
type TermImg ¶
type TermImg struct {
// contains filtered or unexported fields
}