Kitty Graphics Protocol in OCaml
terminal graphics ocaml

headers

+5
example/example.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(* Kitty Graphics Protocol Demo - Matching kgp/examples/demo *)
module K = Kgp
+5
example/tiny_anim.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(* Tiny animation test - no chunking needed *)
(* Uses 20x20 images which are ~1067 bytes base64 (well under 4096) *)
+5
lib-cli/kgp_cli.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(* Cmdliner Support for Kitty Graphics Protocol *)
open Cmdliner
+5
lib-cli/kgp_cli.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Cmdliner Support for Kitty Graphics Protocol
This module provides Cmdliner terms for configuring graphics output mode
+5
lib/kgp.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(* Type modules *)
module Format = Kgp_format
module Transmission = Kgp_transmission
+5
lib/kgp.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Kitty Terminal Graphics Protocol
This library implements the Kitty terminal graphics protocol, allowing
+5
lib/kgp_animation.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
type t =
[ `Set_state of Kgp_animation_state.t * int option
| `Set_gap of int * int
+5
lib/kgp_animation.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Animation Control
Operations for controlling animation playback. The protocol supports
+5
lib/kgp_animation_state.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
type t = [ `Stop | `Loading | `Run ]
let to_int : t -> int = function
+5
lib/kgp_animation_state.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Animation Playback State
Controls the playback state of animated images.
+5
lib/kgp_command.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
type action =
[ `Transmit
| `Transmit_and_display
+5
lib/kgp_command.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Kitty Graphics Protocol Commands
This module provides functions for building and serializing graphics
+5
lib/kgp_compose.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
type t = {
source_frame : int;
dest_frame : int;
+5
lib/kgp_compose.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Frame Composition
Operations for compositing rectangular regions between animation frames.
+5
lib/kgp_composition.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
type t = [ `Alpha_blend | `Overwrite ]
let to_int : t -> int = function
+5
lib/kgp_composition.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Pixel Composition Mode
Controls how pixels are blended when compositing images or animation frames.
+5
lib/kgp_compression.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
type t = [ `None | `Zlib ]
let to_char : t -> char option = function
+5
lib/kgp_compression.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Data Compression
Specifies compression applied to image data before transmission.
+5
lib/kgp_cursor.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
type t = [ `Move | `Static ]
let to_int : t -> int = function
+5
lib/kgp_cursor.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Cursor Movement Behavior
Controls cursor position after displaying an image.
+5
lib/kgp_delete.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
type t =
[ `All_visible
| `By_id of int * int option
+5
lib/kgp_delete.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Image Deletion Target
Specifies which images or placements to delete.
+5
lib/kgp_detect.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(* Kitty Graphics Protocol Detection - Implementation *)
let make_query () =
+5
lib/kgp_detect.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Kitty Graphics Protocol Detection
Detect terminal graphics support capabilities. *)
+5
lib/kgp_format.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
type t = [ `Rgba32 | `Rgb24 | `Png ]
let to_int : t -> int = function
+5
lib/kgp_format.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Image Data Format
Specifies the pixel format of image data being transmitted to the terminal.
+5
lib/kgp_frame.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
type t = {
x : int option;
y : int option;
+5
lib/kgp_frame.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Animation Frame Configuration
Configuration for adding or editing animation frames. Frames can be
+5
lib/kgp_placement.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
type t = {
source_x : int option;
source_y : int option;
+5
lib/kgp_placement.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Image Placement Configuration
Configuration for where and how to display images. Placements control
+5
lib/kgp_quiet.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
type t = [ `Noisy | `Errors_only | `Silent ]
let to_int : t -> int = function
+5
lib/kgp_quiet.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Response Suppression Level
Controls which terminal responses are sent back to the application.
+5
lib/kgp_response.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(* Kitty Graphics Protocol Response - Implementation *)
type t = {
+5
lib/kgp_response.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Kitty Graphics Protocol Response
Parse and interpret terminal responses to graphics commands. *)
+5
lib/kgp_terminal.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(* Terminal Environment Detection *)
type graphics_mode = [ `Auto | `Enabled | `Disabled | `Tmux ]
+5
lib/kgp_terminal.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Terminal Environment Detection
Detect terminal capabilities and environment for graphics protocol support.
+5
lib/kgp_tmux.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(* Tmux Passthrough Support - Implementation *)
let is_active () =
+5
lib/kgp_tmux.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Tmux Passthrough Support
Support for passing graphics protocol escape sequences through tmux
+5
lib/kgp_transmission.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
type t = [ `Direct | `File | `Tempfile ]
let to_char : t -> char = function
+5
lib/kgp_transmission.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Data Transmission Method
Specifies how image data is transmitted to the terminal.
+5
lib/kgp_unicode.ml
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(* Kitty Graphics Protocol Unicode Placeholders - Implementation *)
let placeholder_char = Uchar.of_int 0x10EEEE
+5
lib/kgp_unicode.mli
···
+
(*---------------------------------------------------------------------------
+
Copyright (c) 2025 Anil Madhavapeddy. All rights reserved.
+
SPDX-License-Identifier: ISC
+
---------------------------------------------------------------------------*)
+
(** Kitty Graphics Protocol Unicode Placeholders
Support for invisible Unicode placeholder characters that encode