feat: Working on node builder
This commit is contained in:
35
Sources/CliDoc/Modifiers/Color.swift
Normal file
35
Sources/CliDoc/Modifiers/Color.swift
Normal file
@@ -0,0 +1,35 @@
|
||||
import Rainbow
|
||||
|
||||
public extension NodeRepresentable {
|
||||
|
||||
@inlinable
|
||||
func color(_ color: NamedColor) -> any NodeRepresentable {
|
||||
modifier(ColorModifier(color: color))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public extension NodeModifier {
|
||||
|
||||
@inlinable
|
||||
static func color(_ color: NamedColor) -> Self where Self == AnyNodeModifier {
|
||||
.init(ColorModifier(color: color))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
struct ColorModifier: NodeModifier, @unchecked Sendable {
|
||||
@usableFromInline
|
||||
let color: NamedColor
|
||||
|
||||
@usableFromInline
|
||||
init(color: NamedColor) {
|
||||
self.color = color
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
func render(_ node: any NodeRepresentable) -> any NodeRepresentable {
|
||||
node.render().applyingColor(color)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user