overhaul colour/ordering system for coherency
squash
This commit is contained in:
parent
0f82bd2dba
commit
3fc9c2e2c8
6 changed files with 90 additions and 38 deletions
|
@ -10,22 +10,6 @@ let ansi_filter s =
|
|||
a)
|
||||
| n -> n
|
||||
|
||||
let permute (order : int array) (colours : colour array) =
|
||||
let olen = length order and clen = length colours in
|
||||
match (olen, clen) with
|
||||
(* nothing provided, take default 16 pal colours *)
|
||||
| 0, 0 -> Seq.ints 0 |> Seq.take 16 |> Seq.map (fun i -> Simple i) |> of_seq
|
||||
(* colours provided with no order, take them as is *)
|
||||
| 0, _ -> colours
|
||||
(* order provided with no colours, map to palette colours *)
|
||||
| _, 0 -> order |> map (fun o -> Simple o)
|
||||
(* order and colours provided, apply order to colours and sub palette where
|
||||
order index exceeds colour array length *)
|
||||
| _, _ ->
|
||||
order
|
||||
|> mapi (fun i o ->
|
||||
if order.(i) < clen then colours.(order.(i)) else Simple o)
|
||||
|
||||
(* TODO: implement this so cli can use a dsl to specify colourising patterns *)
|
||||
type culr = { colours : colour array; sz : int; mutable current : int }
|
||||
|
||||
|
@ -36,13 +20,12 @@ module Culriser = struct
|
|||
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 f (c : colour array) =
|
||||
let create ?(filters = []) (c : colour array) =
|
||||
let ( @ ) = append in
|
||||
let colours =
|
||||
c |> permute s |> fun c ->
|
||||
if List.length f > 0 then
|
||||
if List.length filters > 0 then
|
||||
fold_left
|
||||
(fun acc el -> if run_filters f el then acc @ [| el |] else acc)
|
||||
(fun acc el -> if run_filters filters el then acc @ [| el |] else acc)
|
||||
[||] c
|
||||
else c
|
||||
in
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue