mirror of
https://github.com/pointfreeco/swift-composable-architecture.git
synced 2025-12-20 09:11:33 +01:00
TextState: DebugOutputConvertible (#421)
* Fix debug text * XML * wip * wip * wip
This commit is contained in:
@@ -302,3 +302,71 @@ extension LocalizedStringKey: CustomDebugOutputConvertible {
|
||||
self.formatted().debugDescription
|
||||
}
|
||||
}
|
||||
|
||||
extension TextState: CustomDebugOutputConvertible {
|
||||
public var debugOutput: String {
|
||||
func debugOutputHelp(_ textState: Self) -> String {
|
||||
var output: String
|
||||
switch textState.storage {
|
||||
case let .concatenated(lhs, rhs):
|
||||
output = debugOutputHelp(lhs) + debugOutputHelp(rhs)
|
||||
case let .localized(key, tableName, bundle, comment):
|
||||
output = key.formatted(tableName: tableName, bundle: bundle, comment: comment)
|
||||
case let .verbatim(string):
|
||||
output = string
|
||||
}
|
||||
for modifier in textState.modifiers {
|
||||
switch modifier {
|
||||
case let .baselineOffset(baselineOffset):
|
||||
output = "<baseline-offset=\(baselineOffset)>\(output)</baseline-offset>"
|
||||
case .bold, .fontWeight(.some(.bold)):
|
||||
output = "**\(output)**"
|
||||
case .font(.some):
|
||||
break // TODO: capture Font description using DSL similar to TextState and print here
|
||||
case let .fontWeight(.some(weight)):
|
||||
func describe(weight: Font.Weight) -> String {
|
||||
switch weight {
|
||||
case .black: return "black"
|
||||
case .bold: return "bold"
|
||||
case .heavy: return "heavy"
|
||||
case .light: return "light"
|
||||
case .medium: return "medium"
|
||||
case .regular: return "regular"
|
||||
case .semibold: return "semibold"
|
||||
case .thin: return "thin"
|
||||
default: return "\(weight)"
|
||||
}
|
||||
}
|
||||
output = "<font-weight=\(describe(weight: weight))>\(output)</font-weight>"
|
||||
case let .foregroundColor(.some(color)):
|
||||
output = "<foreground-color=\(color)>\(output)</foreground-color>"
|
||||
case .italic:
|
||||
output = "_\(output)_"
|
||||
case let .kerning(kerning):
|
||||
output = "<kerning=\(kerning)>\(output)</kerning>"
|
||||
case let .strikethrough(active: true, color: .some(color)):
|
||||
output = "<s color=\(color)>\(output)</s>"
|
||||
case .strikethrough(active: true, color: .none):
|
||||
output = "~~\(output)~~"
|
||||
case let .tracking(tracking):
|
||||
output = "<tracking=\(tracking)>\(output)</tracking>"
|
||||
case let .underline(active: true, color):
|
||||
output = "<u\(color.map { " color=\($0)" } ?? "")>\(output)</u>"
|
||||
case .font(.none),
|
||||
.fontWeight(.none),
|
||||
.foregroundColor(.none),
|
||||
.strikethrough(active: false, color: _),
|
||||
.underline(active: false, color: _):
|
||||
break
|
||||
}
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
return #"""
|
||||
\#(Self.self)(
|
||||
\#(debugOutputHelp(self).indent(by: 2))
|
||||
)
|
||||
"""#
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user