//go:build darwin || linux package server import ( "os" "os/exec" "syscall" "github.com/creack/pty" ) // chatShellTerminals is true where operator commands run in a pseudo-terminal. const chatShellTerminals = true // startChatShellTerminal starts cmd as the leader of a new session whose // controlling terminal is a fresh pseudo-terminal of cols x rows, and returns // the terminal's controller side: the command's merged output is read from // it, typed input written to it. The session id is also its process group, // so Stop's group signals reach everything it started. func startChatShellTerminal(cmd *exec.Cmd, cols, rows int) (*os.File, error) { return pty.StartWithAttrs(cmd, chatShellWinsize(cols, rows), &syscall.SysProcAttr{Setsid: true, Setctty: true}) } // resizeChatShellTerminal sets the terminal's size; the kernel signals the // foreground process group with SIGWINCH. func resizeChatShellTerminal(terminal *os.File, cols, rows int) error { return pty.Setsize(terminal, chatShellWinsize(cols, rows)) } func chatShellWinsize(cols, rows int) *pty.Winsize { return &pty.Winsize{Cols: uint16(cols), Rows: uint16(rows)} }