// NewTerminal creates a terminal and sets it to raw input mode.

NewTerminal creates a terminal and sets it to raw input mode.
// NewTerminal creates a terminal and sets it to raw input mode .
func NewTerminal() (*Terminal, error) {
	term := &Terminal{
		In:       os.Stdin,
		Out:      os.Stdout,
		History:  make([]string, 0, 10),
		histIdx:  -1,
		terminal: new(terminal),
	}
	if !supportedTerminal() {
		return term, nil
	}
	t, err := getTermios(term.In.Fd(), uintptr(tcgets))
	if err != nil {
		if IsNotTerminal(err) {
			return term, nil
		}
		return nil, err
	}
	term.origMode = *t
	mode := term.origMode
	term.supported = true
	mode.Iflag &^= (syscall.BRKINT | syscall.IGNBRK | syscall.ICRNL |
		syscall.INLCR | syscall.IGNCR | syscall.ISTRIP | syscall.IXON |
		syscall.PARMRK)
	mode.Oflag &^= syscall.OPOST
	mode.Lflag &^= (syscall.ECHO | syscall.ECHONL | syscall.ICANON |
		syscall.ISIG | syscall.IEXTEN)
	mode.Cflag &^= (syscall.CSIZE | syscall.PARENB)
	mode.Cflag |= syscall.CS8
	mode.Cc[syscall.VMIN] = 1
	mode.Cc[syscall.VTIME] = 0
	err = setTermios(term.In.Fd(), uintptr(tcsetsf), &mode)
	if err != nil {
		return nil, err
	}
	return term, nil
}
func NewTerminal ( ) ( * Terminal , error ) { term := & Terminal { In : os . Stdin , Out : os . Stdout , History : make ( [ ] string , 0 , 10 ) , histIdx : - 1 , terminal : new ( terminal ) , } if ! supportedTerminal ( ) { return term , nil } t , err := getTermios ( term . In . Fd ( ) , uintptr ( tcgets ) ) if err != nil { if IsNotTerminal ( err ) { return term , nil } return nil , err } term . origMode = * t mode := term . origMode term . supported = true mode . Iflag &^= ( syscall . BRKINT | syscall . IGNBRK | syscall . ICRNL | syscall . INLCR | syscall . IGNCR | syscall . ISTRIP | syscall . IXON | syscall . PARMRK ) mode . Oflag &^= syscall . OPOST mode . Lflag &^= ( syscall . ECHO | syscall . ECHONL | syscall . ICANON | syscall . ISIG | syscall . IEXTEN ) mode . Cflag &^= ( syscall . CSIZE | syscall . PARENB ) mode . Cflag |= syscall . CS8 mode . Cc [ syscall . VMIN ] = 1 mode . Cc [ syscall . VTIME ] = 0 err = setTermios ( term . In . Fd ( ) , uintptr ( tcsetsf ) , & mode ) if err != nil { return nil , err } return term , nil }
NewTerminal creates a terminal and sets it to raw input mode.
NewTerminal creates a terminal and sets it to raw input mode .
// Set new mode flags, for reference see cfmakeraw(3).
 // Set controls; min num of bytes, and timeouts.
