Skip to content
المشاريع

حول

SwiftUI semantics, drawn in terminal cells — macOS/Linux/Windows/WASI

أدوات التطوير

كيف تُقاس هذه الأرقام

النمو المقاس للنجوم

خلال 24 ساعة
٠
خلال 7 أيام
+٢
خلال 15 يومًا
+٣
خلال شهر
جارٍ جمع السجل

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل

SwiftTUI

SwiftUI semantics, drawn in terminal cells.

Swift 6.4 Status License

SwiftTUI applies SwiftUI's declarative programming model and APIs to the terminal. You declare views; the framework handles reactivity, layout, and the terminal details on macOS, Linux, and Windows.

The framework is Foundation free and ships hosts to display 'terminal apps' on web and in macOS, iOS, and Android apps. These hosts display and run the app natively — not through an emulated TTY. No xterm.js, no libghostty, etc.

[!important] Public beta. The framework's public APIs are stable, but deprecations and aggressive development should be expected until 1.0.0. All changes are documented in the CHANGELOG.
Use .upToNextMajor for supported dependencies; see the compatibility policy.

Three clicks on Increment take the counter from 0 to 3, each sending a ripple across the terminal.

Try it first
This is a real SwiftTUI app, compiled to WebAssembly and running live.
The guided introduction and API reference are at SwiftTUI.sh

The counter

The terminal and browser demos share the same counter view.

import SwiftTUI
import SwiftTUIEffects

struct CounterView: View {
  @State private var count = 0

  var body: some View {
    VStack(spacing: 1) {
      TextFigure("\(count)", font: .future)
      Button("Increment") {
        count += 1
      }
    }
    .padding(.horizontal, 6)
    .padding(.vertical, 3)
    .background(.background)
    .border(.tint, style: .heavy)
    .frame(maxWidth: .infinity, maxHeight: .infinity)
    .background(TileStyle(.checkerShade, foreground: .black.lightened(by: 0.3), background: .black))
    .feedbackEffect(.ripple, trigger: count)
  }
}

The terminal entry point imports SwiftTUI, which includes the SwiftTUICLI runner. The browser host runs the same view with SwiftTUIWASI.

import SwiftTUI

@main
struct CounterApp: App {
  var body: some Scene {
    WindowGroup("Counter") { CounterView() }
  }
}

RenderOnce.print(CounterView(), width: 40) renders the idle counter at 40 columns. With color off, it prints this frame.

░▒░▒░▒░▒┏━━━━━━━━━━━━━━━━━━━━━┓▒░▒░▒░▒░▒
▒░▒░▒░▒░┃                     ┃░▒░▒░▒░▒░
░▒░▒░▒░▒┃                     ┃▒░▒░▒░▒░▒
▒░▒░▒░▒░┃         ┏━┓         ┃░▒░▒░▒░▒░
░▒░▒░▒░▒┃         ┃┃┃         ┃▒░▒░▒░▒░▒
▒░▒░▒░▒░┃         ┗━┛         ┃░▒░▒░▒░▒░
░▒░▒░▒░▒┃                     ┃▒░▒░▒░▒░▒
▒░▒░▒░▒░┃      Increment      ┃░▒░▒░▒░▒░
░▒░▒░▒░▒┃                     ┃▒░▒░▒░▒░▒
▒░▒░▒░▒░┃                     ┃░▒░▒░▒░▒░
░▒░▒░▒░▒┗━━━━━━━━━━━━━━━━━━━━━┛▒░▒░▒░▒░▒

Click Increment or press Space with the button focused. Each increment updates the figure and sends a ripple across the background. Ctrl-C quits and restores your shell.

Run it

Any Swift 6.4+ toolchain builds and runs SwiftTUI apps from the command line on macOS 15+, Linux, and Windows 10 1809+ (swiftly, a current Xcode, or the swift.org installer). For the terminal counter, add both packages and their products, then run swift run:

// Package.swift
.package(url: "https://github.com/SwiftTUI/swift-tui.git", .upToNextMajor(from: "0.27.0")),
.package(url: "https://github.com/SwiftTUI/swift-tui-effects.git", .upToNextMajor(from: "0.1.0")),
// in your executable target:
.product(name: "SwiftTUI", package: "swift-tui"),
.product(name: "SwiftTUIEffects", package: "swift-tui-effects"),

Or clone the demo's repo and run its terminal target:

git clone https://github.com/SwiftTUI/swift-tui-counter-demo
cd swift-tui-counter-demo
swift run --package-path counter counter

Project index

What Where
Primary repo: build a terminal app SwiftTUI/swift-tui
Run the web demo, read the intro https://swifttui.sh
Quick-start: the Counter App demo SwiftTUI/swift-tui-counter-demo
Read the documentation https://swifttui.sh/docs/documentation/
   
Add feedback and ambient effects SwiftTUI/swift-tui-effects
Animate views as they appear and disappear SwiftTUI/swift-tui-transitions
Add charts & dashboards SwiftTUI/swift-tui-charts
Embed terminal programs SwiftTUI/swift-tui-terminal-view
   
Embed in a website SwiftTUI/swift-tui-web
Embed in SwiftUI (macOS · iOS) SwiftTUI/swift-tui-swiftui
Embed in Android SwiftTUI/swift-tui-android
Examples: demo apps across all host platforms SwiftTUI/swift-tui-examples

Why SwiftTUI

  • State in, screen out. Views are a pure function of your app's state: change a value and the runtime recomputes layout and rewrites exactly the cells that changed.
  • Useful components, focus based navigation, open styles. Buttons, text fields, pickers, sliders, scroll views, and charts, with a focus engine, tab traversal, keyboard chords. You compose behavior instead of hand-routing key events to widgets. Every one of the 28 control and presentation families is an open style protocol, so one modifier restyles a control, a subtree, or the whole app.
  • Drawing and motion. Compose arcs, shape clips, compatible path morphs, layered images, and finite GIF playback. Animate state, numeric text, and matched geometry on the terminal grid, with reduced-motion support.
  • Scrolling workspaces. Combine lazy sections and multiple data sources, nest scroll panes, and retain authored state across tab switches. Lists and tables provide selection, tall rows, and embedded controls.
  • The terminal, negotiated for you. Truecolor, Kitty and Sixel images, OSC 8 hyperlinks, and mouse reporting are probed per session and degrade gracefully; one binary is correct in kitty, a bare SSH session, or CI. You write views, not escape codes.
  • Developer ergonomics Your app compiles into a single fast executable with checked concurrency. Layout and state are type-checked at build time, and tests render frames as integer-cell rasters without a TTY.
  • Batteries included, accessible by default. Default builds provide accessibility flags --reduce-motion, --cursor-follows-focus, and even --web for a browser view. Terminal conveniences like --no-color, and --ascii are similarly bundled.

Contributing

Open an issue for SwiftUI-style APIs you find missing or anything that gets in your way.

Small, well-scoped issues and pull requests are easiest to review. The repo uses the pinned Swift 6.4.3 toolchain through swiftly: swiftly run swift test for the unit tests. Read CONTRIBUTING.md

Development happens on GitHub and Discord. Come ask questions, show what you are building, give feedback, or talk through a contribution.

License

SwiftTUI is licensed under the MIT License (MIT). Vendored third-party code under Vendor/ keeps its own license and provenance notices. See LICENSE.

Version compatibility

See the compatibility policy for supported major lines, independent dependency adoption, and experimental interfaces.

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…