feat: Adds stack separators, removes some unused nodes from cli-doc module
All checks were successful
CI / Run tests. (push) Successful in 52s
All checks were successful
CI / Run tests. (push) Successful in 52s
This commit is contained in:
@@ -1,26 +1,57 @@
|
||||
/// A vertical stack of text nodes.
|
||||
///
|
||||
///
|
||||
|
||||
public struct VStack: TextNode {
|
||||
@usableFromInline
|
||||
let content: [any TextNode]
|
||||
|
||||
@usableFromInline
|
||||
let separator: Separator.Vertical
|
||||
|
||||
@inlinable
|
||||
public init(
|
||||
separator: Separator.Vertical = .newLine(count: 1),
|
||||
@TextBuilder content: () -> any TextNode
|
||||
) {
|
||||
self.content = array(from: content())
|
||||
self.separator = separator
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public var body: some TextNode {
|
||||
content.removingEmptys()
|
||||
.joined(separator: separator.render())
|
||||
style(.separator(.newLine(count: 1)))
|
||||
}
|
||||
}
|
||||
|
||||
public extension VStack {
|
||||
|
||||
func style<S: VStackStyle>(_ style: S) -> some TextNode {
|
||||
style.render(content: .init(content: content.removingEmptys()))
|
||||
}
|
||||
|
||||
func separator(_ separator: Separator.Vertical) -> some TextNode {
|
||||
style(.separator(separator))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Style
|
||||
|
||||
public protocol VStackStyle: TextModifier where Content == StackConfiguration {}
|
||||
|
||||
public extension VStackStyle where Self == VStackSeparatorStyle {
|
||||
|
||||
static func separator(_ separator: Separator.Vertical) -> Self {
|
||||
VStackSeparatorStyle(separator: separator)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public struct VStackSeparatorStyle: VStackStyle {
|
||||
@usableFromInline
|
||||
let separator: Separator.Vertical
|
||||
|
||||
@usableFromInline
|
||||
init(separator: Separator.Vertical) {
|
||||
self.separator = separator
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func render(content: StackConfiguration) -> some TextNode {
|
||||
AnySeparatableStackNode(content: content, separator: separator)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user