···211211(** {2 Deletion}
212212213213 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. *)
214214+ By default, only placements are removed and image data is retained
215215+ for potential reuse. Use [~free:true] to also release the image data. *)
216216217217-val delete : ?quiet:Quiet.t -> Delete.t -> command
217217+val delete : ?free:bool -> ?quiet:Quiet.t -> Delete.t -> command
218218(** Delete images or placements.
219219220220 See {!Delete} for the full list of deletion targets.
221221222222+ @param free If true, also free the image data from memory (default: false).
223223+ Without [~free:true], only placements are removed and the image data
224224+ can be reused for new placements.
225225+222226 Examples:
223227 {[
224224- (* Delete all visible images *)
228228+ (* Delete all visible images, keep data *)
225229 Kgp.delete `All_visible
226230227231 (* Delete specific image, keeping data for reuse *)
228232 Kgp.delete (`By_id (42, None))
229233230234 (* Delete specific image and free its data *)
231231- Kgp.delete (`By_id_and_free (42, None))
235235+ Kgp.delete ~free:true (`By_id (42, None))
232236233237 (* Delete all placements at a specific cell *)
234238 Kgp.delete (`At_cell (10, 5))
+16-15
lib/kgp_command.ml
···2222 image_number : int option;
2323 placement : Kgp_placement.t option;
2424 delete : Kgp_delete.t option;
2525+ delete_free : bool;
2526 frame : Kgp_frame.t option;
2627 animation : Kgp_animation.t option;
2728 compose : Kgp_compose.t option;
···4243 image_number = None;
4344 placement = None;
4445 delete = None;
4646+ delete_free = false;
4547 frame = None;
4648 animation = None;
4749 compose = None;
···8688let display ?image_id ?image_number ?placement ?quiet () =
8789 { (make `Display) with image_id; image_number; placement; quiet }
88908989-let delete ?quiet del = { (make `Delete) with quiet; delete = Some del }
9191+let delete ?(free = false) ?quiet del =
9292+ { (make `Delete) with quiet; delete = Some del; delete_free = free }
90939194let frame ?image_id ?image_number ?format ?transmission ?compression ?width
9295 ?height ?quiet ~frame () =
···162165 kv_int_if w 'C' ~default:0 (Some (Kgp_cursor.to_int c)));
163166 if Kgp_placement.unicode_placeholder p then kv_int w 'U' 1
164167165165-let write_delete w (d : Kgp_delete.t) =
166166- kv_char w 'd' (Kgp_delete.to_char d);
168168+let write_delete w ~free (d : Kgp_delete.t) =
169169+ kv_char w 'd' (Kgp_delete.to_char ~free d);
167170 match d with
168168- | `By_id (id, pid) | `By_id_and_free (id, pid) ->
171171+ | `By_id (id, pid) ->
169172 kv_int w 'i' id;
170173 kv_int_opt w 'p' pid
171171- | `By_number (n, pid) | `By_number_and_free (n, pid) ->
174174+ | `By_number (n, pid) ->
172175 kv_int w 'I' n;
173176 kv_int_opt w 'p' pid
174174- | `At_cell (x, y) | `At_cell_and_free (x, y) ->
177177+ | `At_cell (x, y) ->
175178 kv_int w 'x' x;
176179 kv_int w 'y' y
177177- | `At_cell_z (x, y, z) | `At_cell_z_and_free (x, y, z) ->
180180+ | `At_cell_z (x, y, z) ->
178181 kv_int w 'x' x;
179182 kv_int w 'y' y;
180183 kv_int w 'z' z
181181- | `By_column c | `By_column_and_free c -> kv_int w 'x' c
182182- | `By_row r | `By_row_and_free r -> kv_int w 'y' r
183183- | `By_z_index z | `By_z_index_and_free z -> kv_int w 'z' z
184184- | `By_id_range (min_id, max_id) | `By_id_range_and_free (min_id, max_id) ->
184184+ | `By_column c -> kv_int w 'x' c
185185+ | `By_row r -> kv_int w 'y' r
186186+ | `By_z_index z -> kv_int w 'z' z
187187+ | `By_id_range (min_id, max_id) ->
185188 kv_int w 'x' min_id;
186189 kv_int w 'y' max_id
187187- | `All_visible | `All_visible_and_free | `At_cursor | `At_cursor_and_free
188188- | `Frames | `Frames_and_free ->
189189- ()
190190+ | `All_visible | `At_cursor | `Frames -> ()
190191191192let write_frame w (f : Kgp_frame.t) =
192193 kv_int_opt w 'x' (Kgp_frame.x f);
···255256 kv_int_opt w 'I' cmd.image_number;
256257 (* Complex options *)
257258 cmd.placement |> Option.iter (write_placement w);
258258- cmd.delete |> Option.iter (write_delete w);
259259+ cmd.delete |> Option.iter (write_delete w ~free:cmd.delete_free);
259260 cmd.frame |> Option.iter (write_frame w);
260261 cmd.animation |> Option.iter (write_animation w);
261262 cmd.compose |> Option.iter (write_compose w);
+6-2
lib/kgp_command.mli
···62626363(** {1 Deletion} *)
64646565-val delete : ?quiet:Kgp_quiet.t -> Kgp_delete.t -> t
6666-(** Delete images or placements. *)
6565+val delete : ?free:bool -> ?quiet:Kgp_quiet.t -> Kgp_delete.t -> t
6666+(** Delete images or placements.
6767+6868+ @param free If true, also free the image data from memory (default: false).
6969+ Without [~free:true], only placements are removed and the image data
7070+ can be reused for new placements. *)
67716872(** {1 Animation} *)
6973
+18-35
lib/kgp_delete.ml
···11type t =
22 [ `All_visible
33- | `All_visible_and_free
43 | `By_id of int * int option
55- | `By_id_and_free of int * int option
64 | `By_number of int * int option
77- | `By_number_and_free of int * int option
85 | `At_cursor
99- | `At_cursor_and_free
106 | `At_cell of int * int
1111- | `At_cell_and_free of int * int
127 | `At_cell_z of int * int * int
1313- | `At_cell_z_and_free of int * int * int
148 | `By_column of int
1515- | `By_column_and_free of int
169 | `By_row of int
1717- | `By_row_and_free of int
1810 | `By_z_index of int
1919- | `By_z_index_and_free of int
2011 | `By_id_range of int * int
2121- | `By_id_range_and_free of int * int
2222- | `Frames
2323- | `Frames_and_free ]
1212+ | `Frames ]
24132525-let to_char : t -> char = function
2626- | `All_visible -> 'a'
2727- | `All_visible_and_free -> 'A'
2828- | `By_id _ -> 'i'
2929- | `By_id_and_free _ -> 'I'
3030- | `By_number _ -> 'n'
3131- | `By_number_and_free _ -> 'N'
3232- | `At_cursor -> 'c'
3333- | `At_cursor_and_free -> 'C'
3434- | `At_cell _ -> 'p'
3535- | `At_cell_and_free _ -> 'P'
3636- | `At_cell_z _ -> 'q'
3737- | `At_cell_z_and_free _ -> 'Q'
3838- | `By_column _ -> 'x'
3939- | `By_column_and_free _ -> 'X'
4040- | `By_row _ -> 'y'
4141- | `By_row_and_free _ -> 'Y'
4242- | `By_z_index _ -> 'z'
4343- | `By_z_index_and_free _ -> 'Z'
4444- | `By_id_range _ -> 'r'
4545- | `By_id_range_and_free _ -> 'R'
4646- | `Frames -> 'f'
4747- | `Frames_and_free -> 'F'
1414+let to_char ~free : t -> char =
1515+ let base = function
1616+ | `All_visible -> 'a'
1717+ | `By_id _ -> 'i'
1818+ | `By_number _ -> 'n'
1919+ | `At_cursor -> 'c'
2020+ | `At_cell _ -> 'p'
2121+ | `At_cell_z _ -> 'q'
2222+ | `By_column _ -> 'x'
2323+ | `By_row _ -> 'y'
2424+ | `By_z_index _ -> 'z'
2525+ | `By_id_range _ -> 'r'
2626+ | `Frames -> 'f'
2727+ in
2828+ fun t ->
2929+ let c = base t in
3030+ if free then Char.uppercase_ascii c else c
+16-28
lib/kgp_delete.mli
···25252626 {2 Placements vs Image Data}
27272828- 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.
2828+ Each deletion type can optionally free image data (controlled by the
2929+ [~free] parameter in the delete command):
3030+ - {b Without free}: Removes placements only. The image data remains in
3131+ memory and can be displayed again later. (Protocol: lowercase char)
3232+ - {b With free}: Removes placements AND frees the image data. The
3333+ image cannot be displayed again without retransmitting. (Protocol:
3434+ uppercase char)
37353836 {2 Placement IDs}
3937···5048 {2 Virtual Placements}
51495250 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. *)
5151+ by: [{`By_id}], [{`By_number}], and [{`By_id_range}]. Other deletion
5252+ commands do not affect virtual placements. *)
56535754type t =
5855 [ `All_visible
5959- | `All_visible_and_free
6056 | `By_id of int * int option
6161- | `By_id_and_free of int * int option
6257 | `By_number of int * int option
6363- | `By_number_and_free of int * int option
6458 | `At_cursor
6565- | `At_cursor_and_free
6659 | `At_cell of int * int
6767- | `At_cell_and_free of int * int
6860 | `At_cell_z of int * int * int
6969- | `At_cell_z_and_free of int * int * int
7061 | `By_column of int
7171- | `By_column_and_free of int
7262 | `By_row of int
7373- | `By_row_and_free of int
7463 | `By_z_index of int
7575- | `By_z_index_and_free of int
7664 | `By_id_range of int * int
7777- | `By_id_range_and_free of int * int
7878- | `Frames
7979- | `Frames_and_free ]
6565+ | `Frames ]
8066(** Deletion target specification.
81678268 {b Screen-based:}
···9884 {b Animation:}
9985 - [`Frames] - Animation frames only (not the base image)
10086101101- All variants have an [_and_free] version that also releases image data. *)
8787+ Use the [~free] parameter in the delete command to also release
8888+ image data from memory. *)
10289103103-val to_char : t -> char
9090+val to_char : free:bool -> t -> char
10491(** Convert to protocol character for the delete command.
10592106106- Returns the character used in the [d=] control data key. Lowercase
107107- for placement-only deletion, uppercase for deletion with data free. *)
9393+ Returns the character used in the [d=] control data key.
9494+ @param free If true, returns uppercase (frees data); if false,
9595+ returns lowercase (keeps data). *)