add serialisation inline with culring
This commit is contained in:
parent
3a2b319b2f
commit
9838079f03
@ -18,17 +18,18 @@ module Culriser = struct
|
||||
type filter = (colour -> bool) list
|
||||
type sort = int array
|
||||
|
||||
let run_filters f el =
|
||||
let run_filters (f : filter) el =
|
||||
List.fold_left (fun res filt -> if not (filt el) then false else res) true f
|
||||
|
||||
let create ?(s = [| 0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15 |])
|
||||
?(f = []) c =
|
||||
let create s f c =
|
||||
let ( @ ) = Array.append in
|
||||
let colours =
|
||||
c |> permute s
|
||||
|> Array.fold_left
|
||||
(fun acc el -> if run_filters f el then acc @ [| el |] else acc)
|
||||
[||]
|
||||
c |> permute s |> fun c ->
|
||||
if List.length f > 0 then
|
||||
Array.fold_left
|
||||
(fun acc el -> if run_filters f el then acc @ [| el |] else acc)
|
||||
[||] c
|
||||
else c
|
||||
in
|
||||
{ colours; sz = Array.length colours; current = 0 }
|
||||
|
||||
@ -39,12 +40,12 @@ module Culriser = struct
|
||||
|
||||
let reset t = t.current <- 0
|
||||
|
||||
let add_colour t serialiser chunk =
|
||||
let serialise_with_colour t serialiser chunk =
|
||||
(match chunk with
|
||||
| Separator _ -> Emitter.serialise serialiser (Ansi [ Fg (next t) ])
|
||||
| Delimiter _ ->
|
||||
reset t;
|
||||
Emitter.serialise serialiser (Ansi [ Fg (next t) ])
|
||||
| _ -> ());
|
||||
chunk
|
||||
Emitter.serialise serialiser chunk
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user