Demo Application
The examples/demo package provides an interactive walkthrough of KGP features.
Running the Demo
bash
cd examples/demo
go run .Place a file named sf.png in the demo directory for the external PNG loading demo.
Demo Sequence
- Image Formats — PNG, RGBA, RGB
- Compression — ZLIB compressed RGBA
- External PNG — Load from
sf.png - Cropping and Scaling — Source rect and display size
- Multiple Placements — One image, multiple displays
- Placement Sizes — Same image at different cell sizes
- Z-Index — Background image behind text
- Query Support — Check terminal capabilities
- Animation — Color-changing square with movement
Code Structure
go
// Clear screen
fmt.Print("\x1b[2J\x1b[H")
// Create image data
redSquare := createColoredSquare(100, 100, color.RGBA{R: 255, G: 0, B: 0, A: 255})
pngData, _ := kgp.ImageToPNG(redSquare)
// Transmit and display
cmd := kgp.NewTransmitDisplay().
ImageID(1).
Format(kgp.FormatPNG).
TransmitDirect(pngData).
ResponseSuppression(kgp.ResponseErrorsOnly).
Build()
fmt.Print(cmd.Encode())Helper Functions in Demo
createColoredSquare(width, height, color)— Solid color imagecreateGradientSquare(width, height)— Gradient for cropping democlearScreen()— ANSI clear and homewaitForEnter(reader)— Pause for user input