Files
phranck db8ea40c0a Refactor: Fix SwiftLint warnings and refactor StatusBar to _StatusBarCore pattern
- Fix 80 SwiftLint warnings (159 -> 79): vertical_whitespace, prefer_self_in_static_references, modifier_order, trailing_newline, trailing_whitespace, prefer_for_where, unneeded_synthesized_initializer, redundant_type_annotation, implicit_optional_initialization, superfluous_disable_command, shorthand_optional_binding, syntactic_sugar, empty_string, vertical_whitespace_closing_braces, identifier_name in BadgeModifier
- Refactor StatusBar from direct Renderable to _StatusBarCore pattern (public View with real body wrapping private Renderable core)
2026-02-15 02:35:18 +01:00

76 lines
2.3 KiB
Swift

// 🖥️ TUIKit — Terminal UI Kit for Swift
// View.swift
//
// Created by LAYERED.work
// License: MIT
import TUIkitCore
/// The base protocol for all TUIkit views.
///
/// `View` is the central protocol in TUIkit and works similarly to `View` in SwiftUI.
/// It defines how components declare their structure and content.
///
/// Every View defines a `body` composed of other Views.
/// This enables a hierarchical, declarative UI description.
///
/// ## Dual Rendering System
///
/// TUIkit uses two rendering paths:
///
/// - **Composite views** implement `body` to compose other views.
/// The rendering system recurses into `body` to resolve the tree.
/// - **Primitive views** additionally conform to `Renderable` and
/// produce a ``FrameBuffer`` directly. They set `body: Never`
/// (which `fatalError`s if called) because their `body` is never used.
///
/// The free function `renderToBuffer(_:context:)` checks `Renderable`
/// first, then falls back to `body`. See `Renderable` for details.
///
/// ## Creating a composite view
///
/// ```swift
/// struct MyView: View {
/// var body: some View {
/// Text("Hello, TUIkit!")
/// }
/// }
/// ```
///
/// ## Creating a primitive view
///
/// ```swift
/// struct MyPrimitive: View {
/// var body: Never { fatalError() }
/// }
///
/// extension MyPrimitive: Renderable {
/// func renderToBuffer(context: RenderContext) -> FrameBuffer {
/// FrameBuffer(text: "output")
/// }
/// }
/// ```
///
/// ## Thread Safety
///
/// Like SwiftUI, all view operations are confined to the main actor.
/// This ensures thread-safe access to state, environment, and rendering.
@MainActor
public protocol View {
/// The type of the body view.
///
/// Swift automatically infers this type from the `body` implementation.
/// Primitive views that conform to `Renderable` set this to `Never`.
associatedtype Body: View
/// The content and behavior of this view.
///
/// Implement this property to define the structure of your view
/// by composing other `View` types.
///
/// For primitive views that conform to `Renderable`, set this
/// to `Never` with a `fatalError` body. The rendering system will
/// call `renderToBuffer(context:)` instead.
@ViewBuilder
var body: Body { get }
}