ptyctl

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StartOption

type StartOption func(*startConfig)

WithEnv returns a StartOption that adds environment variables.

func WithDir

func WithDir(dir string) StartOption

func WithEnv

func WithEnv(env ...string) StartOption

func WithSize

func WithSize(width, height int) StartOption

type Terminal

type Terminal struct {
	// contains filtered or unexported fields
}

func Start

func Start(ctx context.Context, name string, args ...string) (*Terminal, error)

func StartWithOptions

func StartWithOptions(ctx context.Context, opts []StartOption, name string, args ...string) (*Terminal, error)

func (*Terminal) Close

func (t *Terminal) Close() error

Close kills the child process and releases the PTY.

func (*Terminal) Cmd

func (t *Terminal) Cmd() *exec.Cmd

Cmd returns the underlying exec.Cmd for env/dir configuration before Start. Only useful when building a Terminal manually; Start() already configures it.

func (*Terminal) Done

func (t *Terminal) Done() <-chan error

Done returns a channel that receives the process exit error.

func (*Terminal) Enter

func (t *Terminal) Enter() error

Enter sends the Enter key.

func (*Terminal) OutputLen

func (t *Terminal) OutputLen() int

OutputLen returns the current length of the raw output buffer. Use before sending a prompt to mark the position for OutputSince.

func (*Terminal) OutputSince

func (t *Terminal) OutputSince(from int) []byte

OutputSince returns raw PTY output accumulated after byte offset `from`. The returned slice is a copy — safe to hold across calls.

func (*Terminal) Pid

func (t *Terminal) Pid() int

Pid returns the PID of the child process, or -1 if not started.

func (*Terminal) ReadOutput

func (t *Terminal) ReadOutput(p []byte) (int, error)

ReadOutput provides raw access to PTY output, bypassing the emulator. Most callers should use Screen() instead.

func (*Terminal) Render

func (t *Terminal) Render() string

Render returns the screen content with ANSI escape codes intact.

func (*Terminal) Resize

func (t *Terminal) Resize(w, h int) error

Resize changes the terminal dimensions.

func (*Terminal) Screen

func (t *Terminal) Screen() string

Screen returns the current text content of the virtual terminal.

func (*Terminal) Send

func (t *Terminal) Send(s string) error

Send writes raw bytes to the PTY (stdin of the child process).

func (*Terminal) SendLine

func (t *Terminal) SendLine(s string) error

SendLine sends text followed by Enter.

func (*Terminal) WaitFor

func (t *Terminal) WaitFor(ctx context.Context, substr string) (string, error)

WaitFor polls the screen until it contains the given substring or the context expires. Returns the screen content at time of match.

func (*Terminal) WaitForAny

func (t *Terminal) WaitForAny(ctx context.Context, substrs ...string) (matched string, screen string, err error)

WaitForAny polls the screen until any of the given substrings appears. Returns the matching substring and the screen content.

func (*Terminal) WriteStdin

func (t *Terminal) WriteStdin(p []byte) (int, error)

WriteStdin writes to the emulator's input pipe (keyboard events processed through the terminal emulator layer). For raw PTY writes, use Send().

Jump to

Keyboard shortcuts

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