diff --git a/lib/processing.ml b/lib/processing.ml index e7ab80a..abd919b 100644 --- a/lib/processing.ml +++ b/lib/processing.ml @@ -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 =