ensure correct treatment of colourisation re invisible characters

This commit is contained in:
atagen 2024-12-05 23:11:04 +11:00
parent e440fda10c
commit 6d98e1639b

View File

@ -7,6 +7,7 @@ type culr = {
sz : int;
mutable current : int;
mutable first : bool;
mutable text_output : bool;
}
module Culriser = struct
@ -25,28 +26,41 @@ module Culriser = struct
[||] c
else c
in
{ colours; sz = length colours; current = 0; first = true }
{
colours;
sz = length colours;
current = 0;
first = true;
text_output = false;
}
let current t = t.colours.(t.current)
let next t =
t.current <- (t.current + 1) mod t.sz;
t.colours.(t.current)
current t
let reset t =
t.current <- 0;
t.first <- true
t.first <- true;
t.text_output <- false
let serialise_with_colour t serialiser chunk =
Emitter.serialise serialiser chunk;
(match chunk with
match chunk with
| Separator _ ->
if not t.first then Emitter.serialise serialiser (Ansi [ Fg (next t) ])
if not t.first then
if t.text_output then (
Emitter.serialise serialiser (Ansi [ Fg (next t) ]);
t.text_output <- false)
else Emitter.serialise serialiser (Ansi [ Fg (current t) ])
| Delimiter _ ->
reset t;
Emitter.serialise serialiser (Ansi [ Fg (current t) ]);
| Text _ -> if t.first then t.first <- false
| _ -> ())
Emitter.serialise serialiser (Ansi [ Fg (current t) ])
| Text _ ->
if t.first then t.first <- false;
if not t.text_output then t.text_output <- true
| _ -> ()
end
let ansi_filter t s =