mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Move the pty master behind a small interface (Read/Write/Close/Resize), and push the actual startup into a platform-specific StartPty function in pkg/commands/oscommands. The Unix implementation still uses creack/pty; the Windows implementation is a stub that returns ErrPtyUnsupported, at which point newPtyTask falls back to a plain cmd task — matching the existing Windows behavior. The primitive lives in oscommands rather than pkg/gui because the cmd_obj_runner pty handler (also in oscommands) is going to consume it too, and tasks → oscommands is the existing dependency direction. Same observable behavior on every platform; this just carves out a seam for a real ConPTY implementation on Windows. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
35 lines
818 B
Go
35 lines
818 B
Go
//go:build !windows
|
|
|
|
package oscommands
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
|
|
creackpty "github.com/creack/pty"
|
|
)
|
|
|
|
type unixPty struct {
|
|
master *os.File
|
|
}
|
|
|
|
func (u *unixPty) Read(p []byte) (int, error) { return u.master.Read(p) }
|
|
func (u *unixPty) Write(p []byte) (int, error) { return u.master.Write(p) }
|
|
func (u *unixPty) Close() error { return u.master.Close() }
|
|
|
|
func (u *unixPty) Resize(cols, rows uint16) error {
|
|
return creackpty.Setsize(u.master, &creackpty.Winsize{Cols: cols, Rows: rows})
|
|
}
|
|
|
|
func StartPty(cmd *exec.Cmd, cols, rows uint16) (StartedPty, error) {
|
|
f, err := creackpty.StartWithSize(cmd, &creackpty.Winsize{Cols: cols, Rows: rows})
|
|
if err != nil {
|
|
return StartedPty{}, err
|
|
}
|
|
return StartedPty{
|
|
Pty: &unixPty{master: f},
|
|
Process: cmd.Process,
|
|
Wait: cmd.Wait,
|
|
}, nil
|
|
}
|