ptycapture

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package ptycapture runs subprocesses with optional pseudo-terminal sizing, timeouts, output limits, and stderr handling for documentation tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyStderrMode

func ApplyStderrMode(stdout, stderr []byte, mode StderrMode) ([]byte, []byte)

ApplyStderrMode merges or discards stderr per mode.

func CapturePTY

func CapturePTY(opts Options, argv []string) (stdout, stderr []byte, err error)

CapturePTY runs argv with stdin and stdout on a PTY (fixed cols×rows). stderr is captured with a separate pipe.

func CapturePlain

func CapturePlain(opts Options, argv []string) (stdout, stderr []byte, err error)

CapturePlain runs argv with ordinary pipe I/O (no pseudo-terminal).

func DrainPTYOutput

func DrainPTYOutput(r io.Reader) ([]byte, error)

DrainPTYOutput reads remaining PTY output after process exit (exported for tests).

func ExitCode

func ExitCode(err error) (int, bool)

ExitCode returns the subprocess exit code when err represents a normal exit failure.

Types

type Options

type Options struct {
	Cols uint
	Rows uint
	// Ctx controls cancellation. A nil context uses context.Background.
	Ctx context.Context
	// Timeout limits subprocess runtime when greater than zero.
	Timeout time.Duration
	// KillAfter allows graceful termination before forcefully stopping the process.
	KillAfter time.Duration
	// MaxOutputBytes limits each captured output stream when greater than zero.
	MaxOutputBytes int64
}

Options configures subprocess capture.

type StderrMode

type StderrMode int

StderrMode controls how stderr is exposed to callers.

const (
	// StderrSeparate keeps stdout and stderr in separate slices.
	StderrSeparate StderrMode = iota
	// StderrMerge appends stderr bytes onto stdout.
	StderrMerge
	// StderrDiscard drops captured stderr.
	StderrDiscard
)

func ParseStderrMode

func ParseStderrMode(s string) (StderrMode, error)

ParseStderrMode parses -stderr flag values.

Jump to

Keyboard shortcuts

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