0 | module Text.PrettyPrint.Bernardy.Core.ANSI
 1 |
 2 | import Data.DPair
 3 | import Text.PrettyPrint.Bernardy.Core
 4 | import Text.ANSI
 5 |
 6 | %default total
 7 |
 8 | reset : String
 9 | reset = escapeSGR [Reset]
10 |
11 | decorateImpl :
12 |      String
13 |   -> (ss : SnocList String)
14 |   -> {auto 0 prf : NonEmptySnoc ss}
15 |   -> Subset (SnocList String) NonEmptySnoc
16 | decorateImpl s [<x]      = Element [<s ++ x ++ reset] %search
17 | decorateImpl s (sx :< x) = Element (go [] sx :< (x ++ reset)) %search
18 |   where
19 |     go : List String -> SnocList String -> SnocList String
20 |     go strs [< x]     = [< s ++ x] <>< strs
21 |     go strs (sx :< x) = go (x :: strs) sx
22 |     go strs [<]       = [<] <>< strs
23 |
24 | ||| Decorate a `Layout` with the given ANSI codes *without*
25 | ||| changing its stats like width or height.
26 | export
27 | decorateLayout : List SGR -> Layout -> Layout
28 | decorateLayout [] l = l
29 | decorateLayout xs (MkLayout content stats) =
30 |   layout (decorateImpl (escapeSGR xs) content) stats
31 |