feat: Working on node builder
This commit is contained in:
@@ -13,43 +13,6 @@ public struct Text: NodeRepresentable {
|
||||
public func render() -> String {
|
||||
text
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func color(_ color: NamedColor) -> Self {
|
||||
.init(text.applyingColor(color))
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func style(_ style: Style) -> Self {
|
||||
.init(text.applyingStyle(style))
|
||||
}
|
||||
}
|
||||
|
||||
public struct NewLine: NodeRepresentable {
|
||||
@usableFromInline
|
||||
let node: any NodeRepresentable
|
||||
|
||||
@inlinable
|
||||
public init(count: Int = 1) {
|
||||
self.node = Text("\n").repeating(count)
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func render() -> String {
|
||||
node.render()
|
||||
}
|
||||
}
|
||||
|
||||
public struct Space: NodeRepresentable {
|
||||
let node: any NodeRepresentable
|
||||
|
||||
public init(count: Int = 1) {
|
||||
self.node = Text(" ").repeating(count)
|
||||
}
|
||||
|
||||
public func render() -> String {
|
||||
node.render()
|
||||
}
|
||||
}
|
||||
|
||||
public extension NodeRepresentable {
|
||||
@@ -58,12 +21,12 @@ public extension NodeRepresentable {
|
||||
Text("")
|
||||
}
|
||||
|
||||
static func newLine(count: Int = 1) -> Self where Self == NewLine {
|
||||
NewLine(count: count)
|
||||
static func newLine(count: Int = 1) -> Self where Self == AnyNode {
|
||||
"\n".repeating(count).eraseToAnyNode()
|
||||
}
|
||||
|
||||
static func space(count: Int = 1) -> Self where Self == Space {
|
||||
Space(count: count)
|
||||
static func space(count: Int = 1) -> Self where Self == AnyNode {
|
||||
" ".repeating(count).eraseToAnyNode()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user