···44 OCaml programs to display images in terminals that support the protocol
55 (Kitty, WezTerm, Konsole, Ghostty, etc.).
6677- The protocol uses APC (Application Programming Command) escape sequences
88- to transmit and display pixel graphics. Images can be transmitted as raw
99- RGB/RGBA data or PNG, and displayed at specific positions with various
1010- placement options.
77+ {1 Protocol Overview}
88+99+ The Kitty Graphics Protocol is a flexible, performant protocol for rendering
1010+ arbitrary pixel (raster) graphics in terminal emulators. Key features:
1111+1212+ - No requirement for terminal emulators to understand image formats
1313+ - Pixel-level positioning of graphics
1414+ - Integration with text (graphics can be drawn below/above text with alpha blending)
1515+ - Automatic scrolling with text
1616+ - Animation support with frame deltas for efficiency
1717+1818+ {2 Escape Sequence Format}
1919+2020+ All graphics commands use the Application Programming Command (APC) format:
2121+2222+ {v <ESC>_G<control data>;<payload><ESC>\ v}
2323+2424+ Where:
2525+ - [ESC _G] is the APC start sequence (bytes 0x1B 0x5F 0x47)
2626+ - Control data is comma-separated key=value pairs
2727+ - Payload is base64-encoded binary data (RFC-4648)
2828+ - [ESC] is the APC terminator (bytes 0x1B 0x5C)
2929+3030+ Most terminal emulators ignore unrecognized APC sequences, making the
3131+ protocol safe to use even in unsupported terminals.
3232+3333+ {2 Terminal Responses}
3434+3535+ When an image ID is specified, the terminal responds:
3636+ - On success: [ESC _Gi=ID;OK ESC]
3737+ - On failure: [ESC _Gi=ID;error ESC]
3838+3939+ Common error codes include [ENOENT] (image not found), [EINVAL] (invalid
4040+ parameter), and [ENOSPC] (storage quota exceeded).
4141+4242+ {2 Image Storage}
4343+4444+ Terminal emulators maintain a storage quota for images (typically ~320MB).
4545+ When the quota is exceeded, older images are deleted to make room for new
4646+ ones. Images without active placements are preferred for deletion.
4747+4848+ For animations, frame data is stored separately with a larger quota
4949+ (typically 5x the base quota).
11501251 {2 Basic Usage}
13521453 {[
1554 (* Display a PNG image *)
1655 let png_data = read_file "image.png" in
1717- let cmd = Kgp.Command.transmit_and_display ~format:`Png () in
5656+ let cmd = Kgp.transmit_and_display ~format:`Png () in
1857 let buf = Buffer.create 1024 in
1919- Kgp.Command.write buf cmd ~data:png_data;
5858+ Kgp.write buf cmd ~data:png_data;
2059 print_string (Buffer.contents buf)
2160 ]}
22616262+ {[
6363+ (* Transmit an image, then display it multiple times *)
6464+ let png_data = read_file "icon.png" in
6565+ let cmd = Kgp.transmit ~image_id:1 ~format:`Png () in
6666+ Kgp.write buf cmd ~data:png_data;
6767+6868+ (* Display at different positions *)
6969+ let cmd = Kgp.display ~image_id:1 () in
7070+ Kgp.write buf cmd ~data:"";
7171+ ]}
7272+2373 {2 Protocol Reference}
24742575 See {{:https://sw.kovidgoyal.net/kitty/graphics-protocol/} Kitty Graphics Protocol}
···4393module Animation = Kgp_animation
4494module Compose = Kgp_compose
45954646-(** {1 Command and Response} *)
9696+(** {1 Commands} *)
9797+9898+type command = Kgp_command.t
9999+(** A graphics protocol command. Commands are built using the functions below
100100+ and then serialized using {!write} or {!to_string}. *)
101101+102102+(** {2 Image Transmission}
103103+104104+ Images can be transmitted to the terminal for storage and later display.
105105+ The terminal assigns storage and responds with success or failure.
106106+107107+ For large images, the library automatically handles chunked transmission
108108+ (splitting data into 4096-byte base64-encoded chunks). *)
109109+110110+val transmit :
111111+ ?image_id:int ->
112112+ ?image_number:int ->
113113+ ?format:Format.t ->
114114+ ?transmission:Transmission.t ->
115115+ ?compression:Compression.t ->
116116+ ?width:int ->
117117+ ?height:int ->
118118+ ?size:int ->
119119+ ?offset:int ->
120120+ ?quiet:Quiet.t ->
121121+ unit ->
122122+ command
123123+(** Transmit image data without displaying.
124124+125125+ The image is stored by the terminal and can be displayed later using
126126+ {!val:display} with the same [image_id].
127127+128128+ @param image_id Unique identifier (1-4294967295) for later reference.
129129+ If specified, the terminal responds with success/failure.
130130+ @param image_number Alternative to [image_id] where the terminal assigns
131131+ a unique ID and returns it in the response. Useful when multiple
132132+ programs share the terminal.
133133+ @param format Pixel format of the data. Default is [`Rgba32].
134134+ @param transmission How data is sent. Default is [`Direct] (inline).
135135+ @param compression Compression applied to data. Default is [`None].
136136+ @param width Image width in pixels (required for raw RGB/RGBA formats).
137137+ @param height Image height in pixels (required for raw RGB/RGBA formats).
138138+ @param size Size in bytes when reading from file.
139139+ @param offset Byte offset when reading from file.
140140+ @param quiet Response suppression level. *)
141141+142142+val transmit_and_display :
143143+ ?image_id:int ->
144144+ ?image_number:int ->
145145+ ?format:Format.t ->
146146+ ?transmission:Transmission.t ->
147147+ ?compression:Compression.t ->
148148+ ?width:int ->
149149+ ?height:int ->
150150+ ?size:int ->
151151+ ?offset:int ->
152152+ ?quiet:Quiet.t ->
153153+ ?placement:Placement.t ->
154154+ unit ->
155155+ command
156156+(** Transmit image data and display it immediately.
157157+158158+ Combines transmission and display in a single command. The image is
159159+ rendered at the current cursor position unless placement options
160160+ specify otherwise.
161161+162162+ See {!transmit} for parameter descriptions. The [placement] parameter
163163+ controls display position and scaling. *)
471644848-module Command = Kgp_command
165165+val query :
166166+ ?format:Format.t ->
167167+ ?transmission:Transmission.t ->
168168+ ?width:int ->
169169+ ?height:int ->
170170+ ?quiet:Quiet.t ->
171171+ unit ->
172172+ command
173173+(** Query terminal support without storing the image.
174174+175175+ Performs the same validation as {!transmit} but does not store the
176176+ image. Useful for testing whether the terminal supports the graphics
177177+ protocol and specific formats.
178178+179179+ To detect graphics support, send a query and check for a response:
180180+ {[
181181+ (* Send query with a tiny 1x1 RGB image *)
182182+ let cmd = Kgp.query ~format:`Rgb24 ~width:1 ~height:1 () in
183183+ Kgp.write buf cmd ~data:"\x00\x00\x00"
184184+ (* If terminal responds, it supports the protocol *)
185185+ ]} *)
186186+187187+(** {2 Display}
188188+189189+ Previously transmitted images can be displayed multiple times at
190190+ different positions with different cropping and scaling options. *)
191191+192192+val display :
193193+ ?image_id:int ->
194194+ ?image_number:int ->
195195+ ?placement:Placement.t ->
196196+ ?quiet:Quiet.t ->
197197+ unit ->
198198+ command
199199+(** Display a previously transmitted image.
200200+201201+ The image is rendered at the current cursor position. Use [placement]
202202+ to control cropping, scaling, z-index, and other display options.
203203+204204+ Each display creates a "placement" of the image. Multiple placements
205205+ of the same image share the underlying image data.
206206+207207+ @param image_id ID of a previously transmitted image.
208208+ @param image_number Image number (acts on the newest image with this number).
209209+ @param placement Display configuration (position, size, z-index, etc.). *)
210210+211211+(** {2 Deletion}
212212+213213+ Images and placements can be deleted to free terminal resources.
214214+ Lowercase delete commands remove placements but keep image data;
215215+ uppercase variants also free the image data. *)
216216+217217+val delete : ?quiet:Quiet.t -> Delete.t -> command
218218+(** Delete images or placements.
219219+220220+ See {!Delete} for the full list of deletion targets.
221221+222222+ Examples:
223223+ {[
224224+ (* Delete all visible images *)
225225+ Kgp.delete `All_visible
226226+227227+ (* Delete specific image, keeping data for reuse *)
228228+ Kgp.delete (`By_id (42, None))
229229+230230+ (* Delete specific image and free its data *)
231231+ Kgp.delete (`By_id_and_free (42, None))
232232+233233+ (* Delete all placements at a specific cell *)
234234+ Kgp.delete (`At_cell (10, 5))
235235+ ]} *)
236236+237237+(** {2 Animation}
238238+239239+ The protocol supports both client-driven and terminal-driven animations.
240240+ Animations are created by first transmitting a base image, then adding
241241+ frames with optional delta encoding for efficiency.
242242+243243+ Frame numbers are 1-based: frame 1 is the root (base) image, frame 2
244244+ is the first added frame, etc. *)
245245+246246+val frame :
247247+ ?image_id:int ->
248248+ ?image_number:int ->
249249+ ?format:Format.t ->
250250+ ?transmission:Transmission.t ->
251251+ ?compression:Compression.t ->
252252+ ?width:int ->
253253+ ?height:int ->
254254+ ?quiet:Quiet.t ->
255255+ frame:Frame.t ->
256256+ unit ->
257257+ command
258258+(** Transmit animation frame data.
259259+260260+ Adds a new frame to an existing image or edits an existing frame.
261261+ The frame can be a full image or a partial update (rectangle).
262262+263263+ Use {!Frame.make} to configure the frame's position, timing, and
264264+ composition options.
265265+266266+ @param frame Frame configuration including timing and composition. *)
267267+268268+val animate :
269269+ ?image_id:int ->
270270+ ?image_number:int ->
271271+ ?quiet:Quiet.t ->
272272+ Animation.t ->
273273+ command
274274+(** Control animation playback.
275275+276276+ For terminal-driven animation:
277277+ {[
278278+ (* Start infinite loop animation *)
279279+ Kgp.animate ~image_id:1 (Animation.set_state ~loops:1 `Run)
280280+281281+ (* Stop animation *)
282282+ Kgp.animate ~image_id:1 (Animation.set_state `Stop)
283283+284284+ (* Change frame timing *)
285285+ Kgp.animate ~image_id:1 (Animation.set_gap ~frame:3 ~gap_ms:100)
286286+ ]}
287287+288288+ For client-driven animation:
289289+ {[
290290+ (* Manually advance to specific frame *)
291291+ Kgp.animate ~image_id:1 (Animation.set_current_frame 5)
292292+ ]} *)
293293+294294+val compose :
295295+ ?image_id:int ->
296296+ ?image_number:int ->
297297+ ?quiet:Quiet.t ->
298298+ Compose.t ->
299299+ command
300300+(** Compose animation frames.
301301+302302+ Copies a rectangular region from one frame onto another. Useful for
303303+ building complex frames from simpler components.
304304+305305+ {[
306306+ (* Copy a 50x50 region from frame 2 to frame 5 *)
307307+ let comp = Compose.make
308308+ ~source_frame:2 ~dest_frame:5
309309+ ~width:50 ~height:50
310310+ ~source_x:10 ~source_y:10
311311+ ~dest_x:20 ~dest_y:20 () in
312312+ Kgp.compose ~image_id:1 comp
313313+ ]} *)
314314+315315+(** {2 Output}
316316+317317+ Commands are serialized to escape sequences that can be written
318318+ to the terminal. *)
319319+320320+val write : Buffer.t -> command -> data:string -> unit
321321+(** Write the command to a buffer.
322322+323323+ The [data] parameter contains the raw image/frame data (before base64
324324+ encoding). Pass an empty string for commands that don't include payload
325325+ data (like {!val:display}, {!val:delete}, {!val:animate}).
326326+327327+ The library handles base64 encoding and chunking automatically. *)
328328+329329+val to_string : command -> data:string -> string
330330+(** Convert command to a string.
331331+332332+ Convenience wrapper around {!write} that returns the serialized
333333+ command as a string. *)
334334+335335+(** {1 Response} *)
336336+49337module Response = Kgp_response
5033851339(** {1 Utilities} *)
5234053341module Unicode_placeholder = Kgp_unicode
54342module Detect = Kgp_detect
343343+344344+(** {1 Low-level Access} *)
345345+346346+module Command = Kgp_command
347347+(** Low-level command module. The command functions are also available
348348+ at the top level of this module for convenience. *)
+92-8
lib/kgp_animation.mli
···11-(** Kitty Graphics Protocol Animation
11+(** Animation Control
22+33+ Operations for controlling animation playback. The protocol supports
44+ both terminal-driven and client-driven animation modes.
55+66+ {2 Protocol Overview}
77+88+ Animation control uses action [a=a] with various keys:
99+ - [s]: Set playback state (1=stop, 2=loading, 3=run)
1010+ - [c]: Set current frame (1-based frame number)
1111+ - [r]: Target frame number for gap changes
1212+ - [z]: Frame gap/delay in milliseconds
1313+ - [v]: Loop count
21433- Animation control operations. *)
1515+ {2 Terminal-Driven Animation}
1616+1717+ The terminal automatically advances frames based on each frame's gap
1818+ (delay). To start terminal-driven animation:
1919+2020+ {[
2121+ (* Start infinite loop *)
2222+ Kgp.animate ~image_id:1 (Animation.set_state ~loops:1 `Run)
2323+2424+ (* Run 3 times then stop *)
2525+ Kgp.animate ~image_id:1 (Animation.set_state ~loops:4 `Run)
2626+2727+ (* Stop animation *)
2828+ Kgp.animate ~image_id:1 (Animation.set_state `Stop)
2929+ ]}
3030+3131+ {2 Client-Driven Animation}
3232+3333+ The client manually controls which frame is displayed:
3434+3535+ {[
3636+ (* Display specific frame *)
3737+ Kgp.animate ~image_id:1 (Animation.set_current_frame 5)
3838+3939+ (* Advance to next frame in application logic *)
4040+ let next_frame = (current_frame mod total_frames) + 1 in
4141+ Kgp.animate ~image_id:1 (Animation.set_current_frame next_frame)
4242+ ]}
4343+4444+ {2 Modifying Frame Timing}
4545+4646+ Frame gaps can be changed during playback:
4747+4848+ {[
4949+ (* Slow down frame 3 *)
5050+ Kgp.animate ~image_id:1 (Animation.set_gap ~frame:3 ~gap_ms:200)
5151+5252+ (* Make frame 5 instant/gapless *)
5353+ Kgp.animate ~image_id:1 (Animation.set_gap ~frame:5 ~gap_ms:(-1))
5454+ ]}
5555+5656+ {2 Loop Counting}
5757+5858+ The [loops] parameter in {!set_state}:
5959+ - 0: Ignored (doesn't change loop setting)
6060+ - 1: Infinite loop
6161+ - n > 1: Loop (n-1) times, then stop *)
462563type t =
664 [ `Set_state of Kgp_animation_state.t * int option
765 | `Set_gap of int * int
866 | `Set_current of int ]
99-(** Animation control operations. *)
6767+(** Animation control operations.
6868+6969+ - [`Set_state (state, loops)] - Set animation playback state with
7070+ optional loop count.
7171+ - [`Set_gap (frame, gap_ms)] - Set the delay for a specific frame.
7272+ - [`Set_current frame] - Jump to a specific frame (1-based). *)
10731174val set_state : ?loops:int -> Kgp_animation_state.t -> t
1212-(** Set animation state.
1313- @param loops Number of loops: 0 = ignored, 1 = infinite, n = n-1 loops *)
7575+(** Set animation playback state.
7676+7777+ @param loops Loop count: 0 = ignored, 1 = infinite, n > 1 = (n-1) loops.
7878+ Protocol key: [v].
7979+ @param state The target playback state.
8080+8181+ Examples:
8282+ {[
8383+ set_state `Run (* Run with current loop setting *)
8484+ set_state ~loops:1 `Run (* Run infinitely *)
8585+ set_state ~loops:3 `Run (* Run twice, then stop *)
8686+ set_state `Stop (* Pause animation *)
8787+ set_state `Loading (* Run, wait for more frames at end *)
8888+ ]} *)
14891590val set_gap : frame:int -> gap_ms:int -> t
1691(** Set the gap (delay) for a specific frame.
1717- @param frame 1-based frame number
1818- @param gap_ms Delay in milliseconds (negative = gapless) *)
9292+9393+ @param frame 1-based frame number to modify. Protocol key: [r].
9494+ @param gap_ms Delay in milliseconds before next frame. Negative values
9595+ create gapless frames (not displayed, instant skip). Protocol key: [z].
9696+9797+ Note: Frame 1 is the root/base image. Use 2+ for added frames. *)
19982099val set_current_frame : int -> t
2121-(** Make a specific frame (1-based) the current displayed frame. *)
100100+(** Make a specific frame the current displayed frame.
101101+102102+ @param frame 1-based frame number to display. Protocol key: [c].
103103+104104+ Used for client-driven animation where the application controls
105105+ frame advancement rather than the terminal. *)
+55-5
lib/kgp_animation_state.mli
···11(** Animation Playback State
2233- Controls the playback state of animated images. *)
33+ Controls the playback state of animated images.
44+55+ {2 Protocol Details}
66+77+ The animation state is specified via the [s] key in the control data
88+ when using action [a=a]:
99+ - [s=1]: stop animation
1010+ - [s=2]: run in loading mode
1111+ - [s=3]: run normally
1212+1313+ {2 Animation Modes}
1414+1515+ The protocol supports two animation approaches:
1616+1717+ {b Terminal-driven animation}: The terminal automatically advances
1818+ frames based on the gap (delay) specified for each frame. Use
1919+ [{`Run}] or [{`Loading}] states.
2020+2121+ {b Client-driven animation}: The client manually sets the current
2222+ frame using [Kgp.Animation.set_current_frame]. Use [{`Stop}] state
2323+ to prevent automatic advancement.
2424+2525+ {2 Stop State}
2626+2727+ [{`Stop}] halts automatic frame advancement. The animation freezes
2828+ on the current frame. Use this when:
2929+ - Implementing client-driven animation
3030+ - Pausing an animation
3131+ - Displaying a static frame from an animated image
3232+3333+ {2 Loading State}
3434+3535+ [{`Loading}] runs the animation but waits for new frames when reaching
3636+ the end instead of looping. Use this when:
3737+ - Streaming animation frames progressively
3838+ - Building an animation while displaying it
3939+ - The animation is not yet complete
4040+4141+ {2 Run State}
4242+4343+ [{`Run}] runs the animation normally, looping back to the first frame
4444+ after the last. The loop count can be controlled via the [loops]
4545+ parameter in [Kgp.Animation.set_state]. *)
446547type t = [ `Stop | `Loading | `Run ]
648(** Animation playback states.
74988- - [`Stop] - Halt animation playback
99- - [`Loading] - Run animation but wait for new frames at end
1010- - [`Run] - Run animation normally and loop *)
5050+ - [`Stop] - Halt animation playback. The animation freezes on the
5151+ current frame and does not advance automatically.
5252+ - [`Loading] - Run animation but wait for new frames at end. When
5353+ the last frame is reached, the animation pauses until more frames
5454+ are added, then continues.
5555+ - [`Run] - Run animation normally and loop. After the last frame,
5656+ playback returns to the first frame (or stops after the specified
5757+ number of loops). *)
11581259val to_int : t -> int
1313-(** Convert to protocol integer (1, 2, or 3). *)
6060+(** Convert to protocol integer.
6161+6262+ Returns 1 for [`Stop], 2 for [`Loading], or 3 for [`Run].
6363+ These values are used in the [s=] control data key. *)
+88-4
lib/kgp_compose.mli
···11-(** Kitty Graphics Protocol Compose
11+(** Frame Composition
22+33+ Operations for compositing rectangular regions between animation frames.
44+ This allows building complex frames from simpler components.
55+66+ {2 Protocol Overview}
77+88+ Frame composition uses action [a=c] to copy a rectangular region from
99+ one frame onto another. This is useful for:
1010+1111+ - Building frames from reusable sprite components
1212+ - Applying partial updates to existing frames
1313+ - Creating complex animations efficiently
1414+1515+ {2 Coordinate System}
1616+1717+ All coordinates are in pixels, relative to the top-left corner of
1818+ the respective frame:
21933- Frame composition operations. *)
2020+ - [source_x], [source_y]: Top-left of rectangle in source frame
2121+ - [dest_x], [dest_y]: Top-left of destination in target frame
2222+ - [width], [height]: Size of the rectangle to copy
2323+2424+ If width/height are omitted, the entire source frame is used.
2525+2626+ {2 Composition Mode}
2727+2828+ The [composition] parameter controls blending:
2929+ - [{`Alpha_blend}]: Standard alpha compositing (default)
3030+ - [{`Overwrite}]: Direct pixel replacement
3131+3232+ {2 Error Conditions}
3333+3434+ The terminal responds with errors for:
3535+ - [ENOENT]: Source or destination frame doesn't exist
3636+ - [EINVAL]: Rectangle out of bounds, or source equals destination
3737+ with overlapping regions
3838+ - [ENOSPC]: Not enough storage after composition
3939+4040+ {2 Example}
4141+4242+ {[
4343+ (* Copy a 32x32 sprite from frame 2 to frame 5 *)
4444+ let comp = Compose.make
4545+ ~source_frame:2 ~dest_frame:5
4646+ ~width:32 ~height:32
4747+ ~source_x:0 ~source_y:0 (* From top-left of source *)
4848+ ~dest_x:100 ~dest_y:50 () (* To position in dest *)
4949+ in
5050+ Kgp.compose ~image_id:1 comp
5151+ ]} *)
452553type t
66-(** Composition operation. *)
5454+(** Composition operation. Opaque type; use {!make} to construct. *)
755856val make :
957 source_frame:int ->
···1765 ?composition:Kgp_composition.t ->
1866 unit ->
1967 t
2020-(** Compose a rectangle from one frame onto another. *)
6868+(** Create a composition operation.
6969+7070+ @param source_frame 1-based frame number to copy from. Required.
7171+ Protocol key: [r].
7272+ @param dest_frame 1-based frame number to copy onto. Required.
7373+ Protocol key: [c].
7474+ @param width Width of rectangle in pixels. Default is full frame.
7575+ Protocol key: [w].
7676+ @param height Height of rectangle in pixels. Default is full frame.
7777+ Protocol key: [h].
7878+ @param source_x Left edge of source rectangle (default 0).
7979+ Protocol key: [X].
8080+ @param source_y Top edge of source rectangle (default 0).
8181+ Protocol key: [Y].
8282+ @param dest_x Left edge of destination position (default 0).
8383+ Protocol key: [x].
8484+ @param dest_y Top edge of destination position (default 0).
8585+ Protocol key: [y].
8686+ @param composition Blending mode. Default is alpha blending.
8787+ Protocol key: [C]. *)
21882289(** {1 Field Accessors} *)
23902491val source_frame : t -> int
9292+(** 1-based source frame number. *)
9393+2594val dest_frame : t -> int
9595+(** 1-based destination frame number. *)
9696+2697val width : t -> int option
9898+(** Width of rectangle in pixels. *)
9999+27100val height : t -> int option
101101+(** Height of rectangle in pixels. *)
102102+28103val source_x : t -> int option
104104+(** Left edge of source rectangle. *)
105105+29106val source_y : t -> int option
107107+(** Top edge of source rectangle. *)
108108+30109val dest_x : t -> int option
110110+(** Left edge of destination position. *)
111111+31112val dest_y : t -> int option
113113+(** Top edge of destination position. *)
114114+32115val composition : t -> Kgp_composition.t option
116116+(** Blending mode for composition. *)
+39-4
lib/kgp_composition.mli
···11(** Pixel Composition Mode
2233- Controls how pixels are blended when compositing images or animation frames. *)
33+ Controls how pixels are blended when compositing images or animation frames.
44+55+ {2 Protocol Details}
66+77+ The composition mode is specified via the [X] key in the control data
88+ (for animation frames) or the [C] key (for frame composition operations):
99+ - Value 0 or omitted: alpha blending (default)
1010+ - Value 1: simple overwrite/replacement
1111+1212+ {2 Alpha Blending}
1313+1414+ [{`Alpha_blend}] performs standard alpha compositing using the source
1515+ pixel's alpha channel. For each pixel:
1616+ - If source alpha is 255 (opaque), source pixel replaces destination
1717+ - If source alpha is 0 (transparent), destination pixel is unchanged
1818+ - Otherwise, colors are blended proportionally
1919+2020+ This mode is essential for:
2121+ - Transparent PNG images
2222+ - Overlaying graphics on backgrounds
2323+ - Anti-aliased edges and text
2424+2525+ {2 Overwrite Mode}
2626+2727+ [{`Overwrite}] simply replaces destination pixels with source pixels,
2828+ ignoring the alpha channel. This is useful for:
2929+ - Performance optimization when transparency isn't needed
3030+ - Replacing rectangular regions entirely
3131+ - Animation frames that completely replace the previous frame *)
432533type t = [ `Alpha_blend | `Overwrite ]
634(** Composition modes.
73588- - [`Alpha_blend] - Full alpha blending (default)
99- - [`Overwrite] - Simple pixel replacement *)
3636+ - [`Alpha_blend] - Full alpha blending (default). Source pixels are
3737+ composited onto the destination using standard Porter-Duff "over"
3838+ compositing based on the source alpha channel.
3939+ - [`Overwrite] - Simple pixel replacement. Source pixels completely
4040+ replace destination pixels, ignoring alpha values. Faster but no
4141+ transparency support. *)
10421143val to_int : t -> int
1212-(** Convert to protocol integer (0 or 1). *)
4444+(** Convert to protocol integer.
4545+4646+ Returns 0 for [`Alpha_blend] or 1 for [`Overwrite].
4747+ These values are used in the [X=] or [C=] control data keys. *)
+35-5
lib/kgp_compression.mli
···11(** Data Compression
2233- Specifies compression applied to image data before transmission. *)
33+ Specifies compression applied to image data before transmission.
44+55+ {2 Protocol Details}
66+77+ Compression is specified via the [o] key in the control data:
88+ - No [o] key means no compression
99+ - [o=z] means zlib (RFC 1950 DEFLATE) compression
1010+1111+ Compression is applied to the raw pixel/PNG data {i before} base64
1212+ encoding. The terminal decompresses after base64 decoding.
1313+1414+ {2 When to Use Compression}
1515+1616+ Zlib compression is beneficial for:
1717+ - Large images with repetitive patterns
1818+ - Screenshots and UI graphics
1919+ - Images with large solid color regions
2020+2121+ It may not help (or could increase size) for:
2222+ - Already-compressed PNG data
2323+ - Photographic images with high entropy
2424+ - Very small images (compression overhead)
2525+2626+ {2 PNG with Compression}
2727+2828+ When using both [{`Png}] format and [{`Zlib}] compression, the [size]
2929+ parameter must be specified with the original (uncompressed) PNG size.
3030+ The terminal needs this to allocate the correct buffer for decompression. *)
431532type t = [ `None | `Zlib ]
633(** Compression options.
73488- - [`None] - Raw uncompressed data
99- - [`Zlib] - RFC 1950 zlib compression *)
3535+ - [`None] - Raw uncompressed data. No [o=] key is sent.
3636+ - [`Zlib] - RFC 1950 zlib/DEFLATE compression. Data is compressed
3737+ before base64 encoding and decompressed by the terminal. *)
10381139val to_char : t -> char option
1212-(** Convert to protocol character. Returns [None] for no compression,
1313- [Some 'z'] for zlib. *)
4040+(** Convert to protocol character.
4141+4242+ Returns [None] for [`None] (no key sent), or [Some 'z'] for [`Zlib].
4343+ When [Some c] is returned, [o=c] is added to the control data. *)
+40-4
lib/kgp_cursor.mli
···11(** Cursor Movement Behavior
2233- Controls cursor position after displaying an image. *)
33+ Controls cursor position after displaying an image.
44+55+ {2 Protocol Details}
66+77+ Cursor movement is specified via the [C] key in the control data:
88+ - [C=0] or no [C] key: move cursor after display (default)
99+ - [C=1]: keep cursor in place (static)
1010+1111+ This key was added in Kitty 0.20.0.
1212+1313+ {2 Default Behavior}
1414+1515+ By default ([{`Move}]), after displaying an image the cursor advances:
1616+ - Right by the number of columns the image occupies
1717+ - Down by the number of rows the image occupies
1818+1919+ This matches how the cursor moves after printing text, allowing images
2020+ to flow naturally with text content.
2121+2222+ {2 Static Cursor}
2323+2424+ With [{`Static}], the cursor remains at its original position. This is
2525+ useful when:
2626+ - Overlaying images on existing content
2727+ - Positioning multiple images relative to the same starting point
2828+ - Implementing custom cursor management
2929+3030+ {2 Relative Placements}
3131+3232+ Note: When using relative placements (positioning images relative to
3333+ other placements), the cursor never moves regardless of this setting. *)
434535type t = [ `Move | `Static ]
636(** Cursor movement behavior.
73788- - [`Move] - Advance cursor past the displayed image (default)
99- - [`Static] - Keep cursor in place *)
3838+ - [`Move] - Advance cursor past the displayed image (default).
3939+ Cursor moves right by the number of columns and down by the
4040+ number of rows occupied by the image.
4141+ - [`Static] - Keep cursor at its original position. The image
4242+ is displayed but cursor position is unchanged. *)
10431144val to_int : t -> int
1212-(** Convert to protocol integer (0 or 1). *)
4545+(** Convert to protocol integer.
4646+4747+ Returns 0 for [`Move] or 1 for [`Static].
4848+ These values are used in the [C=] control data key. *)
+75-15
lib/kgp_delete.mli
···11(** Image Deletion Target
2233- Specifies which images or placements to delete. Each deletion type has
44- two variants: one that only removes placements and one that also frees
55- the underlying image data. *)
33+ Specifies which images or placements to delete.
44+55+ {2 Protocol Details}
66+77+ Deletion is performed with action [a=d] and the [d] key specifies
88+ the deletion type. The [d] key uses single characters:
99+1010+ {v
1111+ | Char | Meaning |
1212+ |------|--------------------------------------------------------|
1313+ | a/A | All placements visible on screen |
1414+ | i/I | By image ID (with optional placement ID) |
1515+ | n/N | By image number (newest with that number) |
1616+ | c/C | At current cursor position |
1717+ | p/P | At specific cell coordinates (x, y) |
1818+ | q/Q | At specific cell with z-index (x, y, z) |
1919+ | x/X | All in specific column |
2020+ | y/Y | All in specific row |
2121+ | z/Z | All with specific z-index |
2222+ | r/R | By image ID range (min_id to max_id) |
2323+ | f/F | Animation frames only |
2424+ v}
2525+2626+ {2 Placements vs Image Data}
2727+2828+ Each deletion type has two variants:
2929+ - {b Lowercase}: Removes placements only. The image data remains in
3030+ memory and can be displayed again later.
3131+ - {b Uppercase}: Removes placements AND frees the image data. The
3232+ image cannot be displayed again without retransmitting.
3333+3434+ Example: [{`By_id (42, None)}] removes all placements of image 42 but
3535+ keeps the data. [{`By_id_and_free (42, None)}] removes placements and
3636+ frees the image data.
3737+3838+ {2 Placement IDs}
3939+4040+ When deleting by image ID or number, an optional placement ID can be
4141+ specified to delete only a specific placement. If [None], all placements
4242+ of that image are deleted.
4343+4444+ {2 Coordinate-Based Deletion}
4545+4646+ For [{`At_cell}] and [{`At_cell_z}], coordinates are 0-based cell
4747+ positions (not pixel positions). Only placements that intersect the
4848+ specified cell are deleted.
4949+5050+ {2 Virtual Placements}
5151+5252+ Virtual placements (used for Unicode placeholder mode) are only affected
5353+ by: [{`By_id}], [{`By_id_and_free}], [{`By_number}], [{`By_number_and_free}],
5454+ [{`By_id_range}], and [{`By_id_range_and_free}]. Other deletion commands
5555+ do not affect virtual placements. *)
656757type t =
858 [ `All_visible
···2979 | `Frames_and_free ]
3080(** Deletion target specification.
31813232- - [`All_visible] - All visible placements
3333- - [`By_id (id, placement_id)] - By image ID and optional placement ID
3434- - [`By_number (n, placement_id)] - By image number and optional placement ID
3535- - [`At_cursor] - Placement at cursor position
3636- - [`At_cell (x, y)] - Placement at cell coordinates
3737- - [`At_cell_z (x, y, z)] - Placement at cell with specific z-index
3838- - [`By_column c] - All placements in column c
3939- - [`By_row r] - All placements in row r
8282+ {b Screen-based:}
8383+ - [`All_visible] - All placements currently visible on screen
8484+ - [`At_cursor] - Placements at current cursor position
8585+ - [`At_cell (x, y)] - Placements intersecting cell at column x, row y
8686+ - [`At_cell_z (x, y, z)] - Like [`At_cell] but only with z-index z
8787+ - [`By_column x] - All placements intersecting column x
8888+ - [`By_row y] - All placements intersecting row y
4089 - [`By_z_index z] - All placements with z-index z
4141- - [`By_id_range (min, max)] - All images with IDs in range
4242- - [`Frames] - Animation frames only
43904444- The [_and_free] variants also release the image data from memory. *)
9191+ {b ID-based:}
9292+ - [`By_id (id, placement_id)] - By image ID. If [placement_id] is
9393+ [Some p], only that specific placement; if [None], all placements.
9494+ - [`By_number (n, placement_id)] - By image number (newest image
9595+ with that number). Placement ID works as above.
9696+ - [`By_id_range (min, max)] - All images with IDs in range [min..max]
9797+9898+ {b Animation:}
9999+ - [`Frames] - Animation frames only (not the base image)
100100+101101+ All variants have an [_and_free] version that also releases image data. *)
4510246103val to_char : t -> char
4747-(** Convert to protocol character for the delete command. *)
104104+(** Convert to protocol character for the delete command.
105105+106106+ Returns the character used in the [d=] control data key. Lowercase
107107+ for placement-only deletion, uppercase for deletion with data free. *)
+37-5
lib/kgp_format.mli
···11(** Image Data Format
2233- Specifies the pixel format of image data being transmitted. *)
33+ Specifies the pixel format of image data being transmitted to the terminal.
44+55+ {2 Protocol Details}
66+77+ The format is specified via the [f] key in the control data:
88+ - [f=24] for RGB (3 bytes per pixel)
99+ - [f=32] for RGBA (4 bytes per pixel, default)
1010+ - [f=100] for PNG
1111+1212+ {2 Raw Pixel Formats}
1313+1414+ For [{`Rgb24}] and [{`Rgba32}], the data consists of raw pixel values in
1515+ row-major order (left-to-right, top-to-bottom). The image dimensions must
1616+ be specified via the [width] and [height] parameters.
1717+1818+ - [{`Rgb24}]: 3 bytes per pixel in sRGB color space (red, green, blue)
1919+ - [{`Rgba32}]: 4 bytes per pixel (red, green, blue, alpha)
2020+2121+ {2 PNG Format}
2222+2323+ For [{`Png}], the data is a complete PNG image. The terminal extracts
2424+ dimensions from PNG metadata, so [width] and [height] are optional.
2525+2626+ When using both PNG format and zlib compression, you must also specify
2727+ the [size] parameter with the uncompressed PNG data size. *)
428529type t = [ `Rgba32 | `Rgb24 | `Png ]
630(** Image data formats.
73188- - [`Rgba32] - 32-bit RGBA (4 bytes per pixel)
99- - [`Rgb24] - 24-bit RGB (3 bytes per pixel)
1010- - [`Png] - PNG encoded data *)
3232+ - [`Rgba32] - 32-bit RGBA (4 bytes per pixel). Default format.
3333+ Pixels are ordered red, green, blue, alpha. Alpha of 255 is fully
3434+ opaque, 0 is fully transparent.
3535+ - [`Rgb24] - 24-bit RGB (3 bytes per pixel). No alpha channel;
3636+ pixels are fully opaque. More compact than RGBA for opaque images.
3737+ - [`Png] - PNG encoded data. The terminal decodes the PNG internally.
3838+ Supports all PNG color types and bit depths. Most convenient format
3939+ as dimensions are embedded in the data. *)
11401241val to_int : t -> int
1313-(** Convert to protocol integer value (32, 24, or 100). *)
4242+(** Convert to protocol integer value.
4343+4444+ Returns 24 for [`Rgb24], 32 for [`Rgba32], or 100 for [`Png].
4545+ These values are used in the [f=] control data key. *)
+93-11
lib/kgp_frame.mli
···11-(** Kitty Graphics Protocol Frame
11+(** Animation Frame Configuration
22+33+ Configuration for adding or editing animation frames. Frames can be
44+ full images or partial updates (rectangles), with options for timing
55+ and composition.
66+77+ {2 Protocol Overview}
2833- Animation frame configuration. *)
99+ Animations are created by:
1010+ 1. Transmitting a base image (becomes frame 1)
1111+ 2. Adding frames using the frame action ([a=f])
1212+ 3. Controlling playback with animation commands
1313+1414+ Frame numbers are 1-based:
1515+ - Frame 1: The original/base image
1616+ - Frame 2+: Added animation frames
1717+1818+ {2 Frame Positioning}
1919+2020+ For partial frame updates, [x] and [y] specify where the new pixel
2121+ data is placed within the frame canvas:
2222+ - [x]: Left edge position in pixels (default 0)
2323+ - [y]: Top edge position in pixels (default 0)
2424+2525+ The frame data dimensions come from the [width] and [height] parameters
2626+ of the frame command.
2727+2828+ {2 Frame Canvas}
2929+3030+ Each frame needs a background canvas to composite onto. Options:
3131+3232+ {b Solid color background} ([background_color]):
3333+ Use a 32-bit RGBA color. Format: [0xRRGGBBAA] where AA is alpha.
3434+ Default is 0 (transparent black).
3535+3636+ {b Copy from existing frame} ([base_frame]):
3737+ Use another frame as the starting canvas. Specified as 1-based frame
3838+ number. The base frame's pixels are copied, then new data is composited.
3939+4040+ {2 Editing Existing Frames}
4141+4242+ Instead of creating a new frame, you can edit an existing one:
4343+ - Set [edit_frame] to the 1-based frame number
4444+ - The frame itself becomes the canvas
4545+ - New data is composited onto it
4646+4747+ {2 Frame Timing}
4848+4949+ The [gap_ms] parameter controls the delay before transitioning to
5050+ the next frame:
5151+ - Positive value: Delay in milliseconds
5252+ - Zero: Ignored (keeps existing gap)
5353+ - Negative value: "Gapless" frame - not displayed, used as a base
5454+ for other frames
5555+5656+ Default gap for new frames is 40ms. The root frame (frame 1) has
5757+ a default gap of 0ms.
5858+5959+ {2 Composition Mode}
6060+6161+ The [composition] parameter controls how new pixel data is blended
6262+ onto the canvas. *)
463564type t
66-(** Animation frame configuration. *)
6565+(** Animation frame configuration. Opaque type; use {!make} to construct. *)
766867val make :
968 ?x:int ->
···1776 t
1877(** Create a frame specification.
19782020- @param x Left edge where frame data is placed (pixels)
2121- @param y Top edge where frame data is placed (pixels)
2222- @param base_frame 1-based frame number to use as background canvas
2323- @param edit_frame 1-based frame number to edit (0 = new frame)
2424- @param gap_ms Delay before next frame in milliseconds
2525- @param composition How to blend pixels onto the canvas
2626- @param background_color 32-bit RGBA background when no base frame *)
7979+ @param x Left edge where frame data is placed in pixels (default 0).
8080+ Protocol key: [x].
8181+ @param y Top edge where frame data is placed in pixels (default 0).
8282+ Protocol key: [y].
8383+ @param base_frame 1-based frame number to use as background canvas.
8484+ Frame 1 is the root image. Protocol key: [c].
8585+ @param edit_frame 1-based frame number to edit instead of creating new.
8686+ If 0 or unset, a new frame is created. Protocol key: [r].
8787+ @param gap_ms Delay before next frame in milliseconds. Negative values
8888+ create gapless frames. Protocol key: [z].
8989+ @param composition How to blend new pixels onto the canvas.
9090+ Default is alpha blending. Protocol key: [X].
9191+ @param background_color 32-bit RGBA background color when not using
9292+ a base frame. Format: [0xRRGGBBAA]. Protocol key: [Y]. *)
27932894val empty : t
2929-(** Empty frame spec with defaults. *)
9595+(** Empty frame spec with all defaults.
9696+9797+ Creates a new frame with transparent black background, composited
9898+ at position (0, 0) with default timing (40ms gap). *)
309931100(** {1 Field Accessors} *)
3210133102val x : t -> int option
103103+(** Left edge position for frame data in pixels. *)
104104+34105val y : t -> int option
106106+(** Top edge position for frame data in pixels. *)
107107+35108val base_frame : t -> int option
109109+(** 1-based frame number to use as background canvas. *)
110110+36111val edit_frame : t -> int option
112112+(** 1-based frame number being edited (0 or None = new frame). *)
113113+37114val gap_ms : t -> int option
115115+(** Delay before next frame in milliseconds. *)
116116+38117val composition : t -> Kgp_composition.t option
118118+(** Pixel composition mode. *)
119119+39120val background_color : t -> int32 option
121121+(** 32-bit RGBA background color. *)
+114-16
lib/kgp_placement.mli
···11-(** Kitty Graphics Protocol Placement
11+(** Image Placement Configuration
22+33+ Configuration for where and how to display images. Placements control
44+ cropping, scaling, positioning, and layering of images.
55+66+ {2 Protocol Overview}
77+88+ When displaying an image, the protocol allows specifying:
99+ - Which part of the source image to display (source rectangle)
1010+ - Where to display it (cell position and pixel offsets)
1111+ - How large to display it (scaling to cell dimensions)
1212+ - How it layers with other content (z-index)
1313+ - Whether it can be referenced via Unicode placeholders
1414+1515+ {2 Source Rectangle}
1616+1717+ The source rectangle specifies which portion of the image to display:
1818+ - [source_x], [source_y]: Top-left corner in pixels (default: 0, 0)
1919+ - [source_width], [source_height]: Size in pixels (default: full image)
2020+2121+ The displayed area is the intersection of this rectangle with the
2222+ actual image bounds. This allows cropping images without modifying
2323+ the original data.
2424+2525+ {2 Cell-Based Sizing}
2626+2727+ Images are sized in terminal cells:
2828+ - [columns]: Number of columns to span (width in cells)
2929+ - [rows]: Number of rows to span (height in cells)
3030+3131+ If both are specified, the source rectangle is scaled to fit.
3232+ If only one is specified, the other is computed to maintain aspect ratio.
3333+ If neither is specified, the image is displayed at natural size.
23433- Configuration for where and how to display images. *)
3535+ {2 Pixel Offsets}
3636+3737+ Fine-grained positioning within the starting cell:
3838+ - [cell_x_offset]: Horizontal offset in pixels from cell left edge
3939+ - [cell_y_offset]: Vertical offset in pixels from cell top edge
4040+4141+ These offsets must be smaller than the cell dimensions.
4242+4343+ {2 Z-Index Layering}
4444+4545+ The [z_index] controls vertical stacking:
4646+ - Positive values: drawn above text
4747+ - Zero: drawn at text level
4848+ - Negative values: drawn below text
4949+ - Values < INT32_MIN/2 (-1,073,741,824): drawn under cells with
5050+ non-default background colors
5151+5252+ Overlapping images with the same z-index are ordered by image ID
5353+ (lower ID draws first/underneath).
5454+5555+ {2 Placement IDs}
5656+5757+ Each placement can have a unique [placement_id] (1-4294967295). This
5858+ enables:
5959+ - Updating a specific placement without affecting others
6060+ - Deleting specific placements
6161+ - Moving placements by resending with same image_id + placement_id
6262+6363+ If [placement_id] is 0 or unspecified, each display creates an
6464+ independent placement. *)
465566type t
66-(** Placement configuration. *)
6767+(** Placement configuration. Opaque type; use {!make} to construct. *)
768869val make :
970 ?source_x:int ->
···2283 t
2384(** Create a placement configuration.
24852525- @param source_x Left edge of source rectangle in pixels (default 0)
2626- @param source_y Top edge of source rectangle in pixels (default 0)
2727- @param source_width Width of source rectangle (default: full width)
2828- @param source_height Height of source rectangle (default: full height)
2929- @param cell_x_offset X offset within the first cell in pixels
3030- @param cell_y_offset Y offset within the first cell in pixels
3131- @param columns Number of columns to display over (scales image)
3232- @param rows Number of rows to display over (scales image)
3333- @param z_index Stacking order (negative = under text)
3434- @param placement_id Unique ID for this placement
3535- @param cursor Cursor movement policy after display
3636- @param unicode_placeholder Create virtual placement for Unicode mode *)
8686+ @param source_x Left edge of source rectangle in pixels (default 0).
8787+ Protocol key: [x].
8888+ @param source_y Top edge of source rectangle in pixels (default 0).
8989+ Protocol key: [y].
9090+ @param source_width Width of source rectangle in pixels.
9191+ Default is the full image width. Protocol key: [w].
9292+ @param source_height Height of source rectangle in pixels.
9393+ Default is the full image height. Protocol key: [h].
9494+ @param cell_x_offset X offset within the first cell in pixels.
9595+ Must be smaller than cell width. Protocol key: [X].
9696+ @param cell_y_offset Y offset within the first cell in pixels.
9797+ Must be smaller than cell height. Protocol key: [Y].
9898+ @param columns Number of columns to display over. Image is scaled
9999+ to fit. Protocol key: [c].
100100+ @param rows Number of rows to display over. Image is scaled to fit.
101101+ Protocol key: [r].
102102+ @param z_index Stacking order. Positive = above text, negative = below.
103103+ Protocol key: [z].
104104+ @param placement_id Unique ID (1-4294967295) for this placement.
105105+ Allows updating/deleting specific placements. Protocol key: [p].
106106+ @param cursor Cursor movement policy after display.
107107+ @param unicode_placeholder If true, creates a virtual (invisible)
108108+ placement for Unicode placeholder mode. Protocol key: [U=1]. *)
3710938110val empty : t
3939-(** Empty placement with all defaults. *)
111111+(** Empty placement with all defaults.
112112+113113+ Equivalent to [make ()]. The image displays at natural size at the
114114+ current cursor position with default z-index (0). *)
4011541116(** {1 Field Accessors} *)
4211743118val source_x : t -> int option
119119+(** Left edge of source rectangle in pixels. *)
120120+44121val source_y : t -> int option
122122+(** Top edge of source rectangle in pixels. *)
123123+45124val source_width : t -> int option
125125+(** Width of source rectangle in pixels. *)
126126+46127val source_height : t -> int option
128128+(** Height of source rectangle in pixels. *)
129129+47130val cell_x_offset : t -> int option
131131+(** X offset within the first cell in pixels. *)
132132+48133val cell_y_offset : t -> int option
134134+(** Y offset within the first cell in pixels. *)
135135+49136val columns : t -> int option
137137+(** Number of columns to display over. *)
138138+50139val rows : t -> int option
140140+(** Number of rows to display over. *)
141141+51142val z_index : t -> int option
143143+(** Stacking order (z-index). *)
144144+52145val placement_id : t -> int option
146146+(** Unique placement identifier. *)
147147+53148val cursor : t -> Kgp_cursor.t option
149149+(** Cursor movement policy. *)
150150+54151val unicode_placeholder : t -> bool
152152+(** Whether this is a virtual placement for Unicode mode. *)
+40-5
lib/kgp_quiet.mli
···11(** Response Suppression Level
2233- Controls which terminal responses are sent back to the application. *)
33+ Controls which terminal responses are sent back to the application.
44+55+ {2 Protocol Details}
66+77+ The quiet level is specified via the [q] key in the control data:
88+ - [q=0] or no [q] key: send all responses (default)
99+ - [q=1]: suppress OK responses, only send errors
1010+ - [q=2]: suppress all responses
1111+1212+ {2 Terminal Responses}
1313+1414+ Normally, when an [image_id] is specified, the terminal responds:
1515+ - On success: [ESC _Gi=ID;OK ESC]
1616+ - On failure: [ESC _Gi=ID;ECODE:message ESC]
1717+1818+ Response processing requires reading from the terminal, which can be
1919+ complex in some applications.
2020+2121+ {2 Use Cases}
2222+2323+ [{`Noisy}] (default): Use when you need to verify operations succeeded
2424+ or want to handle errors programmatically.
2525+2626+ [{`Errors_only}]: Use when you want to detect failures but don't need
2727+ confirmation of success. Reduces response traffic.
2828+2929+ [{`Silent}]: Use in fire-and-forget scenarios like shell scripts or
3030+ when the application cannot easily read terminal responses. Also useful
3131+ for high-frequency animation updates where response processing would
3232+ add latency. *)
433534type t = [ `Noisy | `Errors_only | `Silent ]
635(** Response suppression levels.
73688- - [`Noisy] - Send all responses (default)
99- - [`Errors_only] - Suppress OK responses, only send errors
1010- - [`Silent] - Suppress all responses *)
3737+ - [`Noisy] - Send all responses including OK confirmations (default).
3838+ Required for detecting success and getting assigned image IDs.
3939+ - [`Errors_only] - Suppress OK responses, only send error messages.
4040+ Useful when success is expected but errors should be caught.
4141+ - [`Silent] - Suppress all responses including errors. Useful for
4242+ shell scripts or when response handling is not possible. *)
11431244val to_int : t -> int
1313-(** Convert to protocol integer (0, 1, or 2). *)
4545+(** Convert to protocol integer.
4646+4747+ Returns 0 for [`Noisy], 1 for [`Errors_only], or 2 for [`Silent].
4848+ These values are used in the [q=] control data key. *)
+52-5
lib/kgp_transmission.mli
···11(** Data Transmission Method
2233- Specifies how image data is transmitted to the terminal. *)
33+ Specifies how image data is transmitted to the terminal.
44+55+ {2 Protocol Details}
66+77+ The transmission method is specified via the [t] key in the control data:
88+ - [t=d] for direct (inline) transmission (default)
99+ - [t=f] for regular file
1010+ - [t=t] for temporary file (deleted after reading)
1111+1212+ {2 Direct Transmission}
1313+1414+ [{`Direct}] sends data inline within the escape sequence itself. The data
1515+ is base64-encoded in the payload section. This is the simplest method and
1616+ works over any connection (including SSH).
1717+1818+ For images larger than 4096 bytes (after base64 encoding), the data is
1919+ automatically split into chunks using the [m=] key:
2020+ - [m=1] indicates more chunks follow
2121+ - [m=0] indicates the final chunk
2222+2323+ {2 File Transmission}
2424+2525+ [{`File}] tells the terminal to read data from a file path. The path is
2626+ sent base64-encoded in the payload. Additional parameters:
2727+ - [S=] specifies the number of bytes to read
2828+ - [O=] specifies the byte offset to start reading from
2929+3030+ File transmission only works when the terminal and client share a
3131+ filesystem (i.e., local terminals, not SSH).
3232+3333+ Security: The terminal will refuse to read device files, sockets, or
3434+ files in sensitive locations like [/proc], [/sys], or [/dev].
3535+3636+ {2 Temporary File Transmission}
3737+3838+ [{`Tempfile}] is like [{`File}] but the terminal deletes the file after
3939+ reading. The file must be in a recognized temporary directory:
4040+ - [/tmp]
4141+ - [/dev/shm]
4242+ - The [TMPDIR] environment variable location
4343+ - Platform-specific temp directories containing [tty-graphics-protocol] *)
444545type t = [ `Direct | `File | `Tempfile ]
646(** Transmission methods.
74788- - [`Direct] - Data is sent inline in the escape sequence
99- - [`File] - Terminal reads from a file path
1010- - [`Tempfile] - Terminal reads and deletes a temporary file *)
4848+ - [`Direct] - Data is sent inline in the escape sequence (base64-encoded).
4949+ Works over any connection including SSH. Automatic chunking for large
5050+ images.
5151+ - [`File] - Terminal reads from a file path sent in the payload.
5252+ Only works when terminal and client share a filesystem.
5353+ - [`Tempfile] - Like [`File] but terminal deletes the file after reading.
5454+ File must be in a recognized temporary directory. *)
11551256val to_char : t -> char
1313-(** Convert to protocol character ('d', 'f', or 't'). *)
5757+(** Convert to protocol character.
5858+5959+ Returns ['d'] for [`Direct], ['f'] for [`File], or ['t'] for [`Tempfile].
6060+ These values are used in the [t=] control data key. *)