@@ -302,3 +302,71 @@ extension LocalizedStringKey: CustomDebugOutputConvertible {
302302 self . formatted ( ) . debugDescription
303303 }
304304}
305+
306+ extension TextState : CustomDebugOutputConvertible {
307+ public var debugOutput : String {
308+ func debugOutputHelp( _ textState: Self ) -> String {
309+ var output : String
310+ switch textState. storage {
311+ case let . concatenated( lhs, rhs) :
312+ output = debugOutputHelp ( lhs) + debugOutputHelp( rhs)
313+ case let . localized( key, tableName, bundle, comment) :
314+ output = key. formatted ( tableName: tableName, bundle: bundle, comment: comment)
315+ case let . verbatim( string) :
316+ output = string
317+ }
318+ for modifier in textState. modifiers {
319+ switch modifier {
320+ case let . baselineOffset( baselineOffset) :
321+ output = " <baseline-offset= \( baselineOffset) > \( output) </baseline-offset> "
322+ case . bold, . fontWeight( . some( . bold) ) :
323+ output = " ** \( output) ** "
324+ case . font( . some) :
325+ break // TODO: capture Font description using DSL similar to TextState and print here
326+ case let . fontWeight( . some( weight) ) :
327+ func describe( weight: Font . Weight ) -> String {
328+ switch weight {
329+ case . black: return " black "
330+ case . bold: return " bold "
331+ case . heavy: return " heavy "
332+ case . light: return " light "
333+ case . medium: return " medium "
334+ case . regular: return " regular "
335+ case . semibold: return " semibold "
336+ case . thin: return " thin "
337+ default : return " \( weight) "
338+ }
339+ }
340+ output = " <font-weight= \( describe ( weight: weight) ) > \( output) </font-weight> "
341+ case let . foregroundColor( . some( color) ) :
342+ output = " <foreground-color= \( color) > \( output) </foreground-color> "
343+ case . italic:
344+ output = " _ \( output) _ "
345+ case let . kerning( kerning) :
346+ output = " <kerning= \( kerning) > \( output) </kerning> "
347+ case let . strikethrough( active: true , color: . some( color) ) :
348+ output = " <s color= \( color) > \( output) </s> "
349+ case . strikethrough( active: true , color: . none) :
350+ output = " ~~ \( output) ~~ "
351+ case let . tracking( tracking) :
352+ output = " <tracking= \( tracking) > \( output) </tracking> "
353+ case let . underline( active: true , color) :
354+ output = " <u \( color. map { " color= \( $0) " } ?? " " ) > \( output) </u> "
355+ case . font( . none) ,
356+ . fontWeight( . none) ,
357+ . foregroundColor( . none) ,
358+ . strikethrough( active: false , color: _) ,
359+ . underline( active: false , color: _) :
360+ break
361+ }
362+ }
363+ return output
364+ }
365+
366+ return #"""
367+ \#( Self . self) (
368+ \#( debugOutputHelp ( self ) . indent ( by: 2 ) )
369+ )
370+ """#
371+ }
372+ }
0 commit comments