@@ -16,7 +16,7 @@ struct TextOutputFormat: OutputFormat {
16
16
extension TextOutputFormat {
17
17
struct Builder : OutputBuilder {
18
18
private let theme : Theme
19
- private var accumulatedText : [ Text ]
19
+ private var accumulatedText : [ AttributedString ]
20
20
21
21
fileprivate init ( theme: Theme ) {
22
22
self . theme = theme
@@ -25,21 +25,24 @@ extension TextOutputFormat {
25
25
26
26
mutating func addToken( _ token: String , ofType type: TokenType ) {
27
27
let color = self . theme. tokenColors [ type] ?? self . theme. plainTextColor
28
- self . accumulatedText. append ( Text ( token) . foregroundColor ( . init( uiColor: color) ) )
28
+ var aster = AttributedString ( token)
29
+ aster. foregroundColor = . init( uiColor: color)
30
+ self . accumulatedText. append ( aster)
29
31
}
30
32
31
33
mutating func addPlainText( _ text: String ) {
32
- self . accumulatedText . append (
33
- Text ( text ) . foregroundColor ( . init( uiColor: self . theme. plainTextColor) )
34
- )
34
+ var aster = AttributedString ( text )
35
+ aster . foregroundColor = . init( uiColor: self . theme. plainTextColor)
36
+ self . accumulatedText . append ( aster )
35
37
}
36
38
37
39
mutating func addWhitespace( _ whitespace: String ) {
38
- self . accumulatedText. append ( Text ( whitespace) )
40
+ self . accumulatedText. append ( AttributedString ( whitespace) )
39
41
}
40
42
41
43
func build( ) -> Text {
42
- self . accumulatedText. reduce ( Text ( " " ) , + )
44
+ let text = self . accumulatedText. reduce ( AttributedString ( " " ) , + )
45
+ return Text ( text)
43
46
}
44
47
}
45
48
}
0 commit comments