Skip to content

Commit

Permalink
Fix windows compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
creack committed Mar 27, 2022
1 parent 7de28ce commit 4830ec4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
18 changes: 0 additions & 18 deletions run.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !windows
// +build !windows

package pty

import (
Expand All @@ -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.
Expand Down
25 changes: 25 additions & 0 deletions start.go
Original file line number Diff line number Diff line change
@@ -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)
}
20 changes: 20 additions & 0 deletions start_windows.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 4830ec4

Please sign in to comment.