From a24f8808b5bfec758c6f21ae8af88b8566b5e33d Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Sun, 27 Mar 2022 10:36:46 -0700 Subject: [PATCH] Fix windows compilation (#142) --- run.go | 18 ------------------ start.go | 25 +++++++++++++++++++++++++ start_windows.go | 20 ++++++++++++++++++++ 3 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 start.go create mode 100644 start_windows.go diff --git a/run.go b/run.go index 3e2b6ec..4755366 100644 --- a/run.go +++ b/run.go @@ -1,6 +1,3 @@ -//go:build !windows -// +build !windows - package pty import ( @@ -18,21 +15,6 @@ func Start(cmd *exec.Cmd) (*os.File, error) { return StartWithSize(cmd, nil) } -// StartWithSize assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout, -// and c.Stderr, calls c.Start, and returns the File of the tty's -// corresponding pty. -// -// This will resize the pty to the specified size before starting the command. -// Starts the process in a new session and sets the controlling terminal. -func StartWithSize(cmd *exec.Cmd, ws *Winsize) (*os.File, error) { - if cmd.SysProcAttr == nil { - cmd.SysProcAttr = &syscall.SysProcAttr{} - } - cmd.SysProcAttr.Setsid = true - cmd.SysProcAttr.Setctty = true - return StartWithAttrs(cmd, ws, cmd.SysProcAttr) -} - // StartWithAttrs assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout, // and c.Stderr, calls c.Start, and returns the File of the tty's // corresponding pty. diff --git a/start.go b/start.go new file mode 100644 index 0000000..9b51635 --- /dev/null +++ b/start.go @@ -0,0 +1,25 @@ +//go:build !windows +// +build !windows + +package pty + +import ( + "os" + "os/exec" + "syscall" +) + +// StartWithSize assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout, +// and c.Stderr, calls c.Start, and returns the File of the tty's +// corresponding pty. +// +// This will resize the pty to the specified size before starting the command. +// Starts the process in a new session and sets the controlling terminal. +func StartWithSize(cmd *exec.Cmd, ws *Winsize) (*os.File, error) { + if cmd.SysProcAttr == nil { + cmd.SysProcAttr = &syscall.SysProcAttr{} + } + cmd.SysProcAttr.Setsid = true + cmd.SysProcAttr.Setctty = true + return StartWithAttrs(cmd, ws, cmd.SysProcAttr) +} diff --git a/start_windows.go b/start_windows.go new file mode 100644 index 0000000..b3efdca --- /dev/null +++ b/start_windows.go @@ -0,0 +1,20 @@ +//go:build windows +// +build windows + +package pty + +import ( + "errors" + "os" + "os/exec" +) + +// StartWithSize assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout, +// and c.Stderr, calls c.Start, and returns the File of the tty's +// corresponding pty. +// +// This will resize the pty to the specified size before starting the command. +// Starts the process in a new session and sets the controlling terminal. +func StartWithSize(cmd *exec.Cmd, ws *Winsize) (*os.File, error) { + return nil, errors.New("unsupported platform") +}