46 lines
813 B
Swift
46 lines
813 B
Swift
@preconcurrency import Rainbow
|
|
|
|
public struct Header: NodeRepresentable, @unchecked Sendable {
|
|
|
|
@usableFromInline
|
|
let node: any NodeRepresentable
|
|
|
|
@usableFromInline
|
|
let color: NamedColor?
|
|
|
|
@usableFromInline
|
|
let styles: [Style]?
|
|
|
|
@inlinable
|
|
public init(
|
|
@NodeBuilder _ build: () -> any NodeRepresentable
|
|
) {
|
|
self.node = build()
|
|
self.color = nil
|
|
self.styles = nil
|
|
}
|
|
|
|
@inlinable
|
|
public init(
|
|
_ text: String,
|
|
color: NamedColor? = .yellow,
|
|
styles: [Style]? = [.bold]
|
|
) {
|
|
self.color = color
|
|
self.node = Text(text)
|
|
self.styles = styles
|
|
}
|
|
|
|
@inlinable
|
|
public func render() -> String {
|
|
var node = node
|
|
if let color {
|
|
node = node.color(color)
|
|
}
|
|
if let styles {
|
|
node = node.style(styles)
|
|
}
|
|
return node.render()
|
|
}
|
|
}
|