~ghost08/tcell-term

27ddd699f188bf020abfac4865b5dd4b865a578d — Tim Culverhouse 1 year, 2 months ago bbd6a57
run: allow running with custom SysProcAttr

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2 files changed, 18 insertions(+), 4 deletions(-)

M terminal.go
M termutil/terminal.go
M terminal.go => terminal.go +10 -1
@@ 5,6 5,7 @@ import (
	"image/color"
	"os"
	"os/exec"
	"syscall"
	"time"

	"git.sr.ht/~ghost08/tcell-term/termutil"


@@ 47,6 48,14 @@ func WithWindowManipulator(wm termutil.WindowManipulator) Option {
}

func (t *Terminal) Run(cmd *exec.Cmd) error {
	return t.run(cmd, &syscall.SysProcAttr{})
}

func (t *Terminal) RunWithAttrs(cmd *exec.Cmd, attr *syscall.SysProcAttr) error {
	return t.run(cmd, attr)
}

func (t *Terminal) run(cmd *exec.Cmd, attr *syscall.SysProcAttr) error {
	w, h := t.view.Size()
	tmr := time.NewTicker(16 * time.Millisecond)
	go func() {


@@ 63,7 72,7 @@ func (t *Terminal) Run(cmd *exec.Cmd) error {
			}
		}
	}()
	err := t.term.Run(cmd, uint16(h), uint16(w))
	err := t.term.Run(cmd, uint16(h), uint16(w), attr)
	if err != nil {
		return err
	}

M termutil/terminal.go => termutil/terminal.go +8 -3
@@ 7,7 7,7 @@ import (
	"io"
	"os"
	"os/exec"
	"time"
	"syscall"

	"github.com/creack/pty"
	"golang.org/x/term"


@@ 116,12 116,17 @@ func (t *Terminal) SetSize(rows, cols uint16) error {
}

// Run starts the terminal/shell proxying process
func (t *Terminal) Run(c *exec.Cmd, rows uint16, cols uint16) error {
func (t *Terminal) Run(c *exec.Cmd, rows uint16, cols uint16, attr *syscall.SysProcAttr) error {
	c.Env = append(os.Environ(), "TERM=xterm-256color")

	// Start the command with a pty.
	var err error
	t.pty, err = pty.Start(c)
	// t.pty, err = pty.Start(c)
	winsize := pty.Winsize{
		Cols: cols,
		Rows: rows,
	}
	t.pty, err = pty.StartWithAttrs(c, &winsize, &syscall.SysProcAttr{Setsid: true, Setctty: true, Ctty: 1})
	if err != nil {
		return err
	}