Skip to main content

kitty_graphics_protocol/
lib.rs

1//! Kitty Graphics Protocol - A Rust library for the Kitty terminal graphics protocol
2//!
3//! This library provides a complete implementation of the Kitty terminal graphics protocol,
4//! allowing you to display images and animations in terminal emulators that support this protocol.
5//!
6//! # Features
7//!
8//! - Full support for all graphics protocol commands
9//! - Support for RGB, RGBA, and PNG image formats
10//! - Chunked data transmission for large images
11//! - Animation support
12//! - Unicode placeholder support
13//! - Terminal size detection
14//! - Protocol support detection
15//!
16//! # Quick Start
17//!
18//! ```no_run
19//! use kitty_graphics_protocol::display_png;
20//!
21//! // Display a PNG file
22//! display_png("image.png").unwrap();
23//! ```
24//!
25//! # Advanced Usage
26//!
27//! ```no_run
28//! use kitty_graphics_protocol::{Command, ImageFormat, Action};
29//!
30//! // Create a command to transmit and display a PNG image
31//! let png_data = std::fs::read("image.png").unwrap();
32//! let cmd = Command::builder()
33//!     .action(Action::TransmitAndDisplay)
34//!     .format(ImageFormat::Png)
35//!     .build();
36//!
37//! // Serialize the command to escape sequence chunks
38//! let chunks: Vec<String> = cmd.serialize_chunked(&png_data).unwrap().collect();
39//! for chunk in chunks {
40//!     print!("{}", chunk);
41//! }
42//! ```
43
44pub mod command;
45pub mod error;
46pub mod image;
47pub mod response;
48pub mod terminal;
49pub mod types;
50
51pub use command::{ChunkedSerializer, Command, CommandBuilder};
52pub use error::{Error, Result};
53pub use image::{ImageDisplay, clear_all_images, display_png, display_png_data};
54pub use response::Response;
55pub use terminal::{WindowSize, check_protocol_support, get_window_size, query_window_size};
56pub use types::{
57    Action, AnimationControl, CompositionMode, Compression, CursorPolicy, DeleteTarget,
58    FrameComposition, ImageFormat, TransmissionMedium, UnicodePlaceholder,
59};
60
61/// The ESC character (0x1b)
62pub const ESC: u8 = 0x1b;
63
64/// The APC (Application Programming Command) start sequence: ESC _
65pub const APC_START: &[u8] = &[ESC, b'_'];
66
67/// The APC end sequence: ESC \
68pub const APC_END: &[u8] = &[ESC, b'\\'];
69
70/// The graphics command prefix: G
71pub const GRAPHICS_PREFIX: &str = "G";
72
73/// Maximum chunk size for data transmission (4096 bytes)
74pub const MAX_CHUNK_SIZE: usize = 4096;