A SwiftUI engine that renders to the terminal.
Credits: Nicolas Dominati with its chess app created with SwiftTUI
- macOS 26 or later
- Swift 6.3 toolchain or later
Create a new executable target and add SwiftTUI as a dependency in your Package.swift:
let package = Package(
name: "MyApp",
platforms: [
.macOS(.v26)
],
dependencies: [
.package(url: "https://github.com/bpisano/SwiftTUI", from: "0.0.3")
],
targets: [
.executableTarget(
name: "MyApp",
dependencies: ["SwiftTUI"]
)
]
)The entry point is a type conforming to App, marked @main.
import SwiftTUI
@main
struct MyApp: App {
var body: some View {
Text("Hello, World!")
}
}Views nest, and @State holds values that change. Here a button updates a count:
import SwiftTUI
@main
struct MyApp: App {
var body: some View {
Counter()
}
}
struct Counter: View {
@State private var count = 0
var body: some View {
VStack(alignment: .leading) {
Text("Count: \(count)")
Button("Increment") {
count += 1
}
}
}
}Run your app with swift run. SwiftTUI takes over the terminal, draws the view tree, and processes keyboard input. Press Ctrl-C to exit.
- Views —
Text,Button,TextField,ForEach. - Layout —
HStack,VStack,ZStack, plus theframeandpaddingmodifiers. - State and data flow —
@State,@Binding,@Environment. - Focus — keyboard navigation between controls (Tab / Shift-Tab / arrows) and
the
@Focusproperty wrapper for moving focus programmatically. - Styling —
Color,foregroundStyle,ShapeStyle, and customButtonStyle.
Many SwiftUI APIs are not yet supported (for example Spacer, Divider, background/overlay, gradients, Toggle/Slider/Picker). See the compatibility guide for the current list.
You can read the full documentation here.
Guides:
SwiftTUI is licensed under the MIT License. See the LICENSE file for more information.