mirror of
https://github.com/phranck/TUIkit.git
synced 2026-05-21 09:50:35 +00:00
7ddac7067daa99ae84750a98f4e62d5ba65cb508
Core Framework: - TView protocol with TViewBuilder result builder (up to 10 children) - Full ANSI rendering pipeline (Terminal, ANSIRenderer, FrameBuffer) - TApp/TScene/WindowGroup app lifecycle with SIGWINCH handling - Color system (ANSI, bright, 256-palette, RGB, hex, semantic colors) - Text styling (bold, italic, underline, strikethrough, dim, blink, inverted) Container Views: - VStack, HStack, ZStack with alignment and spacing - Card (bordered container with padding/background) - Box (simple bordered container) - Panel (titled container with title in border) - ForEach for dynamic content Modifiers: - .padding(), .frame(), .border() (8 border styles), .background() - .overlay() with alignment, .dimmed(), .modal() helper Overlay System: - Alert view with title, message, actions, and presets (warning/error/info/success) - Dialog view for flexible modal content - FrameBuffer character-level compositing Menu View: - Menu with items, selection indicator, shortcuts - MenuItem model with id, label, shortcut - AnyView type-erased wrapper Example App: - Menu-based navigation with multiple demo pages - Text Styles, Colors, Containers, Overlays, Layout demos Tests: - 58 tests across 12 suites, all passing
SwiftTUI
A SwiftUI-like framework for building Terminal User Interfaces in Swift — no ncurses, no C dependencies, just pure Swift.
What is this?
SwiftTUI lets you build TUI apps using the same declarative syntax you already know from SwiftUI. Define your UI with TView, compose views with VStack, HStack, and ZStack, style text with modifiers like .bold() and .foregroundColor(.red), and run it all in your terminal.
struct ContentView: TView {
var body: some TView {
VStack(spacing: 1) {
Text("Hello, SwiftTUI!")
.bold()
.foregroundColor(.cyan)
Divider()
HStack {
Text("Status:")
Text("Running").foregroundColor(.green)
}
}
}
}
Features
TViewprotocol — the core building block, mirroring SwiftUI'sView@TViewBuilder— result builder for declarative view composition (up to 10 children, conditionals, optionals, loops)- Primitive views —
Text,EmptyView,Spacer,Divider - Layout containers —
VStack,HStack,ZStackwith alignment and spacing ForEach— iterate over collections, ranges, orIdentifiabledata- Text styling — bold, italic, underline, strikethrough, dim, blink, inverted
- Full color support — 8 standard ANSI colors, bright variants, 256-color palette, 24-bit RGB, hex values
- Terminal abstraction — raw mode, cursor control, alternate screen buffer
TAppprotocol — app lifecycle with signal handling and run loop
Run the Example App
swift run SwiftTUIExample
Press q or ESC to exit.
Developer Notes
- Swift 6.2 with strict concurrency is required (swift-tools-version 6.2)
- macOS only — this is a terminal framework, iOS/watchOS/tvOS don't apply
- The rendering engine uses pure ANSI escape codes — no external dependencies
TViewis a protocol (not a class), so views are value types by default- Primitive views (
Text,Spacer,Divider, stacks, etc.) conform to the internalRenderableprotocol for direct terminal output - Composite views just define a
bodyand the renderer walks the tree recursively - The
Terminalclass handles raw mode, screen buffer switching, and cursor control via POSIXtermios - Tests use Swift Testing (
@Test,#expect) — run withswift test
Project Structure
Sources/
├── SwiftTUI/
│ ├── App/ TApp, TScene, WindowGroup
│ ├── Core/ TView, TViewBuilder, Color, TupleViews, PrimitiveViews
│ ├── Rendering/ Terminal, ANSIRenderer, ViewRenderer, Renderable
│ └── Views/ Text, Stacks, Spacer, Divider, ForEach
└── SwiftTUIExample/ Example app (executable target)
License
MIT
Languages
Swift
84.5%
C
14.1%
Shell
1.4%