SwiftTUI Documentation

repository·main·Indexed 23 days ago

https://github.com/rensbreur/swifttui

A framework that brings the SwiftUI API to the terminal for building text-based user interfaces (TUI) using declarative patterns. It supports core SwiftUI concepts including property wrappers (@State, @Binding), layout structures (HStack, VStack, GeometryReader), UI components (Button, TextField, Text), and styling modifiers for ANSI, xterm, and TrueColor.

Tokens
474
Snippets
3
Records
4
Agent score
31%

What's inside SwiftTUI

  1. Get started with SwiftTUI

    main

    To use SwiftTUI, create an executable Swift package and add the repository as a dependency. Use the main branch to access the latest features. Import SwiftTUI in your Swift files and define your UI using views and modifiers similar to SwiftUI.

    To launch the application, use the Application struct in your main.swift file, providing a rootView and calling .start().

    import SwiftTUI
    
    struct MyTerminalView: View {
      var body: some View {
        Text("Hello, world!")
      }
    }
    
    // In main.swift
    Application(
      rootView: MyTerminalView()
    )
    .start()
  2. Supported SwiftTUI features and modifiers

    main

    SwiftTUI implements many core SwiftUI concepts for the terminal environment. Supported features include:

    Property Wrappers

    • @State
    • @Binding
    • @Environment
    • @ObservedObject

    Layout and Structure

    • Stacks (HStack/VStack)
    • .frame()
    • .padding()
    • GeometryReader
    • @ViewBuilder
    • ForEach
    • Group
    • ScrollView for scrollable lists

    UI Components

    • Button
    • TextField (supports moving focus with arrow keys)
    • Text (supports bold, italic, underscore, and ^strikethrough^ variants)

    Styling and Modifiers

    • Color support for ANSI, xterm, and TrueColor
    • .onAppear()
    • .border()
    • .foregroundColor()
    • .backgroundColor()
    • Modifiers applied to collections of views