Kitty Graphics Protocol in OCaml
terminal graphics ocaml
1(*--------------------------------------------------------------------------- 2 Copyright (c) 2025 Anil Madhavapeddy. All rights reserved. 3 SPDX-License-Identifier: ISC 4 ---------------------------------------------------------------------------*) 5 6(** Cmdliner Support for Kitty Graphics Protocol 7 8 This module provides Cmdliner terms for configuring graphics output mode in 9 CLI applications. It allows users to override auto-detection with 10 command-line flags. 11 12 {2 Usage} 13 14 Add the graphics term to your command: 15 16 {[ 17 let cmd = 18 let graphics = Kgp_cli.graphics_term in 19 let my_args = ... in 20 Cmd.v info Term.(const my_run $ graphics $ my_args) 21 ]} 22 23 Then use the resolved mode in your application: 24 25 {[ 26 let my_run graphics_mode args = 27 if Kgp.Terminal.supports_graphics graphics_mode then 28 (* render with graphics *) 29 else 30 (* use text fallback *) 31 ]} *) 32 33(** {1 Terms} *) 34 35val graphics_term : Kgp.Terminal.graphics_mode Cmdliner.Term.t 36(** Cmdliner term for graphics mode selection. 37 38 Provides the following command-line options: 39 40 - [--graphics] / [-g]: Force graphics output enabled 41 - [--no-graphics]: Force graphics output disabled (use placeholders) 42 - [--tmux]: Force tmux passthrough mode 43 - (default): Auto-detect based on terminal environment 44 45 The term evaluates to a {!Kgp.Terminal.graphics_mode} value which can be 46 passed to {!Kgp.Terminal.supports_graphics} or {!Kgp.Terminal.resolve_mode}. 47*) 48 49val graphics_docs : string 50(** Section name for graphics options in help output ("GRAPHICS OPTIONS"). 51 52 Use this when grouping graphics options in a separate help section. *)