PseudoTerminalHelpers

public class PseudoTerminalHelpers

APIs to assist in controlling a Unix pseudo-terminal from Swift, it provides a wrapper for the libc forkptyAPI in the form of fork(andExec:args:env:desiredWindowSize: method, setWinSize and availableBytes

  • This method both forks and executes the provided command under a Pseudo Terminal, and returns both the process ID and the file descriptor for the pseudo-terminal

    Declaration

    Swift

    public static func fork(andExec: String, args: [String], env: [String], desiredWindowSize: inout winsize) -> (pid: pid_t, masterFd: Int32)?

    Parameters

    andExec

    the name of the executable to run

    args

    arguments to be passed to the executable

    env

    the environment variables for the child process

    desiredWindowSize

    the window size that will be set on the pseudo terminal.

  • Sets the window size of the underlying pseudo terminal.

    Declaration

    Swift

    public static func setWinSize(masterPtyDescriptor: Int32, windowSize: inout winsize) -> Int32

    Parameters

    masterPtyDescriptor

    a pseudo-terminal master file descriptor, as returned by fork(andExec:)

    Return Value

    the value from calling the ioctl

  • Returns the number of available bytes to be read from the file descriptor

    Declaration

    Swift

    public static func availableBytes(fd: Int32) -> (status: Int32, size: Int32)