Prerelease This site documents an alpha of libtmux. Its structure, URLs and APIs are subject to change.

Swift workspace builder examples

Edit this page on GitHub

TmuxWorkspace 0.1.0-alpha.5 · Source

The port’s ExampleCode package contains functions for describing a workspace in Swift, building it, and reading JSON or YAML. Its tests compile and call those functions.

Describe and buildLink to section

The example’s YAML reader requires the dependency’s YAMLWorkspaces trait. That trait enables the API inside the dependency; it does not define the same compilation condition in a consumer package.

// The examples in the README's `WorkspaceBuilder` section.
import Foundation
import LibTmux
import TmuxWorkspace
public func describeAWorkspaceInSwift() -> Workspace {
let workspace = Workspace(
sessionName: "work",
windows: [
WindowPlan(
windowName: "editor",
layout: "even-horizontal",
panes: [PanePlan(), PanePlan()]
),
WindowPlan(
windowName: "logs",
panes: [PanePlan(shellCommands: ["tail -f /tmp/build.log"])]
),
]
)
return workspace
}
public func buildItOnAServer(_ server: Server, _ workspace: Workspace) async throws -> Session {
let session = try await WorkspaceBuilder.build(workspace, on: server)
print(session.name, session.windowCount)
return session
}
public func readAWorkspaceWrittenAsJSON(_ json: Data) throws -> Workspace {
try Workspace.decode(json: json)
}
// Deliberately NOT wrapped in `#if YAMLWorkspaces`. A trait defines its
// compilation condition only inside the package that declares it, so that guard
// in a consumer package is always false and deletes the example — loudly if a
// test calls it, silently if nothing does. The symbol is nonetheless here,
// because the dependency was resolved with the trait on.
public func readATmuxpFile(_ text: String) throws -> Workspace {
try Workspace.decode(yaml: text)
}

The log pane expects a log file at the configured path. Change that command to match the application before using the description as a launcher. The returned session is a captured value; request a fresh server snapshot to inspect membership after all windows have been created.

The guide provides an isolated executable and cleanup. These helper functions accept a caller-owned server and keep the workspace running for that caller to use.

VerificationLink to section

From a prepared source checkout, run the example package:

Terminal window
$ swift test --package-path Examples

The port also checks correspondence between these source functions and its README examples. Source inclusion in this page keeps the excerpt current; it does not run the Swift tests during site rendering.

Example source

Esc

Type to search.