implement CULRS and CULR_ORDER env vars

This commit is contained in:
atagen 2024-12-03 01:32:28 +11:00
parent 8db7ba4de3
commit 3a2b319b2f
3 changed files with 55 additions and 22 deletions

View file

@ -1,21 +1,13 @@
let read_all () =
open Processing
let read_all colours order =
In_channel.set_binary_mode stdin true;
let open Types in
let t = Emitter.create
and culr =
Processing.Culriser.create ~s:[| 0; 2; 1; 3; 4 |]
~f:[ (function RGB (r, g, _) -> (g > 0 || r = 255) | _ -> true) ]
[| Simple 0; Simple 1; Simple 2; RGB (255, 0, 127); RGB (0, 200, 0) |]
in
Emitter.serialise t (Ansi [ Fg (Processing.Culriser.next culr) ]);
let t = Emitter.create and culr = Culriser.create order [] colours in
Emitter.serialise t (Ansi [ Fg (Culriser.next culr) ]);
Angstrom_unix.parse_many ~buf_size:4096 Parse.culr_parse
(fun c ->
c |> Processing.ansi_filter
|> Processing.Culriser.add_colour culr t
|> Emitter.serialise t)
(fun c -> c |> ansi_filter |> Culriser.serialise_with_colour culr t)
stdin
|> function
| _, Ok _ ->
Emitter.flush t
(* print_endline ("didn't parse this much: " ^ string_of_int unparsed.len ^ "\nunparsed:\n" ^ (Bigstringaf.substring unparsed.buf ~off:unparsed.off ~len:unparsed.len) ); *)
| _, Ok _ -> Emitter.flush t
| _ -> ()