0 | module Data.String.Builder
2 | import Data.Linear.Ref1
11 | record Builder (q : Type) where
14 | ref : Ref q (SnocList String)
18 | builder : F1 q (Builder q)
19 | builder = ref1 [<] >>= pure . B
23 | withBuilder : (forall q . Builder q => F1' q) -> String
29 | pure (fastConcat $
ss <>> [])
31 | parameters {auto b : Builder q}
38 | write1 b.ref (ss:<"\n")
45 | write1 b.ref (ss:<"\t")
52 | write1 b.ref (ss:<" ")
56 | spaces : Nat -> F1' q
59 | write1 b.ref (ss:<replicate n ' ')
63 | putText : String -> F1' q
64 | putText "" = pure ()
67 | write1 b.ref (ss:<s)
72 | putTextLn : String -> F1' q
73 | putTextLn "" = linebreak
76 | write1 b.ref (ss:<s:<"\n")
81 | putTextSep : String -> F1' q
82 | putTextSep "" = pure ()
83 | putTextSep s = T1.do
85 | write1 b.ref (ss:<s:<" ")
89 | putChars : List Char -> F1' q
90 | putChars = putText . fastPack
95 | putCharsLn : List Char -> F1' q
96 | putCharsLn = putTextLn . fastPack
100 | putShow : Show a => a -> F1' q
101 | putShow = putText . show
106 | putShowLn : Show a => a -> F1' q
107 | putShowLn = putTextLn . show
112 | putShowSep : Show a => a -> F1' q
113 | putShowSep = putTextSep . show
117 | putVal : Interpolation a => a -> F1' q
118 | putVal = putText . interpolate
123 | putValLn : Interpolation a => a -> F1' q
124 | putValLn = putTextLn . interpolate
129 | putValSep : Interpolation a => a -> F1' q
130 | putValSep = putTextSep . interpolate
134 | putAll : List String -> F1' q
137 | write1 b.ref (ss <>< l)
141 | putLeftPadded : Nat -> Char -> String -> F1' q
142 | putLeftPadded n c s = T1.do
144 | write1 b.ref (ss :< replicate (n `minus` length s) c :< s)
148 | padRightPadded : Nat -> Char -> String -> F1' q
149 | padRightPadded n c s = T1.do
151 | write1 b.ref (ss:< s:< replicate (n `minus` length s) c)