Kitty Graphics Protocol in OCaml
terminal graphics ocaml

restructure

+9 -18
lib/kgp.ml
···
(* Kitty Terminal Graphics Protocol - Main Module *)
-
(* Re-export polymorphic variant types *)
-
type format = Kgp_types.format
-
type transmission = Kgp_types.transmission
-
type compression = Kgp_types.compression
-
type quiet = Kgp_types.quiet
-
type cursor = Kgp_types.cursor
-
type composition = Kgp_types.composition
-
type delete = Kgp_types.delete
-
type animation_state = Kgp_types.animation_state
-
-
(* Type conversion modules *)
-
module Format = Kgp_types.Format
-
module Transmission = Kgp_types.Transmission
-
module Compression = Kgp_types.Compression
-
module Quiet = Kgp_types.Quiet
-
module Cursor = Kgp_types.Cursor
-
module Composition = Kgp_types.Composition
-
module Delete = Kgp_types.Delete
(* Configuration modules *)
module Placement = Kgp_placement
···
(* Kitty Terminal Graphics Protocol - Main Module *)
+
(* Type modules *)
+
module Format = Kgp_format
+
module Transmission = Kgp_transmission
+
module Compression = Kgp_compression
+
module Quiet = Kgp_quiet
+
module Cursor = Kgp_cursor
+
module Composition = Kgp_composition
+
module Delete = Kgp_delete
+
module Animation_state = Kgp_animation_state
(* Configuration modules *)
module Placement = Kgp_placement
+8 -41
lib/kgp.mli
···
See {{:https://sw.kovidgoyal.net/kitty/graphics-protocol/} Kitty Graphics Protocol}
for the full specification. *)
-
(** {1 Polymorphic Variant Types} *)
-
-
type format = Kgp_types.format
-
(** Image data formats. [`Rgba32] is 32-bit RGBA (4 bytes per pixel),
-
[`Rgb24] is 24-bit RGB (3 bytes per pixel), [`Png] is PNG encoded data. *)
-
-
type transmission = Kgp_types.transmission
-
(** Transmission methods. [`Direct] sends data inline, [`File] reads from a path,
-
[`Tempfile] reads from a temp file that the terminal deletes after reading. *)
-
-
type compression = Kgp_types.compression
-
(** Compression options. [`None] for raw data, [`Zlib] for RFC 1950 compression. *)
-
-
type quiet = Kgp_types.quiet
-
(** Response suppression. [`Noisy] sends all responses (default),
-
[`Errors_only] suppresses OK responses, [`Silent] suppresses all. *)
-
-
type cursor = Kgp_types.cursor
-
(** Cursor movement after displaying. [`Move] advances cursor (default),
-
[`Static] keeps cursor in place. *)
-
-
type composition = Kgp_types.composition
-
(** Composition modes. [`Alpha_blend] for full blending (default),
-
[`Overwrite] for simple pixel replacement. *)
-
-
type delete = Kgp_types.delete
-
(** Delete target specification. Each variant has two forms: one that only
-
removes placements (e.g., [`All_visible]) and one that also frees the
-
image data (e.g., [`All_visible_and_free]). *)
-
-
type animation_state = Kgp_types.animation_state
-
(** Animation playback state. [`Stop] halts animation, [`Loading] runs but
-
waits for new frames at end, [`Run] runs normally and loops. *)
-
(** {1 Type Modules} *)
-
module Format = Kgp_types.Format
-
module Transmission = Kgp_types.Transmission
-
module Compression = Kgp_types.Compression
-
module Quiet = Kgp_types.Quiet
-
module Cursor = Kgp_types.Cursor
-
module Composition = Kgp_types.Composition
-
module Delete = Kgp_types.Delete
(** {1 Configuration Modules} *)
···
See {{:https://sw.kovidgoyal.net/kitty/graphics-protocol/} Kitty Graphics Protocol}
for the full specification. *)
(** {1 Type Modules} *)
+
module Format = Kgp_format
+
module Transmission = Kgp_transmission
+
module Compression = Kgp_compression
+
module Quiet = Kgp_quiet
+
module Cursor = Kgp_cursor
+
module Composition = Kgp_composition
+
module Delete = Kgp_delete
+
module Animation_state = Kgp_animation_state
(** {1 Configuration Modules} *)
+1 -5
lib/kgp_animation.ml
···
-
(* Kitty Graphics Protocol Animation - Implementation *)
-
-
type state = Kgp_types.animation_state
-
type t =
-
[ `Set_state of state * int option
| `Set_gap of int * int
| `Set_current of int ]
···
type t =
+
[ `Set_state of Kgp_animation_state.t * int option
| `Set_gap of int * int
| `Set_current of int ]
+2 -5
lib/kgp_animation.mli
···
Animation control operations. *)
-
type state = Kgp_types.animation_state
-
(** Animation playback state. *)
-
type t =
-
[ `Set_state of state * int option
| `Set_gap of int * int
| `Set_current of int ]
(** Animation control operations. *)
-
val set_state : ?loops:int -> state -> t
(** Set animation state.
@param loops Number of loops: 0 = ignored, 1 = infinite, n = n-1 loops *)
···
Animation control operations. *)
type t =
+
[ `Set_state of Kgp_animation_state.t * int option
| `Set_gap of int * int
| `Set_current of int ]
(** Animation control operations. *)
+
val set_state : ?loops:int -> Kgp_animation_state.t -> t
(** Set animation state.
@param loops Number of loops: 0 = ignored, 1 = infinite, n = n-1 loops *)
+6
lib/kgp_animation_state.ml
···
···
+
type t = [ `Stop | `Loading | `Run ]
+
+
let to_int : t -> int = function
+
| `Stop -> 1
+
| `Loading -> 2
+
| `Run -> 3
+13
lib/kgp_animation_state.mli
···
···
+
(** Animation Playback State
+
+
Controls the playback state of animated images. *)
+
+
type t = [ `Stop | `Loading | `Run ]
+
(** Animation playback states.
+
+
- [`Stop] - Halt animation playback
+
- [`Loading] - Run animation but wait for new frames at end
+
- [`Run] - Run animation normally and loop *)
+
+
val to_int : t -> int
+
(** Convert to protocol integer (1, 2, or 3). *)
+15 -41
lib/kgp_command.ml
···
-
(* Kitty Graphics Protocol Command - Implementation *)
-
type action =
[ `Transmit
| `Transmit_and_display
···
type t = {
action : action;
-
format : Kgp_types.format option;
-
transmission : Kgp_types.transmission option;
-
compression : Kgp_types.compression option;
width : int option;
height : int option;
size : int option;
offset : int option;
-
quiet : Kgp_types.quiet option;
image_id : int option;
image_number : int option;
placement : Kgp_placement.t option;
-
delete : Kgp_types.delete option;
frame : Kgp_frame.t option;
animation : Kgp_animation.t option;
compose : Kgp_compose.t option;
···
| `Animate -> 'a'
| `Compose -> 'c'
-
let delete_char : Kgp_types.delete -> char = function
-
| `All_visible -> 'a'
-
| `All_visible_and_free -> 'A'
-
| `By_id _ -> 'i'
-
| `By_id_and_free _ -> 'I'
-
| `By_number _ -> 'n'
-
| `By_number_and_free _ -> 'N'
-
| `At_cursor -> 'c'
-
| `At_cursor_and_free -> 'C'
-
| `At_cell _ -> 'p'
-
| `At_cell_and_free _ -> 'P'
-
| `At_cell_z _ -> 'q'
-
| `At_cell_z_and_free _ -> 'Q'
-
| `By_column _ -> 'x'
-
| `By_column_and_free _ -> 'X'
-
| `By_row _ -> 'y'
-
| `By_row_and_free _ -> 'Y'
-
| `By_z_index _ -> 'z'
-
| `By_z_index_and_free _ -> 'Z'
-
| `By_id_range _ -> 'r'
-
| `By_id_range_and_free _ -> 'R'
-
| `Frames -> 'f'
-
| `Frames_and_free -> 'F'
-
let write_placement w (p : Kgp_placement.t) =
kv_int_opt w 'x' (Kgp_placement.source_x p);
kv_int_opt w 'y' (Kgp_placement.source_y p);
···
kv_int_opt w 'p' (Kgp_placement.placement_id p);
Kgp_placement.cursor p
|> Option.iter (fun c ->
-
kv_int_if w 'C' ~default:0 (Some (Kgp_types.Cursor.to_int c)));
if Kgp_placement.unicode_placeholder p then kv_int w 'U' 1
-
let write_delete w (d : Kgp_types.delete) =
-
kv_char w 'd' (delete_char d);
match d with
| `By_id (id, pid) | `By_id_and_free (id, pid) ->
kv_int w 'i' id;
···
kv_int_opt w 'z' (Kgp_frame.gap_ms f);
Kgp_frame.composition f
|> Option.iter (fun c ->
-
kv_int_if w 'X' ~default:0 (Some (Kgp_types.Composition.to_int c)));
kv_int32_opt w 'Y' (Kgp_frame.background_color f)
let write_animation w : Kgp_animation.t -> unit = function
| `Set_state (state, loops) ->
-
let s = match state with `Stop -> 1 | `Loading -> 2 | `Run -> 3 in
kv_int w 's' s;
kv_int_opt w 'v' loops
| `Set_gap (frame, gap_ms) ->
···
kv_int_opt w 'Y' (Kgp_compose.source_y c);
Kgp_compose.composition c
|> Option.iter (fun comp ->
-
kv_int_if w 'C' ~default:0 (Some (Kgp_types.Composition.to_int comp)))
let write_control_data buf cmd =
let w = kv_writer buf in
···
(* Quiet - only if non-default *)
cmd.quiet
|> Option.iter (fun q ->
-
kv_int_if w 'q' ~default:0 (Some (Kgp_types.Quiet.to_int q)));
(* Format *)
cmd.format
-
|> Option.iter (fun f -> kv_int w 'f' (Kgp_types.Format.to_int f));
(* Transmission - only for transmit/frame actions, always include t=d for compatibility *)
(match cmd.action with
| `Transmit | `Transmit_and_display | `Frame -> (
match cmd.transmission with
-
| Some t -> kv_char w 't' (Kgp_types.Transmission.to_char t)
| None -> kv_char w 't' 'd')
| _ -> ());
(* Compression *)
cmd.compression
|> Option.iter (fun c ->
-
Kgp_types.Compression.to_char c |> Option.iter (kv_char w 'o'));
(* Dimensions *)
kv_int_opt w 's' cmd.width;
kv_int_opt w 'v' cmd.height;
···
type action =
[ `Transmit
| `Transmit_and_display
···
type t = {
action : action;
+
format : Kgp_format.t option;
+
transmission : Kgp_transmission.t option;
+
compression : Kgp_compression.t option;
width : int option;
height : int option;
size : int option;
offset : int option;
+
quiet : Kgp_quiet.t option;
image_id : int option;
image_number : int option;
placement : Kgp_placement.t option;
+
delete : Kgp_delete.t option;
frame : Kgp_frame.t option;
animation : Kgp_animation.t option;
compose : Kgp_compose.t option;
···
| `Animate -> 'a'
| `Compose -> 'c'
let write_placement w (p : Kgp_placement.t) =
kv_int_opt w 'x' (Kgp_placement.source_x p);
kv_int_opt w 'y' (Kgp_placement.source_y p);
···
kv_int_opt w 'p' (Kgp_placement.placement_id p);
Kgp_placement.cursor p
|> Option.iter (fun c ->
+
kv_int_if w 'C' ~default:0 (Some (Kgp_cursor.to_int c)));
if Kgp_placement.unicode_placeholder p then kv_int w 'U' 1
+
let write_delete w (d : Kgp_delete.t) =
+
kv_char w 'd' (Kgp_delete.to_char d);
match d with
| `By_id (id, pid) | `By_id_and_free (id, pid) ->
kv_int w 'i' id;
···
kv_int_opt w 'z' (Kgp_frame.gap_ms f);
Kgp_frame.composition f
|> Option.iter (fun c ->
+
kv_int_if w 'X' ~default:0 (Some (Kgp_composition.to_int c)));
kv_int32_opt w 'Y' (Kgp_frame.background_color f)
let write_animation w : Kgp_animation.t -> unit = function
| `Set_state (state, loops) ->
+
let s = Kgp_animation_state.to_int state in
kv_int w 's' s;
kv_int_opt w 'v' loops
| `Set_gap (frame, gap_ms) ->
···
kv_int_opt w 'Y' (Kgp_compose.source_y c);
Kgp_compose.composition c
|> Option.iter (fun comp ->
+
kv_int_if w 'C' ~default:0 (Some (Kgp_composition.to_int comp)))
let write_control_data buf cmd =
let w = kv_writer buf in
···
(* Quiet - only if non-default *)
cmd.quiet
|> Option.iter (fun q ->
+
kv_int_if w 'q' ~default:0 (Some (Kgp_quiet.to_int q)));
(* Format *)
cmd.format
+
|> Option.iter (fun f -> kv_int w 'f' (Kgp_format.to_int f));
(* Transmission - only for transmit/frame actions, always include t=d for compatibility *)
(match cmd.action with
| `Transmit | `Transmit_and_display | `Frame -> (
match cmd.transmission with
+
| Some t -> kv_char w 't' (Kgp_transmission.to_char t)
| None -> kv_char w 't' 'd')
| _ -> ());
(* Compression *)
cmd.compression
|> Option.iter (fun c ->
+
Kgp_compression.to_char c |> Option.iter (kv_char w 'o'));
(* Dimensions *)
kv_int_opt w 's' cmd.width;
kv_int_opt w 'v' cmd.height;
+19 -19
lib/kgp_command.mli
···
val transmit :
?image_id:int ->
?image_number:int ->
-
?format:Kgp_types.format ->
-
?transmission:Kgp_types.transmission ->
-
?compression:Kgp_types.compression ->
?width:int ->
?height:int ->
?size:int ->
?offset:int ->
-
?quiet:Kgp_types.quiet ->
unit ->
t
(** Transmit image data without displaying. *)
···
val transmit_and_display :
?image_id:int ->
?image_number:int ->
-
?format:Kgp_types.format ->
-
?transmission:Kgp_types.transmission ->
-
?compression:Kgp_types.compression ->
?width:int ->
?height:int ->
?size:int ->
?offset:int ->
-
?quiet:Kgp_types.quiet ->
?placement:Kgp_placement.t ->
unit ->
t
(** Transmit image data and display it immediately. *)
val query :
-
?format:Kgp_types.format ->
-
?transmission:Kgp_types.transmission ->
?width:int ->
?height:int ->
-
?quiet:Kgp_types.quiet ->
unit ->
t
(** Query terminal support without storing the image. *)
···
?image_id:int ->
?image_number:int ->
?placement:Kgp_placement.t ->
-
?quiet:Kgp_types.quiet ->
unit ->
t
(** Display a previously transmitted image. *)
(** {1 Deletion} *)
-
val delete : ?quiet:Kgp_types.quiet -> Kgp_types.delete -> t
(** Delete images or placements. *)
(** {1 Animation} *)
···
val frame :
?image_id:int ->
?image_number:int ->
-
?format:Kgp_types.format ->
-
?transmission:Kgp_types.transmission ->
-
?compression:Kgp_types.compression ->
?width:int ->
?height:int ->
-
?quiet:Kgp_types.quiet ->
frame:Kgp_frame.t ->
unit ->
t
···
val animate :
?image_id:int ->
?image_number:int ->
-
?quiet:Kgp_types.quiet ->
Kgp_animation.t ->
t
(** Control animation playback. *)
···
val compose :
?image_id:int ->
?image_number:int ->
-
?quiet:Kgp_types.quiet ->
Kgp_compose.t ->
t
(** Compose animation frames. *)
···
val transmit :
?image_id:int ->
?image_number:int ->
+
?format:Kgp_format.t ->
+
?transmission:Kgp_transmission.t ->
+
?compression:Kgp_compression.t ->
?width:int ->
?height:int ->
?size:int ->
?offset:int ->
+
?quiet:Kgp_quiet.t ->
unit ->
t
(** Transmit image data without displaying. *)
···
val transmit_and_display :
?image_id:int ->
?image_number:int ->
+
?format:Kgp_format.t ->
+
?transmission:Kgp_transmission.t ->
+
?compression:Kgp_compression.t ->
?width:int ->
?height:int ->
?size:int ->
?offset:int ->
+
?quiet:Kgp_quiet.t ->
?placement:Kgp_placement.t ->
unit ->
t
(** Transmit image data and display it immediately. *)
val query :
+
?format:Kgp_format.t ->
+
?transmission:Kgp_transmission.t ->
?width:int ->
?height:int ->
+
?quiet:Kgp_quiet.t ->
unit ->
t
(** Query terminal support without storing the image. *)
···
?image_id:int ->
?image_number:int ->
?placement:Kgp_placement.t ->
+
?quiet:Kgp_quiet.t ->
unit ->
t
(** Display a previously transmitted image. *)
(** {1 Deletion} *)
+
val delete : ?quiet:Kgp_quiet.t -> Kgp_delete.t -> t
(** Delete images or placements. *)
(** {1 Animation} *)
···
val frame :
?image_id:int ->
?image_number:int ->
+
?format:Kgp_format.t ->
+
?transmission:Kgp_transmission.t ->
+
?compression:Kgp_compression.t ->
?width:int ->
?height:int ->
+
?quiet:Kgp_quiet.t ->
frame:Kgp_frame.t ->
unit ->
t
···
val animate :
?image_id:int ->
?image_number:int ->
+
?quiet:Kgp_quiet.t ->
Kgp_animation.t ->
t
(** Control animation playback. *)
···
val compose :
?image_id:int ->
?image_number:int ->
+
?quiet:Kgp_quiet.t ->
Kgp_compose.t ->
t
(** Compose animation frames. *)
+1 -3
lib/kgp_compose.ml
···
-
(* Kitty Graphics Protocol Compose - Implementation *)
-
type t = {
source_frame : int;
dest_frame : int;
···
source_y : int option;
dest_x : int option;
dest_y : int option;
-
composition : Kgp_types.composition option;
}
let make ~source_frame ~dest_frame ?width ?height ?source_x ?source_y ?dest_x
···
type t = {
source_frame : int;
dest_frame : int;
···
source_y : int option;
dest_x : int option;
dest_y : int option;
+
composition : Kgp_composition.t option;
}
let make ~source_frame ~dest_frame ?width ?height ?source_x ?source_y ?dest_x
+2 -2
lib/kgp_compose.mli
···
?source_y:int ->
?dest_x:int ->
?dest_y:int ->
-
?composition:Kgp_types.composition ->
unit ->
t
(** Compose a rectangle from one frame onto another. *)
···
val source_y : t -> int option
val dest_x : t -> int option
val dest_y : t -> int option
-
val composition : t -> Kgp_types.composition option
···
?source_y:int ->
?dest_x:int ->
?dest_y:int ->
+
?composition:Kgp_composition.t ->
unit ->
t
(** Compose a rectangle from one frame onto another. *)
···
val source_y : t -> int option
val dest_x : t -> int option
val dest_y : t -> int option
+
val composition : t -> Kgp_composition.t option
+5
lib/kgp_composition.ml
···
···
+
type t = [ `Alpha_blend | `Overwrite ]
+
+
let to_int : t -> int = function
+
| `Alpha_blend -> 0
+
| `Overwrite -> 1
+12
lib/kgp_composition.mli
···
···
+
(** Pixel Composition Mode
+
+
Controls how pixels are blended when compositing images or animation frames. *)
+
+
type t = [ `Alpha_blend | `Overwrite ]
+
(** Composition modes.
+
+
- [`Alpha_blend] - Full alpha blending (default)
+
- [`Overwrite] - Simple pixel replacement *)
+
+
val to_int : t -> int
+
(** Convert to protocol integer (0 or 1). *)
+5
lib/kgp_compression.ml
···
···
+
type t = [ `None | `Zlib ]
+
+
let to_char : t -> char option = function
+
| `None -> None
+
| `Zlib -> Some 'z'
+13
lib/kgp_compression.mli
···
···
+
(** Data Compression
+
+
Specifies compression applied to image data before transmission. *)
+
+
type t = [ `None | `Zlib ]
+
(** Compression options.
+
+
- [`None] - Raw uncompressed data
+
- [`Zlib] - RFC 1950 zlib compression *)
+
+
val to_char : t -> char option
+
(** Convert to protocol character. Returns [None] for no compression,
+
[Some 'z'] for zlib. *)
+5
lib/kgp_cursor.ml
···
···
+
type t = [ `Move | `Static ]
+
+
let to_int : t -> int = function
+
| `Move -> 0
+
| `Static -> 1
+12
lib/kgp_cursor.mli
···
···
+
(** Cursor Movement Behavior
+
+
Controls cursor position after displaying an image. *)
+
+
type t = [ `Move | `Static ]
+
(** Cursor movement behavior.
+
+
- [`Move] - Advance cursor past the displayed image (default)
+
- [`Static] - Keep cursor in place *)
+
+
val to_int : t -> int
+
(** Convert to protocol integer (0 or 1). *)
+47
lib/kgp_delete.ml
···
···
+
type t =
+
[ `All_visible
+
| `All_visible_and_free
+
| `By_id of int * int option
+
| `By_id_and_free of int * int option
+
| `By_number of int * int option
+
| `By_number_and_free of int * int option
+
| `At_cursor
+
| `At_cursor_and_free
+
| `At_cell of int * int
+
| `At_cell_and_free of int * int
+
| `At_cell_z of int * int * int
+
| `At_cell_z_and_free of int * int * int
+
| `By_column of int
+
| `By_column_and_free of int
+
| `By_row of int
+
| `By_row_and_free of int
+
| `By_z_index of int
+
| `By_z_index_and_free of int
+
| `By_id_range of int * int
+
| `By_id_range_and_free of int * int
+
| `Frames
+
| `Frames_and_free ]
+
+
let to_char : t -> char = function
+
| `All_visible -> 'a'
+
| `All_visible_and_free -> 'A'
+
| `By_id _ -> 'i'
+
| `By_id_and_free _ -> 'I'
+
| `By_number _ -> 'n'
+
| `By_number_and_free _ -> 'N'
+
| `At_cursor -> 'c'
+
| `At_cursor_and_free -> 'C'
+
| `At_cell _ -> 'p'
+
| `At_cell_and_free _ -> 'P'
+
| `At_cell_z _ -> 'q'
+
| `At_cell_z_and_free _ -> 'Q'
+
| `By_column _ -> 'x'
+
| `By_column_and_free _ -> 'X'
+
| `By_row _ -> 'y'
+
| `By_row_and_free _ -> 'Y'
+
| `By_z_index _ -> 'z'
+
| `By_z_index_and_free _ -> 'Z'
+
| `By_id_range _ -> 'r'
+
| `By_id_range_and_free _ -> 'R'
+
| `Frames -> 'f'
+
| `Frames_and_free -> 'F'
+47
lib/kgp_delete.mli
···
···
+
(** Image Deletion Target
+
+
Specifies which images or placements to delete. Each deletion type has
+
two variants: one that only removes placements and one that also frees
+
the underlying image data. *)
+
+
type t =
+
[ `All_visible
+
| `All_visible_and_free
+
| `By_id of int * int option
+
| `By_id_and_free of int * int option
+
| `By_number of int * int option
+
| `By_number_and_free of int * int option
+
| `At_cursor
+
| `At_cursor_and_free
+
| `At_cell of int * int
+
| `At_cell_and_free of int * int
+
| `At_cell_z of int * int * int
+
| `At_cell_z_and_free of int * int * int
+
| `By_column of int
+
| `By_column_and_free of int
+
| `By_row of int
+
| `By_row_and_free of int
+
| `By_z_index of int
+
| `By_z_index_and_free of int
+
| `By_id_range of int * int
+
| `By_id_range_and_free of int * int
+
| `Frames
+
| `Frames_and_free ]
+
(** Deletion target specification.
+
+
- [`All_visible] - All visible placements
+
- [`By_id (id, placement_id)] - By image ID and optional placement ID
+
- [`By_number (n, placement_id)] - By image number and optional placement ID
+
- [`At_cursor] - Placement at cursor position
+
- [`At_cell (x, y)] - Placement at cell coordinates
+
- [`At_cell_z (x, y, z)] - Placement at cell with specific z-index
+
- [`By_column c] - All placements in column c
+
- [`By_row r] - All placements in row r
+
- [`By_z_index z] - All placements with z-index z
+
- [`By_id_range (min, max)] - All images with IDs in range
+
- [`Frames] - Animation frames only
+
+
The [_and_free] variants also release the image data from memory. *)
+
+
val to_char : t -> char
+
(** Convert to protocol character for the delete command. *)
+6
lib/kgp_format.ml
···
···
+
type t = [ `Rgba32 | `Rgb24 | `Png ]
+
+
let to_int : t -> int = function
+
| `Rgba32 -> 32
+
| `Rgb24 -> 24
+
| `Png -> 100
+13
lib/kgp_format.mli
···
···
+
(** Image Data Format
+
+
Specifies the pixel format of image data being transmitted. *)
+
+
type t = [ `Rgba32 | `Rgb24 | `Png ]
+
(** Image data formats.
+
+
- [`Rgba32] - 32-bit RGBA (4 bytes per pixel)
+
- [`Rgb24] - 24-bit RGB (3 bytes per pixel)
+
- [`Png] - PNG encoded data *)
+
+
val to_int : t -> int
+
(** Convert to protocol integer value (32, 24, or 100). *)
+1 -3
lib/kgp_frame.ml
···
-
(* Kitty Graphics Protocol Frame - Implementation *)
-
type t = {
x : int option;
y : int option;
base_frame : int option;
edit_frame : int option;
gap_ms : int option;
-
composition : Kgp_types.composition option;
background_color : int32 option;
}
···
type t = {
x : int option;
y : int option;
base_frame : int option;
edit_frame : int option;
gap_ms : int option;
+
composition : Kgp_composition.t option;
background_color : int32 option;
}
+2 -2
lib/kgp_frame.mli
···
?base_frame:int ->
?edit_frame:int ->
?gap_ms:int ->
-
?composition:Kgp_types.composition ->
?background_color:int32 ->
unit ->
t
···
val base_frame : t -> int option
val edit_frame : t -> int option
val gap_ms : t -> int option
-
val composition : t -> Kgp_types.composition option
val background_color : t -> int32 option
···
?base_frame:int ->
?edit_frame:int ->
?gap_ms:int ->
+
?composition:Kgp_composition.t ->
?background_color:int32 ->
unit ->
t
···
val base_frame : t -> int option
val edit_frame : t -> int option
val gap_ms : t -> int option
+
val composition : t -> Kgp_composition.t option
val background_color : t -> int32 option
+1 -3
lib/kgp_placement.ml
···
-
(* Kitty Graphics Protocol Placement - Implementation *)
-
type t = {
source_x : int option;
source_y : int option;
···
rows : int option;
z_index : int option;
placement_id : int option;
-
cursor : Kgp_types.cursor option;
unicode_placeholder : bool;
}
···
type t = {
source_x : int option;
source_y : int option;
···
rows : int option;
z_index : int option;
placement_id : int option;
+
cursor : Kgp_cursor.t option;
unicode_placeholder : bool;
}
+2 -2
lib/kgp_placement.mli
···
?rows:int ->
?z_index:int ->
?placement_id:int ->
-
?cursor:Kgp_types.cursor ->
?unicode_placeholder:bool ->
unit ->
t
···
val rows : t -> int option
val z_index : t -> int option
val placement_id : t -> int option
-
val cursor : t -> Kgp_types.cursor option
val unicode_placeholder : t -> bool
···
?rows:int ->
?z_index:int ->
?placement_id:int ->
+
?cursor:Kgp_cursor.t ->
?unicode_placeholder:bool ->
unit ->
t
···
val rows : t -> int option
val z_index : t -> int option
val placement_id : t -> int option
+
val cursor : t -> Kgp_cursor.t option
val unicode_placeholder : t -> bool
+6
lib/kgp_quiet.ml
···
···
+
type t = [ `Noisy | `Errors_only | `Silent ]
+
+
let to_int : t -> int = function
+
| `Noisy -> 0
+
| `Errors_only -> 1
+
| `Silent -> 2
+13
lib/kgp_quiet.mli
···
···
+
(** Response Suppression Level
+
+
Controls which terminal responses are sent back to the application. *)
+
+
type t = [ `Noisy | `Errors_only | `Silent ]
+
(** Response suppression levels.
+
+
- [`Noisy] - Send all responses (default)
+
- [`Errors_only] - Suppress OK responses, only send errors
+
- [`Silent] - Suppress all responses *)
+
+
val to_int : t -> int
+
(** Convert to protocol integer (0, 1, or 2). *)
+6
lib/kgp_transmission.ml
···
···
+
type t = [ `Direct | `File | `Tempfile ]
+
+
let to_char : t -> char = function
+
| `Direct -> 'd'
+
| `File -> 'f'
+
| `Tempfile -> 't'
+13
lib/kgp_transmission.mli
···
···
+
(** Data Transmission Method
+
+
Specifies how image data is transmitted to the terminal. *)
+
+
type t = [ `Direct | `File | `Tempfile ]
+
(** Transmission methods.
+
+
- [`Direct] - Data is sent inline in the escape sequence
+
- [`File] - Terminal reads from a file path
+
- [`Tempfile] - Terminal reads and deletes a temporary file *)
+
+
val to_char : t -> char
+
(** Convert to protocol character ('d', 'f', or 't'). *)
-89
lib/kgp_types.ml
···
-
(* Kitty Graphics Protocol Types - Implementation *)
-
-
type format = [ `Rgba32 | `Rgb24 | `Png ]
-
type transmission = [ `Direct | `File | `Tempfile ]
-
type compression = [ `None | `Zlib ]
-
type quiet = [ `Noisy | `Errors_only | `Silent ]
-
type cursor = [ `Move | `Static ]
-
type composition = [ `Alpha_blend | `Overwrite ]
-
-
type delete =
-
[ `All_visible
-
| `All_visible_and_free
-
| `By_id of int * int option
-
| `By_id_and_free of int * int option
-
| `By_number of int * int option
-
| `By_number_and_free of int * int option
-
| `At_cursor
-
| `At_cursor_and_free
-
| `At_cell of int * int
-
| `At_cell_and_free of int * int
-
| `At_cell_z of int * int * int
-
| `At_cell_z_and_free of int * int * int
-
| `By_column of int
-
| `By_column_and_free of int
-
| `By_row of int
-
| `By_row_and_free of int
-
| `By_z_index of int
-
| `By_z_index_and_free of int
-
| `By_id_range of int * int
-
| `By_id_range_and_free of int * int
-
| `Frames
-
| `Frames_and_free ]
-
-
type animation_state = [ `Stop | `Loading | `Run ]
-
-
module Format = struct
-
type t = format
-
-
let to_int : t -> int = function
-
| `Rgba32 -> 32
-
| `Rgb24 -> 24
-
| `Png -> 100
-
end
-
-
module Transmission = struct
-
type t = transmission
-
-
let to_char : t -> char = function
-
| `Direct -> 'd'
-
| `File -> 'f'
-
| `Tempfile -> 't'
-
end
-
-
module Compression = struct
-
type t = compression
-
-
let to_char : t -> char option = function
-
| `None -> None
-
| `Zlib -> Some 'z'
-
end
-
-
module Quiet = struct
-
type t = quiet
-
-
let to_int : t -> int = function
-
| `Noisy -> 0
-
| `Errors_only -> 1
-
| `Silent -> 2
-
end
-
-
module Cursor = struct
-
type t = cursor
-
-
let to_int : t -> int = function
-
| `Move -> 0
-
| `Static -> 1
-
end
-
-
module Composition = struct
-
type t = composition
-
-
let to_int : t -> int = function
-
| `Alpha_blend -> 0
-
| `Overwrite -> 1
-
end
-
-
module Delete = struct
-
type t = delete
-
end
···
-109
lib/kgp_types.mli
···
-
(** Kitty Graphics Protocol Types
-
-
This module defines the base polymorphic variant types used throughout
-
the Kitty graphics protocol implementation. *)
-
-
(** {1 Polymorphic Variant Types} *)
-
-
type format = [ `Rgba32 | `Rgb24 | `Png ]
-
(** Image data formats. [`Rgba32] is 32-bit RGBA (4 bytes per pixel),
-
[`Rgb24] is 24-bit RGB (3 bytes per pixel), [`Png] is PNG encoded data. *)
-
-
type transmission = [ `Direct | `File | `Tempfile ]
-
(** Transmission methods. [`Direct] sends data inline, [`File] reads from a path,
-
[`Tempfile] reads from a temp file that the terminal deletes after reading. *)
-
-
type compression = [ `None | `Zlib ]
-
(** Compression options. [`None] for raw data, [`Zlib] for RFC 1950 compression. *)
-
-
type quiet = [ `Noisy | `Errors_only | `Silent ]
-
(** Response suppression. [`Noisy] sends all responses (default),
-
[`Errors_only] suppresses OK responses, [`Silent] suppresses all. *)
-
-
type cursor = [ `Move | `Static ]
-
(** Cursor movement after displaying. [`Move] advances cursor (default),
-
[`Static] keeps cursor in place. *)
-
-
type composition = [ `Alpha_blend | `Overwrite ]
-
(** Composition modes. [`Alpha_blend] for full blending (default),
-
[`Overwrite] for simple pixel replacement. *)
-
-
type delete =
-
[ `All_visible
-
| `All_visible_and_free
-
| `By_id of int * int option
-
| `By_id_and_free of int * int option
-
| `By_number of int * int option
-
| `By_number_and_free of int * int option
-
| `At_cursor
-
| `At_cursor_and_free
-
| `At_cell of int * int
-
| `At_cell_and_free of int * int
-
| `At_cell_z of int * int * int
-
| `At_cell_z_and_free of int * int * int
-
| `By_column of int
-
| `By_column_and_free of int
-
| `By_row of int
-
| `By_row_and_free of int
-
| `By_z_index of int
-
| `By_z_index_and_free of int
-
| `By_id_range of int * int
-
| `By_id_range_and_free of int * int
-
| `Frames
-
| `Frames_and_free ]
-
(** Delete target specification. Each variant has two forms: one that only
-
removes placements (e.g., [`All_visible]) and one that also frees the
-
image data (e.g., [`All_visible_and_free]). Tuple variants contain
-
(image_id, optional_placement_id) or (x, y) coordinates. *)
-
-
type animation_state = [ `Stop | `Loading | `Run ]
-
(** Animation playback state. [`Stop] halts animation, [`Loading] runs but
-
waits for new frames at end, [`Run] runs normally and loops. *)
-
-
(** {1 Type Modules} *)
-
-
module Format : sig
-
type t = format
-
-
val to_int : t -> int
-
(** Convert to protocol integer value (32, 24, or 100). *)
-
end
-
-
module Transmission : sig
-
type t = transmission
-
-
val to_char : t -> char
-
(** Convert to protocol character ('d', 'f', or 't'). *)
-
end
-
-
module Compression : sig
-
type t = compression
-
-
val to_char : t -> char option
-
(** Convert to protocol character ([None] or [Some 'z']). *)
-
end
-
-
module Quiet : sig
-
type t = quiet
-
-
val to_int : t -> int
-
(** Convert to protocol integer (0, 1, or 2). *)
-
end
-
-
module Cursor : sig
-
type t = cursor
-
-
val to_int : t -> int
-
(** Convert to protocol integer (0 or 1). *)
-
end
-
-
module Composition : sig
-
type t = composition
-
-
val to_int : t -> int
-
(** Convert to protocol integer (0 or 1). *)
-
end
-
-
module Delete : sig
-
type t = delete
-
end
···