예제 #1
0
파일: term_solaris.go 프로젝트: pkg/term
// Open opens an asynchronous communications port.
func Open(name string, options ...func(*Term) error) (*Term, error) {
	fd, e := syscall.Open(name, syscall.O_NOCTTY|syscall.O_CLOEXEC|syscall.O_NDELAY|syscall.O_RDWR, 0666)
	if e != nil {
		return nil, &os.PathError{"open", name, e}
	}

	modules := [2]string{"ptem", "ldterm"}
	for _, mod := range modules {
		err := unix.IoctlSetInt(fd, C.I_PUSH, int(uintptr(unsafe.Pointer(syscall.StringBytePtr(mod)))))
		if err != nil {
			return nil, err
		}
	}

	t := Term{name: name, fd: fd}
	termios.Tcgetattr(uintptr(t.fd), &t.orig)
	if err := termios.Tcgetattr(uintptr(t.fd), &t.orig); err != nil {
		return nil, err
	}

	if err := t.SetOption(options...); err != nil {
		return nil, err
	}

	return &t, syscall.SetNonblock(t.fd, false)
}
예제 #2
0
func getTerm() syscall.Termios {
	var term syscall.Termios
	if err := termios.Tcgetattr(uintptr(syscall.Stdin), &term); err != nil {
		panic(err)
	}
	return term
}
예제 #3
0
파일: demo.go 프로젝트: jaguilar/vt100
func tcgetattr(fd uintptr) (syscall.Termios, error) {
	var t syscall.Termios
	if err := termios.Tcgetattr(fd, &t); err != nil {
		return t, fmt.Errorf("tcgetattr: %v", err)
	}
	return t, nil
}
예제 #4
0
func (t *Term) setSpeed(baud int) error {
	var a attr
	if err := termios.Tcgetattr(uintptr(t.fd), (*syscall.Termios)(&a)); err != nil {
		return err
	}
	a.setSpeed(baud)
	return termios.Tcsetattr(uintptr(t.fd), termios.TCSANOW, (*syscall.Termios)(&a))
}
예제 #5
0
// RawMode places the terminal into raw mode.
func RawMode(t *Term) error {
	var a attr
	if err := termios.Tcgetattr(uintptr(t.fd), (*syscall.Termios)(&a)); err != nil {
		return err
	}
	termios.Cfmakeraw((*syscall.Termios)(&a))
	return termios.Tcsetattr(uintptr(t.fd), termios.TCSANOW, (*syscall.Termios)(&a))
}
예제 #6
0
파일: term_posix.go 프로젝트: pkg/term
func (t *Term) setReadTimeout(d time.Duration) error {
	var a attr
	if err := termios.Tcgetattr(uintptr(t.fd), (*syscall.Termios)(&a)); err != nil {
		return err
	}
	a.Cc[syscall.VMIN], a.Cc[syscall.VTIME] = timeoutVals(d)
	return termios.Tcsetattr(uintptr(t.fd), termios.TCSANOW, (*syscall.Termios)(&a))
}
예제 #7
0
// Open opens an asynchronous communications port.
func Open(name string, options ...func(*Term) error) (*Term, error) {
	fd, e := syscall.Open(name, syscall.O_NOCTTY|syscall.O_CLOEXEC|syscall.O_RDWR, 0666)
	if e != nil {
		return nil, &os.PathError{"open", name, e}
	}
	t := Term{name: name, fd: fd}
	if err := termios.Tcgetattr(uintptr(t.fd), &t.orig); err != nil {
		return nil, err
	}
	return &t, t.SetOption(options...)
}
예제 #8
0
파일: raw.go 프로젝트: pcfdev-forks/houdini
func SetRaw(tty *os.File) error {
	var attr syscall.Termios

	err := termios.Tcgetattr(uintptr(tty.Fd()), (*syscall.Termios)(&attr))
	if err != nil {
		return err
	}

	termios.Cfmakeraw((*syscall.Termios)(&attr))

	return termios.Tcsetattr(uintptr(tty.Fd()), termios.TCSANOW, (*syscall.Termios)(&attr))
}
예제 #9
0
파일: term_open_posix.go 프로젝트: pkg/term
// Open opens an asynchronous communications port.
func Open(name string, options ...func(*Term) error) (*Term, error) {
	fd, e := syscall.Open(name, syscall.O_NOCTTY|syscall.O_CLOEXEC|syscall.O_NDELAY|syscall.O_RDWR, 0666)
	if e != nil {
		return nil, &os.PathError{"open", name, e}
	}

	t := Term{name: name, fd: fd}
	if err := termios.Tcgetattr(uintptr(t.fd), &t.orig); err != nil {
		time.Sleep(time.Second * 100)
		return nil, err
	}
	if err := t.SetOption(options...); err != nil {
		return nil, err
	}
	return &t, syscall.SetNonblock(t.fd, false)
}
예제 #10
0
파일: term.go 프로젝트: chzyer/temux
func (p *Pty) Copy(o *os.File) (err error) {
	var attr syscall.Termios
	if err = termios.Tcgetattr(o.Fd(), &attr); err != nil {
		return err
	}
	w, h, err := GetSize(o.Fd())
	if err != nil {
		return err
	}

	if err = SetSize(p.tty.Fd(), w, h); err != nil {
		return err
	}

	err = termios.Tcsetattr(p.tty.Fd(), termios.TCSADRAIN, &attr)
	if err != nil {
		return err
	}
	return nil
}
예제 #11
0
파일: term_posix.go 프로젝트: pkg/term
func (t *Term) setFlowControl(kind int) error {
	var a attr
	if err := termios.Tcgetattr(uintptr(t.fd), (*syscall.Termios)(&a)); err != nil {
		return err
	}
	switch kind {
	case NONE:
		a.Iflag &^= termios.IXON | termios.IXOFF | termios.IXANY
		a.Cflag &^= termios.CRTSCTS

	case XONXOFF:
		a.Cflag &^= termios.CRTSCTS
		a.Iflag |= termios.IXON | termios.IXOFF | termios.IXANY

	case HARDWARE:
		a.Iflag &^= termios.IXON | termios.IXOFF | termios.IXANY
		a.Cflag |= termios.CRTSCTS
	}
	return termios.Tcsetattr(uintptr(t.fd), termios.TCSANOW, (*syscall.Termios)(&a))
}