@@ -16,7 +16,7 @@ struct TextOutputFormat: OutputFormat {
1616extension TextOutputFormat {
1717 struct Builder : OutputBuilder {
1818 private let theme : Theme
19- private var accumulatedText : [ Text ]
19+ private var accumulatedText : [ AttributedString ]
2020
2121 fileprivate init ( theme: Theme ) {
2222 self . theme = theme
@@ -25,21 +25,24 @@ extension TextOutputFormat {
2525
2626 mutating func addToken( _ token: String , ofType type: TokenType ) {
2727 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)
2931 }
3032
3133 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 )
3537 }
3638
3739 mutating func addWhitespace( _ whitespace: String ) {
38- self . accumulatedText. append ( Text ( whitespace) )
40+ self . accumulatedText. append ( AttributedString ( whitespace) )
3941 }
4042
4143 func build( ) -> Text {
42- self . accumulatedText. reduce ( Text ( " " ) , + )
44+ let text = self . accumulatedText. reduce ( AttributedString ( " " ) , + )
45+ return Text ( text)
4346 }
4447 }
4548}
0 commit comments