// IsTerminal return true if the file descriptor is terminal.
518501
func IsTerminal(fd uintptr) bool {
	var termios syscall.Termios
	_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
	return err == 0
}
169296
func IsTerminal(fd int) bool {
	var st uint32
	r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(fd), uintptr(unsafe.Pointer(&st)), 0)
	return r != 0 && e == 0
}
262565
func IsDir(fpath string) bool {
	d := cleanPath(fpath)
	if fi, err := os.Stat(d); err == nil {
		return fi.IsDir()
	}
	return false
}
880026
func IsTemporary(err error) bool {
	for err != nil {
		if tmp, ok := err.(Temporary); ok && tmp.Temporary() {
			return true
		}

		cause := errors.Cause(err)
		if cause == err {
			break
		}

		err = cause
	}

	return false
}
724458
func (p Phase) IsTerminal() bool {
	for _, t := range terminalPhases {
		if p == t {
			return true
		}
	}
	return false
}
94001
func IsCygwinTerminal(fd uintptr) bool {
	if procGetFileInformationByHandleEx == nil {
		return false
	}

	// Cygwin/msys's pty is a pipe.
	ft, _, e := syscall.Syscall(procGetFileType.Addr(), 1, fd, 0, 0)
	if ft != fileTypePipe || e != 0 {
		return false
	}

	var buf [2 + syscall.MAX_PATH]uint16
	r, _, e := syscall.Syscall6(procGetFileInformationByHandleEx.Addr(),
		4, fd, fileNameInfo, uintptr(unsafe.Pointer(&buf)),
		uintptr(len(buf)*2), 0, 0)
	if r == 0 || e != 0 {
		return false
	}

	l := *(*uint32)(unsafe.Pointer(&buf))
	return isCygwinPipeName(string(utf16.Decode(buf[2 : 2+l/2])))
}
543814
func DrawTerminal(w io.Writer) DrawFunc {
	return DrawTerminalf(w, func(progress, total int64) string {
		return fmt.Sprintf("%d/%d", progress, total)
	})
}
113988
func NewTerminal(ctx *ServerContext) (Terminal, error) {
	// It doesn't matter what mode the cluster is in, if this is a Teleport node
	// return a local terminal.
	if ctx.srv.Component() == teleport.ComponentNode {
		return newLocalTerminal(ctx)
	}

	// If this is not a Teleport node, find out what mode the cluster is in and
	// return the correct terminal.
	if ctx.ClusterConfig.GetSessionRecording() == services.RecordAtProxy {
		return newRemoteTerminal(ctx)
	}
	return newLocalTerminal(ctx)
}
1115582
func (fs *Filespace) IsFile(subPath string) bool {
	srcNode, err := fs.root.GetByPath(subPath)
	if err != nil || srcNode == nil {
		return false
	}
	return !srcNode.IsDir()
}
843999
func NewTerminal() (*Terminal, error) {
	in := os.Stdin

	term, err := newTerminal(in)
	if err != nil {
		return nil, err
	}

	return &Terminal{
		In:      in,
		Out:     os.Stdout,
		History: make([]string, 0, 10),
		histIdx: -1,
		t:       term,
	}, nil
}
660658
func (o *Out) SetRawTerminal() (err error) {
	if os.Getenv("NORAW") != "" || !o.commonStream.isTerminal {
		return nil
	}
	o.commonStream.state, err = term.SetRawTerminalOutput(o.commonStream.fd)
	return err
}
409629
func IsTerminalPhase(phase buildv1.BuildPhase) bool {
	switch phase {
	case buildv1.BuildPhaseNew,
		buildv1.BuildPhasePending,
		buildv1.BuildPhaseRunning:
		return false
	}
	return true
}
989728
func newTerminal(in *os.File) (*terminal, error) {
	term := &terminal{fd: in.Fd()}

	if !supportsEditing() {
		return term, nil
	}

	t, err := getTermios(term.fd)
	if err != nil {
		if IsNotTerminal(err) {
			return term, nil
		}

		return nil, err
	}
	term.origMode = *t
	mode := term.origMode
	term.supportsEditing = true

	// Set new mode flags, for reference see cfmakeraw(3).
	mode.Iflag &^= (unix.BRKINT | unix.IGNBRK | unix.ICRNL |
		unix.INLCR | unix.IGNCR | unix.ISTRIP | unix.IXON |
		unix.PARMRK)

	mode.Oflag &^= unix.OPOST

	mode.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON |
		unix.ISIG | unix.IEXTEN)

	mode.Cflag &^= (unix.CSIZE | unix.PARENB)
	mode.Cflag |= unix.CS8

	// Set controls; min num of bytes, and timeouts.
	mode.Cc[unix.VMIN] = 1
	mode.Cc[unix.VTIME] = 0

	err = setTermios(term.fd, true, &mode)
	if err != nil {
		return nil, err
	}

	return term, nil
}
1067953
func (s Status) Terminal() bool {
	switch s {
	case Success, Failure, InfraFailure, Warning, Expired, Exception, Cancelled:
		return true
	default:
		return false
	}
}
213171
func IsMSYSTerminal(w io.Writer) bool {
	var handle syscall.Handle

	if fw, ok := w.(fder); ok {
		handle = syscall.Handle(fw.Fd())
	} else {
		// The writer has no file-descriptor and so can't be a terminal.
		return false
	}

	// MSYS(2) terminal reports as a pipe for STDIN/STDOUT/STDERR. If it isn't
	// a pipe, it can't be a MSYS(2) terminal.
	filetype, err := syscall.GetFileType(handle)

	if filetype != syscall.FILE_TYPE_PIPE || err != nil {
		return false
	}

	// MSYS2/Cygwin terminal's name looks like: \msys-dd50a72ab4668b33-pty2-to-master
	data := make([]byte, 256, 256)

	r, _, e := syscall.Syscall6(
		procGetFileInformationByHandleEx.Addr(),
		4,
		uintptr(handle),
		uintptr(fileNameInfo),
		uintptr(unsafe.Pointer(&data[0])),
		uintptr(len(data)),
		0,
		0,
	)

	if r != 0 && e == 0 {
		// The first 4 bytes of the buffer are the size of the UTF16 name, in bytes.
		unameLen := binary.LittleEndian.Uint32(data[:4]) / 2
		uname := make([]uint16, unameLen, unameLen)

		for i := uint32(0); i < unameLen; i++ {
			uname[i] = binary.LittleEndian.Uint16(data[i*2+4 : i*2+2+4])
		}

		name := syscall.UTF16ToString(uname)

		return msysPipeNameRegex.MatchString(name)
	}

	return false
}
509921
func (fs *fakeFs) MkdirAll(path string, perm os.FileMode) error {
	return fs.a.Fs.MkdirAll(path, perm)
}
394969
func NewTerminal(c io.ReadWriter, prompt string) *Terminal {
	return &Terminal{
		Escape:       &vt100EscapeCodes,
		c:            c,
		prompt:       []rune(prompt),
		termWidth:    80,
		termHeight:   24,
		echo:         true,
		historyIndex: -1,
	}
}