feat: Working on node builder

This commit is contained in:
2024-12-01 01:41:36 -05:00
parent 56a406b231
commit 55d8888961
14 changed files with 480 additions and 39 deletions

View File

@@ -0,0 +1,32 @@
@preconcurrency import Rainbow
public struct Header: NodeRepresentable {
@usableFromInline
let node: Text
@usableFromInline
let styles: [Style]
@inlinable
public init(
_ text: String,
color: NamedColor? = .yellow,
styles: [Style] = [.bold]
) {
var text = Text(text)
if let color {
text = text.color(color)
}
self.node = text
self.styles = styles
}
@inlinable
public func render() -> String {
styles.reduce(node) { node, style in
node.style(style)
}
.render()
}
}