Examples

Practical examples for common KGP use cases. All code is runnable and assumes you have imported github.com/SerenaFontaine/kgp.

Quick Navigation

Basic Image Display

PNG from File go Copy package main import ( "fmt" "os" "github.com/SerenaFontaine/kgp" ) func …

Multiple Placements

Transmit once, display many times. Saves bandwidth and memory. Transmit Then Put go Copy // 1. Transmit image (no …

Cropping and Scaling

Source Rect (Crop) Display only a portion of the source image. go Copy // Display top-left 400×300 region cmd := …

Z-Index Layering

Control whether images appear above or below text. Negative z-index: below text (background) Positive z-index: above …

Deletion

Delete All Placements Keep image data in memory for reuse: go Copy fmt.Print(kgp.DeleteAll().Encode()) Free everything: …

Animation

Basic Animation Flow Transmit base frame (or first frame) Add frames with NewFrame Create placement Control playback …

Relative Positioning

Place child images relative to a parent placement. Useful for overlays, badges, and anchored UI elements. Parent and …

Chunked Transmission

For large images or remote connections (e.g., SSH), split the payload into chunks. The terminal reassembles them. Basic …

Compression

ZLIB compression reduces payload size for raw RGB/RGBA data. PNG is already compressed. Compress RGBA go Copy rgbaData …

File and Shared Memory Transmission

Alternatives to embedding data directly in escape sequences. Transmit from File go Copy cmd := kgp.NewTransmitDisplay(). …

Error Handling

Parse terminal responses to detect and handle errors. Basic Parsing go Copy resp, err := kgp.ParseResponse(responseStr) …

Demo Application

The examples/demo package provides an interactive walkthrough of KGP features. Running the Demo bash Copy cd …