Files
kandev/apps/backend/internal/common/ptyexec/pty_unix.go
T
João Salavisa c5c591b60b refactor(pty): collapse duplicated PTY and cmdline helpers into common/ptyexec (#2457)
Co-authored-by: Kandev Agent <agent@kandev.dev>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-09 01:03:13 +01:00

34 lines
866 B
Go

//go:build !windows
package ptyexec
import (
"os"
"os/exec"
"github.com/creack/pty"
)
// unixPTY wraps a Unix PTY master file descriptor.
type unixPTY struct {
f *os.File
}
func (p *unixPTY) Read(b []byte) (int, error) { return p.f.Read(b) }
func (p *unixPTY) Write(b []byte) (int, error) { return p.f.Write(b) }
func (p *unixPTY) Close() error { return p.f.Close() }
func (p *unixPTY) Resize(cols, rows uint16) error {
return pty.Setsize(p.f, &pty.Winsize{Cols: cols, Rows: rows})
}
// Start starts cmd under a Unix PTY with the given dimensions.
// pty.StartWithSize calls cmd.Start() internally, so cmd.Process is set on return.
func Start(cmd *exec.Cmd, cols, rows uint16) (PtyHandle, error) {
f, err := pty.StartWithSize(cmd, &pty.Winsize{Cols: cols, Rows: rows})
if err != nil {
return nil, err
}
return &unixPTY{f: f}, nil
}