Beyond ASCII Art: Display Real Images in (Kitty) Terminals with Rust (Terminal Graphics Protocol)

Опубликовано: 11 Май 2026
на канале: MrJakob
4,936
94

In this coding session, I explore the Terminal Graphics Protocol (TGP). Together with you I investigate how to display images directly in the terminal, starting from absolute zero knowledge.

What we cover:
Reading through the protocol specification together
Setting up a basic Rust project to experiment with the protocol
Implementing just enough to display a PNG image in the terminal
Exploring how to make it work with tmux using passthrough mode
Using alternate screen mode for improved display

This is very much an exploratory session - we're figuring things out as we go, with some trial and error along the way. By the end, we manage to display a PNG image in the terminal, which serves as a starting point for potential future work.

This might later lead to integration with my PixelLoop project, though that's not decided yet. If you enjoy learning alongside someone who's also discovering things for the first time, this session demonstrates the process of diving into a protocol specification and bringing it to life through code.

Note: I don't implement the full protocol in this session - just enough to understand the basics and display the first image.

Github Repository: https://github.com/jakobwesthoff/kitt...

Chapters:

00:00:00 - The Terminal Graphics Protocol
00:00:36 - Detour: awrit - How cool is that?
00:01:40 - The Plan for today
00:03:03 - Initializing our Rust Project
00:04:51 - Analyzing the Terminal Graphics Protocol Specs
00:10:56 - Starting the Implementation
00:13:23 - Creating a TerminalRawMode Guard
00:17:00 - Graphics Protocol Message Encoding
00:21:10 - DisplayLocalPngFile Message
00:24:30 - Protocol Message Encoding
00:28:56 - Encoding Control Data
00:33:38 - Base64 encoding the Path
00:38:40 - First try to display an Image
00:39:11 - Analyzing the Problem
00:41:02 - Difference between Placement and Transmission
00:43:02 - Success!
00:46:40 - Passing through tmux
00:49:45 - Refactoring the Message struct
00:57:44 - Implement TmuxWrappedMessage
01:09:34 - Trying out the tmux passthrough
01:10:25 - Different Terminals, different Behaviour
01:11:48 - Switching to Alternate Mode
01:18:40 - Trying out the Alternate Screen Switch
01:22:08 - Explaining Alternate Mode
01:23:12 - Conclusion