Skip to content

Updating Table

This component renders tabular data and automatically refreshes whenever new data is emitted from an async source. It's ideal for streaming status dashboards, build logs, or any dataset that changes over time. When paired with the selectable API, users can keep navigating while the table keeps updating.

PropertyValue
InteractivityRequired since it re-renders when new data arrives

Demo

A gif that shows the updating table component in action

API

Basic Example

swift
let columns = [
    TableColumn(title: "SSID", width: .auto, alignment: .left),
    TableColumn(title: "Signal", width: .auto, alignment: .right)
]

let initial = TableData(
    columns: columns,
    rows: [
        ["Home", "-40 dBm"].map(TerminalText.init)
    ]
)

let updates = AsyncStream<TableData> { continuation in
    wifiScanner.onChange { networks in
        let rows = networks.map { [$0.ssid, "\($0.rssi) dBm"].map(TerminalText.init) }
        continuation.yield(TableData(columns: columns, rows: rows))
    }
}

await Noora().table(initial, updates: updates)

Selectable Updating Example

swift
let columns = [
    TableColumn(title: "SSID", width: .auto, alignment: .left),
    TableColumn(title: "Signal", width: .auto, alignment: .right),
]

var latest = TableData(columns: columns, rows: [["Home", "-40 dBm"].map(TerminalText.init)])
let updates = AsyncStream<TableData> { continuation in
    Task.detached {
        while !Task.isCancelled {
            latest = makeSnapshot() // Build new TableData from your source
            continuation.yield(latest)
            try? await Task.sleep(for: .seconds(1))
        }
        continuation.finish()
    }
}

let selectedIndex = try await Noora().selectableTable(
    latest,
    updates: updates,
    pageSize: 8
)

let selectedRow = latest.rows[selectedIndex]
print("Picked network: \(selectedRow[0].plain())")

Options

Updating table method

AttributeDescriptionRequiredDefault value
dataInitial TableData to renderYes
updatesAsync sequence emitting TableData with the latest rowsYes
rendererRendering interface that holds UI stateNoRenderer()

Selectable updating table method

AttributeDescriptionRequiredDefault value
dataInitial TableData to renderYes
updatesAsync sequence emitting TableData with the latest rowsYes
pageSizeNumber of visible rowsYes
rendererRendering interface that holds UI stateNoRenderer()

Released under the MIT License.