// +build !windows,!plan9

package term

import (
	
	

	
	
	
)

func (,  *os.File) (func() error, error) {
	// On Unix, use input file for changing termios. All fds pointing to the
	// same terminal are equivalent.

	 := int(.Fd())
	,  := sys.TermiosForFd()
	if  != nil {
		return nil, fmt.Errorf("can't get terminal attribute: %s", )
	}

	 := .Copy()

	.SetICanon(false)
	.SetIExten(false)
	.SetEcho(false)
	.SetVMin(1)
	.SetVTime(0)

	// Enforcing crnl translation on readline. Assuming user won't set
	// inlcr or -onlcr, otherwise we have to hardcode all of them here.
	.SetICRNL(true)

	 = .ApplyToFd()
	if  != nil {
		return nil, fmt.Errorf("can't set up terminal attribute: %s", )
	}

	var  error
	 = setupVT()
	if  != nil {
		 = fmt.Errorf("can't setup VT: %s", )
	}

	 := func() error {
		return diag.Errors(.ApplyToFd(), restoreVT())
	}

	return , 
}

func () func() {
	return func() {}
}

func (,  *os.File) {
	// Some programs use non-blocking IO but do not correctly clear the
	// non-blocking flags after exiting, so we always clear the flag. See #822
	// for an example.
	unix.SetNonblock(int(.Fd()), false)
	unix.SetNonblock(int(.Fd()), false)
}