Documentation

SwiftTUI documentation

Organized by what you're doing: your first hour, then the reference guides for views, state, and focus, charts, and what lies beyond the terminal. The module-by-module API reference is at the end.

Your first hour

Read these in order. Each one picks up where the last left off, from an empty package to an app that handles state, focus, and the terminal's own rules.

  1. 01

    Add it to your app

    Pick a toolchain, add the package, paste the counter, swift run.

  2. 02

    Authoring Views

    Compose containers, local state, focused controls, and modifiers around a body-driven tree.

  3. 03

    State, Environment, and Focus

    State, observation, environment, and focus share one runtime invalidation path.

  4. 04

    Running Apps

    The @main entry point, the standard flags, exit keys, and rendering one frame without a TTY.

  5. 05

    Coming from SwiftUI

    What transfers unchanged, which reflexes need retraining, and what is not here yet.

Setup / Swift 6.4

A toolchain and an executable package.

You can build from the command line on macOS, Linux, or Windows. Choose a Swift 6.4 toolchain before you begin.

macOS or Linux

Install Swift with swiftly. On macOS, an Xcode installation with Swift 6.4 also works.

Windows

Follow the Swift installation guide for the toolchain and its required build tools.

  1. Run swift --version to check your active toolchain.
  2. In a new MyTerminalApp directory, run swift package init --type executable.
  3. Replace Package.swift with the manifest below.
  4. Replace the generated executable source with the complete counter example. Save it as Sources/MyTerminalApp/CounterApp.swift and remove the generated entry-point file, so only the counter’s @main remains.
  5. Run swift run. Your app is ready for the next guide.
Package.swift
// swift-tools-version: 6.4
import PackageDescription

let package = Package(
  name: "MyTerminalApp",
  platforms: [.macOS(.v15)],
  dependencies: [
    .package(
      url: "https://github.com/SwiftTUI/swift-tui",
      .upToNextMinor(from: "0.15.1")
    ),
  ],
  targets: [
    .executableTarget(
      name: "MyTerminalApp",
      dependencies: [
        .product(name: "SwiftTUI", package: "swift-tui"),
      ]
    ),
  ]
)

Then read Authoring Views, or run the maintained counter directly.

Build your interface

Views, controls, drawing, and animated images. Read the guides as you need them.

Forms and Controls

Compose buttons, pickers, toggles, sliders, and text entry into a working form.

Commands and Key Input

Focus-scoped arrows and Escape, keyboard shortcuts, submit actions, and command palettes.

Scrolling

Finite viewports, compositional lazy stacks, nested wheel routing, indicators, and scrolling from code.

Animating Views

State animation, default fades, numeric text, nested matched geometry, keyframes, and reduced motion.

Navigation and Tabs

Typed navigation paths, destinations, tab selection, and view lifetime.

Animated Images and GIFs

Decode and author frames, control finite or continuous playback, and preserve GIF loop metadata on export.

The Style System

All 28 open style families in one place: built-ins, scoping, custom conformances, routes, theming, diagnostics, and tests.

Styling and Theming

Colors, semantic roles, gradients, the theme model, and your first custom button style.

Authoring Styles

The contract every style family shares: body-producing and presentation-value styles, route wrappers, and what a style may change.

Testing Styles

Exercise custom styles with fixture configurations, snapshots, and runtime route checks.

Understanding Focus

The runtime focus model for input routing, state control, and context export.

Lists and Tables

Collections with authored row content, selection, and viewport-backed data sources.

Geometry and Preferences

Anchor preferences let a subtree publish geometry that other views resolve after layout.

Shapes

Arcs and angles, fills and strokes, shape clipping, and compatible-topology path animation.

Aspect-correct shapes

Cell pixel metrics keep circles circular across terminal fonts and hosts.

Pointer and Canvas

One continuous cell coordinate space for gestures, hover, and drawing.

Accessibility

Semantic metadata for terminal screen readers, browser ARIA trees, VoiceOver, and TalkBack.

Custom Dynamic Properties

Build your own property wrappers on the DynamicProperty extension point.

State Keying

How @State storage is keyed across evaluations, and where owners survive lazy seams.

Dormant Tab State

What happens to a tab's persistent state while the tab is not selected.

Dismissal Is Data

Presentations are driven by Boolean bindings and identifiable items, not hidden stacks.

Charts

Sparklines, bar and line charts, heatmaps, meters, and calendar views ship separately as swift-tui-charts, composed on the same view surface.

At run time

What a running terminal app reads and can do, from the SwiftTUIRuntime catalog.

Beyond the terminal

Terminal first, not terminal only. The same app runs in a browser, inside native SwiftUI windows, and on Android; these guides own that path and its platform notes.

Concepts and background

API reference by module

The combined DocC archive documents each module. Most app code touches only the first row.

What you import

Hosts and opt-in products

The last group declares types that reach app code through re-export: CellSize, Alignment, PreferenceKey, SwiftTUIOptions. Their pages document symbols you use, behind imports you never write.