My agentic slop goes here. Not intended for anyone else!
1(* Example demonstrating the Termgraph module of termext library *)
2
3let () =
4 print_endline "=== Kitty Graphics Protocol Demo ===\n";
5
6 (* Example 1: Display a PNG file *)
7 print_endline "--- Example 1: Display PNG file ---";
8 let png_path = "example.png" in
9 (* Simple convenience function *)
10 print_string (Termext.Termgraph.display_png_file png_path);
11 print_endline "\n";
12
13 (* Example 2: Display PNG file with size control *)
14 print_endline "--- Example 2: PNG file with sizing ---";
15 print_string (Termext.Termgraph.display_png_file
16 ~rows:10
17 ~columns:20
18 png_path);
19 print_endline "\n";
20
21 (* Example 3: Using the full placement API *)
22 print_endline "--- Example 3: Full placement control ---";
23 let img_id = Termext.Termgraph.image_id_of_string "demo-image" in
24 let placement = Termext.Termgraph.v
25 ~image_id:img_id
26 ~x:10
27 ~y:5
28 ~rows:15
29 ~columns:30
30 ~z_index:10
31 (Termext.Termgraph.File { path = png_path })
32 ()
33 in
34 print_string (Termext.Termgraph.render placement);
35 print_endline "\n";
36
37 (* Example 4: Direct transmission with raw PNG data *)
38 print_endline "--- Example 4: Direct transmission ---";
39 (* In a real use case, you would load PNG data from somewhere *)
40 let png_data = Bytes.of_string "\x89PNG\r\n\x1a\n..." in
41 print_string (Termext.Termgraph.display_png_bytes
42 ~w:100
43 ~h:100
44 ~rows:10
45 ~columns:10
46 png_data);
47 print_endline "\n";
48
49 (* Example 5: Fmt-style formatters *)
50 print_endline "--- Example 5: Fmt formatters ---";
51 let img = Termext.Termgraph.v
52 (Termext.Termgraph.File { path = "logo.png" })
53 ()
54 in
55 Fmt.pr "Here's our logo: %a\n" (Termext.Termgraph.pp img) ();
56 print_endline "";
57
58 (* Example 6: Animation *)
59 print_endline "--- Example 6: Animation frames ---";
60 let anim_id = Termext.Termgraph.image_id_of_string "animation" in
61
62 (* Upload frame 1 *)
63 let frame1 = Termext.Termgraph.Animation.frame
64 ~gap:100 (* 100ms gap *)
65 (Termext.Termgraph.File { path = "frame1.png" })
66 1 (* Frame number *)
67 in
68 print_string (Termext.Termgraph.Animation.render_frame anim_id frame1);
69
70 (* Upload frame 2 *)
71 let frame2 = Termext.Termgraph.Animation.frame
72 ~gap:100
73 ~composition:Termext.Termgraph.Animation.Blend
74 (Termext.Termgraph.File { path = "frame2.png" })
75 2
76 in
77 print_string (Termext.Termgraph.Animation.render_frame anim_id frame2);
78
79 (* Upload frame 3 *)
80 let frame3 = Termext.Termgraph.Animation.frame
81 ~gap:100
82 (Termext.Termgraph.File { path = "frame3.png" })
83 3
84 in
85 print_string (Termext.Termgraph.Animation.render_frame anim_id frame3);
86
87 (* Set animation to loop infinitely *)
88 let loop_control = Termext.Termgraph.Animation.Set_loop 0 in
89 print_string (Termext.Termgraph.Animation.render_control anim_id loop_control);
90 print_endline "\n";
91
92 (* Example 7: Using Fmt for animation *)
93 print_endline "--- Example 7: Animation with Fmt ---";
94 Fmt.pr "Frame 1: %a\n"
95 (Termext.Termgraph.pp_animation_frame anim_id frame1) ();
96 Fmt.pr "Setting loop: %a\n"
97 (Termext.Termgraph.pp_animation_control anim_id (Termext.Termgraph.Animation.Set_loop 3)) ();
98 print_endline "";
99
100 (* Example 8: Deletion *)
101 print_endline "--- Example 8: Deleting images ---";
102 Unix.sleep 2; (* Show images for 2 seconds *)
103
104 (* Delete specific image *)
105 print_string (Termext.Termgraph.delete_by_id img_id);
106
107 (* Or delete all images *)
108 print_string (Termext.Termgraph.delete_all ());
109 print_endline "";
110
111 (* Example 9: Complex scene with z-index *)
112 print_endline "--- Example 9: Layered images ---";
113 (* Background layer *)
114 let bg = Termext.Termgraph.v
115 ~image_id:(Termext.Termgraph.image_id_of_string "background")
116 ~z_index:(-10)
117 ~rows:20
118 ~columns:40
119 (Termext.Termgraph.File { path = "background.png" })
120 ()
121 in
122 print_string (Termext.Termgraph.render bg);
123
124 (* Foreground layer *)
125 let fg = Termext.Termgraph.v
126 ~image_id:(Termext.Termgraph.image_id_of_string "foreground")
127 ~z_index:10
128 ~x:50
129 ~y:50
130 ~rows:10
131 ~columns:20
132 (Termext.Termgraph.File { path = "sprite.png" })
133 ()
134 in
135 print_string (Termext.Termgraph.render fg);
136 print_endline "\n";
137
138 (* Example 10: Combining text sizing and graphics *)
139 print_endline "--- Example 10: Mixed text and graphics ---";
140 print_string (Termext.Textsize.double "Large Title");
141 print_endline "\n";
142
143 let small_img = Termext.Termgraph.v
144 ~rows:5
145 ~columns:10
146 (Termext.Termgraph.File { path = "icon.png" })
147 ()
148 in
149 Fmt.pr "Icon: %a Description text here\n"
150 (Termext.Termgraph.pp small_img) ();
151
152 print_string (Termext.Textsize.subscript "footnote");
153 print_endline "\n";
154
155 print_endline "=== Demo Complete ===";
156 print_endline "Note: This demo requires PNG files and a Kitty-compatible terminal.";