loom & weft
Made for Swift.

Unreleased APIs from PR #2. Not in 0.2.1. Stable 0.2.1 reference.

LOOM Unreleased (PR #2) / SUPPORTING WEFT TYPES

PseudoTerminalProcess

A child process with a controlling pseudo-terminal and bounded, nonblocking I/O.

Use one serial execution context. Drain output and poll exit status independently: a child may exit before its final output is read. Closing terminates a running child group and reaps it off the caller's execution context.

Defined by weft, with no loom typealias. Add the weft product to your target and use import weft when referring to this type by name.

Standard inherited Swift protocol operations such as synthesized equality and OptionSet set operations are not repeated. The public declarations below are extracted from the exact source revision listed in the coverage manifest.

Members on this page

Feature guides and release status

PseudoTerminalProcess

Class
final class PseudoTerminalProcess

A child process with a controlling pseudo-terminal and bounded, nonblocking I/O.

Use one serial execution context. Drain output and poll exit status independently: a child may exit before its final output is read. Closing terminates a running child group and reaps it off the caller's execution context.

Source · PseudoTerminalProcess.swift:17

processIdentifier

Instance Property
let processIdentifier: Int32

A public field of this type. Its value type and mutability are shown in the declaration.

Source · PseudoTerminalProcess.swift:18

init(executable:arguments:environment:size:)

Initializer Throws
init(executable: URL, arguments: [String] = [], environment: [String : String]? = nil, size: Rect = Rect(width: 80, height: 24)) throws

Creates a value with the supplied arguments. Default arguments are shown in the declaration.

Parameters (4)
executable
Argument type and any default are shown in the declaration; see the behavior notes above.
arguments
Argument type and any default are shown in the declaration; see the behavior notes above.
environment
Environment hints used to infer optional terminal features.
size
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · PseudoTerminalProcess.swift:24

read(timeoutMilliseconds:)

Instance Method Throws
func read(timeoutMilliseconds: Int = 0) throws -> Data?

Returns at most 8 KiB, empty data when not ready, or nil on terminal EOF.

Zero polls immediately; -1 waits for readiness. No output bytes are decoded.

Parameters (1)
timeoutMilliseconds
Poll timeout: 0 is nonblocking, -1 waits indefinitely.

Returns Data?.

Source · PseudoTerminalProcess.swift:46

write(_:)

Instance Method Throws
func write(_ bytes: Data) throws -> Int

Writes at most 8 KiB; zero means backpressure or that the child terminal is still starting.

Retain and retry the unwritten suffix. This call never waits for writable space.

Parameters (1)
bytes
Input bytes to decode incrementally.

Returns Int.

Source · PseudoTerminalProcess.swift:59

waitForWritable(timeoutMilliseconds:)

Instance Method Throws
func waitForWritable(timeoutMilliseconds: Int = 16) throws -> Bool

Waits for writable space without consuming child output or changing terminal modes.

Returns false on timeout or interruption so the caller can service signals and resize.

Parameters (1)
timeoutMilliseconds
Poll timeout: 0 is nonblocking, -1 waits indefinitely.

Returns Bool.

Source · PseudoTerminalProcess.swift:84

resize(_:)

Instance Method Throws
func resize(_ size: Rect) throws

Updates the child terminal dimensions and lets the kernel notify its foreground group.

Parameters (1)
size
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · PseudoTerminalProcess.swift:97

pollExitStatus()

Instance Method Throws
func pollExitStatus() throws -> Int32?

Returns nil while running, a normal exit code, or 128 plus its terminating signal.

This also drains final output before reaping. Consume read() while polling: status can be deferred until the bounded output queue has room.

Returns Int32?.

Source · PseudoTerminalProcess.swift:107

terminate(signal:)

Instance Method Throws
func terminate(signal: Int32 = 15) throws

Sends a signal to the owned child session's process group while its leader is unreaped.

Parameters (1)
signal
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · PseudoTerminalProcess.swift:131

close()

Instance Method
func close()

Releases the PTY exactly once and terminates any still-running owned child group.

Source · PseudoTerminalProcess.swift:140