pax_global_header00006660000000000000000000000064121710667000014512gustar00rootroot0000000000000052 comment=13dcf1c6107462afd4263b6bc555caab69af395f golang-pty-dev-0.0~git20130701/000077500000000000000000000000001217106670000157265ustar00rootroot00000000000000golang-pty-dev-0.0~git20130701/License000066400000000000000000000020401217106670000172270ustar00rootroot00000000000000Copyright (c) 2011 Keith Rarick Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. golang-pty-dev-0.0~git20130701/README.md000066400000000000000000000007251217106670000172110ustar00rootroot00000000000000# pty Pty is a Go package for using unix pseudo-terminals. ## Install go get github.com/kr/pty ## Example ```go package main import ( "github.com/kr/pty" "io" "os" "os/exec" ) func main() { c := exec.Command("grep", "--color=auto", "bar") f, err := pty.Start(c) if err != nil { panic(err) } go func() { f.Write([]byte("foo\n")) f.Write([]byte("bar\n")) f.Write([]byte("baz\n")) f.Write([]byte{4}) // EOT }() io.Copy(os.Stdout, f) } ``` golang-pty-dev-0.0~git20130701/doc.go000066400000000000000000000003121217106670000170160ustar00rootroot00000000000000// Package pty provides functions for working with Unix terminals. package pty import ( "os" ) // Opens a pty and its corresponding tty. func Open() (pty, tty *os.File, err error) { return open() } golang-pty-dev-0.0~git20130701/pty_darwin.go000066400000000000000000000023551217106670000204420ustar00rootroot00000000000000package pty import ( "errors" "os" "syscall" "unsafe" ) // see ioccom.h const sys_IOCPARM_MASK = 0x1fff func open() (pty, tty *os.File, err error) { p, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0) if err != nil { return nil, nil, err } sname, err := ptsname(p) if err != nil { return nil, nil, err } err = grantpt(p) if err != nil { return nil, nil, err } err = unlockpt(p) if err != nil { return nil, nil, err } t, err := os.OpenFile(sname, os.O_RDWR, 0) if err != nil { return nil, nil, err } return p, t, nil } func ptsname(f *os.File) (string, error) { var n [(syscall.TIOCPTYGNAME >> 16) & sys_IOCPARM_MASK]byte ioctl(f.Fd(), syscall.TIOCPTYGNAME, uintptr(unsafe.Pointer(&n))) for i, c := range n { if c == 0 { return string(n[:i]), nil } } return "", errors.New("TIOCPTYGNAME string not NUL-terminated") } func grantpt(f *os.File) error { var u int return ioctl(f.Fd(), syscall.TIOCPTYGRANT, uintptr(unsafe.Pointer(&u))) } func unlockpt(f *os.File) error { var u int return ioctl(f.Fd(), syscall.TIOCPTYUNLK, uintptr(unsafe.Pointer(&u))) } func ioctl(fd, cmd, ptr uintptr) error { _, _, e := syscall.Syscall(syscall.SYS_IOCTL, fd, cmd, ptr) if e != 0 { return syscall.ENOTTY } return nil } golang-pty-dev-0.0~git20130701/pty_linux.go000066400000000000000000000017331217106670000203140ustar00rootroot00000000000000package pty import ( "os" "strconv" "syscall" "unsafe" ) const ( sys_TIOCGPTN = 0x80045430 sys_TIOCSPTLCK = 0x40045431 ) func open() (pty, tty *os.File, err error) { p, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0) if err != nil { return nil, nil, err } sname, err := ptsname(p) if err != nil { return nil, nil, err } err = unlockpt(p) if err != nil { return nil, nil, err } t, err := os.OpenFile(sname, os.O_RDWR, 0) if err != nil { return nil, nil, err } return p, t, nil } func ptsname(f *os.File) (string, error) { var n int err := ioctl(f.Fd(), sys_TIOCGPTN, &n) if err != nil { return "", err } return "/dev/pts/" + strconv.Itoa(n), nil } func unlockpt(f *os.File) error { var u int return ioctl(f.Fd(), sys_TIOCSPTLCK, &u) } func ioctl(fd uintptr, cmd uintptr, data *int) error { _, _, e := syscall.Syscall( syscall.SYS_IOCTL, fd, cmd, uintptr(unsafe.Pointer(data)), ) if e != 0 { return syscall.ENOTTY } return nil } golang-pty-dev-0.0~git20130701/run.go000066400000000000000000000010421217106670000170560ustar00rootroot00000000000000package pty import ( "os" "os/exec" "syscall" ) // Start 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. func Start(c *exec.Cmd) (pty *os.File, err error) { pty, tty, err := Open() if err != nil { return nil, err } defer tty.Close() c.Stdout = tty c.Stdin = tty c.Stderr = tty c.SysProcAttr = &syscall.SysProcAttr{Setctty: true, Setsid: true} err = c.Start() if err != nil { pty.Close() return nil, err } return pty, err } golang-pty-dev-0.0~git20130701/util.go000066400000000000000000000011611217106670000172310ustar00rootroot00000000000000package pty import ( "os" "syscall" "unsafe" ) // Getsize returns the number of rows (lines) and cols (positions // in each line) in terminal t. func Getsize(t *os.File) (rows, cols int, err error) { var ws winsize err = windowrect(&ws, t.Fd()) return int(ws.ws_row), int(ws.ws_col), err } type winsize struct { ws_row uint16 ws_col uint16 ws_xpixel uint16 ws_ypixel uint16 } func windowrect(ws *winsize, fd uintptr) error { _, _, errno := syscall.Syscall( syscall.SYS_IOCTL, fd, syscall.TIOCGWINSZ, uintptr(unsafe.Pointer(ws)), ) if errno != 0 { return syscall.Errno(errno) } return nil }