Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsInteractiveTerminal ¶
func IsInteractiveTerminal() bool
IsInteractiveTerminal returns true if stdin is a real terminal (TTY). Returns false in CI environments (when the "CI" env var set to "true"), when input is piped, or in non-interactive shells.
Types ¶
type InputRouter ¶
type InputRouter struct {
// contains filtered or unexported fields
}
InputRouter manages routing stdin to either PTY or a prompt pipe. Only ONE goroutine should call ReadLoop().
func NewInputRouter ¶
func NewInputRouter(ptyWriter io.Writer) (*InputRouter, error)
func (*InputRouter) ReadLoop ¶
func (r *InputRouter) ReadLoop(src io.Reader)
ReadLoop continuously reads from src and routes data to the current destination.
IMPORTANT: Only ONE goroutine should call ReadLoop() because:
- Multiple readers on the same source (e.g., stdin) cause data splitting - one goroutine might read "hel" while another reads "lo\n"
- Concurrent routing decisions create race conditions on the destination
- User input becomes unpredictably interleaved between readers
This function blocks until src returns an error (e.g., EOF).
func (*InputRouter) RouteToPTY ¶
func (r *InputRouter) RouteToPTY()
RouteToPTY switches input back to the PTY (default)
func (*InputRouter) RouteToPrompt ¶
func (r *InputRouter) RouteToPrompt(w io.Writer)
RouteToPrompt switches input to go to the given writer (prompt pipe)
type InteractiveSession ¶
type InteractiveSession interface {
// PtyWriter returns the writer to send input to the child process
PtyWriter() io.Writer
// PtyReader returns the reader to receive output from the child process
PtyReader() io.Reader
// SetRawMode puts terminal in raw mode (for PTY passthrough)
SetRawMode() error
// SetCookedMode restores normal terminal mode (for prompts)
SetCookedMode() error
// Wait blocks until the child process exits
// Returns ExitError if process exited with non-zero code
Wait() error
// Close cleans up resources (PTY, terminal state)
Close() error
}
InteractiveSession manages a PTY-based command execution with support for input/output routing and terminal mode switching.
func NewSession ¶
func NewSession(ctx context.Context, cfg SessionConfig) (InteractiveSession, error)
NewSession creates a new interactive PTY session. The terminal is put into raw mode automatically.
type OutputRouter ¶
type OutputRouter struct {
// contains filtered or unexported fields
}
OutputRouter manages buffered vs live output.
func NewOutputRouter ¶
func NewOutputRouter(out io.Writer) (*OutputRouter, error)
func (*OutputRouter) Pause ¶
func (r *OutputRouter) Pause()
Pause starts buffering output. Call this before showing a confirmation prompt.
func (*OutputRouter) Resume ¶
func (r *OutputRouter) Resume()
Resume stops buffering, flushes any buffered output, and resumes live output. Call this after the confirmation prompt is complete.
type SessionConfig ¶
SessionConfig holds options for creating a session
func NewSessionConfig ¶
func NewSessionConfig(cmd string, args, env []string) SessionConfig