package claudetui import ( "os" "strconv" "syscall" "golang.org/x/sys/unix" ) // openPTY opens a pseudo-terminal: its master, and the name of its slave. func openPTY() (*os.File, string, error) { m, err := os.OpenFile("/dev/ptmx", os.O_RDWR|syscall.O_NOCTTY, 0) if err != nil { return nil, "", err } fd := int(m.Fd()) if err := unix.IoctlSetPointerInt(fd, unix.TIOCSPTLCK, 0); err != nil { m.Close() return nil, "", err } n, err := unix.IoctlGetInt(fd, unix.TIOCGPTN) if err != nil { m.Close() return nil, "", err } return m, "/dev/pts/" + strconv.Itoa(n), nil } // the requests that read and set a terminal's modes (the tests' fake // Claude Code sets its own raw, as the real one does) const ioctlGetTermios, ioctlSetTermios = unix.TCGETS, unix.TCSETS