// IsTerminal returns true if the given file descriptor is a terminal.
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
}
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,
	}
}
408772
func (e Entry) IsDir() bool {
	for _, kv := range e.AllKeys() {
		if kv.Keyword().Prefix() == "type" {
			return kv.Value() == "dir"
		}
	}
	return false
}
276633
func IsTerminal(fd int) bool {
	_, err := getTermios(fd)
	return err == nil
}
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
}
1100526
func IsTemporary(name string) bool {
	name = filepath.Base(name)
	if strings.HasPrefix(name, WindowsTempPrefix) ||
		strings.HasPrefix(name, UnixTempPrefix) {
		return true
	}
	return false
}
590502
func (ns *NodeSession) isTerminalAttached() bool {
	return ns.stdin == os.Stdin && term.IsTerminal(os.Stdin.Fd())
}
678210
func (t *terminal) GetTerminalParams() rsession.TerminalParams {
	t.mu.Lock()
	defer t.mu.Unlock()
	return t.params
}
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)
}
1291444
func (s *Operation) SetIsTerminal(v bool) *Operation {
	s.IsTerminal = &v
	return s
}
688141
func WithTerminal(ctx context.Context, isTerm bool) context.Context {
	return context.WithValue(ctx, ctxKeyTerminal, isTerm)
}
116550
func RestoreTerminal(fd uintptr, state *State) error {
	if state == nil {
		return ErrInvalidState
	}
	_, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&state.termios)))
	if err != 0 {
		return err
	}
	return nil
}
235271
func IsInternal(file string) bool {
	// fs cannot import config, so we hard code .stfolder here (config.DefaultMarkerName)
	internals := []string{".stfolder", ".stignore", ".stversions"}
	for _, internal := range internals {
		if file == internal {
			return true
		}
		if IsParent(file, internal) {
			return true
		}
	}
	return false
}
1220141
func newTerminalPrompter() *terminalPrompter {
	p := new(terminalPrompter)
	// Get the original mode before calling NewLiner.
	// This is usually regular "cooked" mode where characters echo.
	normalMode, _ := liner.TerminalMode()
	// Turn on liner. It switches to raw mode.
	p.State = liner.NewLiner()
	rawMode, err := liner.TerminalMode()
	if err != nil || !liner.TerminalSupported() {
		p.supported = false
	} else {
		p.supported = true
		p.normalMode = normalMode
		p.rawMode = rawMode
		// Switch back to normal mode while we're not prompting.
		normalMode.ApplyMode()
	}
	p.SetCtrlCAborts(true)
	p.SetTabCompletionStyle(liner.TabPrints)
	p.SetMultiLineMode(true)
	return p
}
1161032
func (s *commonStream) RestoreTerminal() {
	if s.state != nil {
		term.RestoreTerminal(s.fd, s.state)
	}
}
484462
func isTerminalFunc(fd int) bool {
	var st uint32
	r, _, errno := syscall.Syscall(procMode.Addr(), 2, uintptr(fd), uintptr(unsafe.Pointer(&st)), 0)
	if errno != 0 {
		return false
	}

	return r != 0
}
437993
func (t *Table) renderTerminal() string {
	// Use a placeholder rather than adding titles/headers to the tables
	// elements or else successive calls will compound them.
	tt := t.clone()

	// Initial top line.
	if !tt.Style.SkipBorder {
		if tt.title != nil && tt.headers == nil {
			tt.elements = append([]Element{&Separator{where: LINE_SUBTOP}}, tt.elements...)
		} else if tt.title == nil && tt.headers == nil {
			tt.elements = append([]Element{&Separator{where: LINE_TOP}}, tt.elements...)
		} else {
			tt.elements = append([]Element{&Separator{where: LINE_INNER}}, tt.elements...)
		}
	}

	// If we have headers, include them.
	if tt.headers != nil {
		ne := make([]Element, 2)
		ne[1] = CreateRow(tt.headers)
		if tt.title != nil {
			ne[0] = &Separator{where: LINE_SUBTOP}
		} else {
			ne[0] = &Separator{where: LINE_TOP}
		}
		tt.elements = append(ne, tt.elements...)
	}

	// If we have a title, write it.
	if tt.title != nil {
		// Match changes to this into renderMarkdown too.
		tt.titleCell = CreateCell(tt.title, &CellStyle{Alignment: AlignCenter, ColSpan: 999})
		ne := []Element{
			&StraightSeparator{where: LINE_TOP},
			CreateRow([]interface{}{tt.titleCell}),
		}
		tt.elements = append(ne, tt.elements...)
	}

	// Create a new table from the
	// generate the runtime style. Must include all cells being printed.
	style := createRenderStyle(tt)

	// Loop over the elements and render them.
	b := bytes.NewBuffer(nil)
	for _, e := range tt.elements {
		b.WriteString(e.Render(style))
		b.WriteString("\n")
	}

	// Add bottom line.
	if !style.SkipBorder {
		b.WriteString((&Separator{where: LINE_BOTTOM}).Render(style) + "\n")
	}

	return b.String()
}