phranck 7ddac7067d feat: Complete SwiftTUI foundation with overlay system and menu
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
2026-01-28 15:35:55 +01:00
2026-01-28 09:26:25 +01:00

Swift 6.2 macOS License Status

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

  • TView protocol — the core building block, mirroring SwiftUI's View
  • @TViewBuilder — result builder for declarative view composition (up to 10 children, conditionals, optionals, loops)
  • Primitive viewsText, EmptyView, Spacer, Divider
  • Layout containersVStack, HStack, ZStack with alignment and spacing
  • ForEach — iterate over collections, ranges, or Identifiable data
  • 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
  • TApp protocol — 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
  • TView is a protocol (not a class), so views are value types by default
  • Primitive views (Text, Spacer, Divider, stacks, etc.) conform to the internal Renderable protocol for direct terminal output
  • Composite views just define a body and the renderer walks the tree recursively
  • The Terminal class handles raw mode, screen buffer switching, and cursor control via POSIX termios
  • Tests use Swift Testing (@Test, #expect) — run with swift 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%