Help us shape the future of Go! Take the 2026 Go Developer Survey

pty

package
v1.233.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecWithPTY

func ExecWithPTY(ctx context.Context, cmd *exec.Cmd, opts *Options) error

ExecWithPTY executes a command in a pseudo-terminal with optional output masking.

This function provides TTY emulation while allowing masking of sensitive data in output. It integrates with Atmos's existing pkg/io masking infrastructure.

Platform Support:

  • macOS: Fully supported
  • Linux: Fully supported
  • Windows: Not supported (use regular exec.Cmd.Run instead)

Limitations:

  • PTY merges stderr and stdout into single stream
  • EIO errors may occur when reading from closed PTY (this is normal)
  • Terminal size must be synchronized with host terminal

Example:

ctx := context.Background()
cmd := exec.Command("docker", "exec", "-it", containerID, "bash")
opts := &Options{
    Masker:        ioCtx.Masker(),
    EnableMasking: true,
}
err := ExecWithPTY(ctx, cmd, opts)

func IsSupported

func IsSupported() bool

IsSupported returns true if PTY operations are supported on this platform.

Currently supported platforms:

  • darwin (macOS)
  • linux

Not supported:

  • windows (PTY operations require Unix-like system calls)

Types

type Options

type Options struct {
	// Masker is the masking implementation from pkg/io.
	Masker iolib.Masker

	// EnableMasking enables output masking through the PTY proxy.
	EnableMasking bool

	// DisableStdinForward skips forwarding Stdin to the PTY and skips putting
	// the host terminal into raw mode (like docker -t without -i: the child
	// gets a TTY but receives no input from the host).
	DisableStdinForward bool

	// Stdin provides input to the PTY. If nil, defaults to os.Stdin.
	Stdin io.Reader

	// Stdout receives output from the PTY. If nil, defaults to os.Stdout.
	Stdout io.Writer

	// Stderr receives error output from the PTY. Note: PTY merges stderr with stdout.
	// This is preserved for API consistency but data will not flow here in PTY mode.
	Stderr io.Writer
}

Options represents configuration for PTY execution.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL