terminal

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package terminal provides terminal-related utilities.

Index

Constants

View Source
const DefaultWidth = 50

DefaultWidth is the default terminal width when detection fails.

Variables

View Source
var GetSize = term.GetSize

GetSize returns the terminal width and height for the given file descriptor. This is a variable to allow mocking in tests.

IsTTY checks if the file descriptor is a TTY. This is a variable to allow mocking in tests.

Functions

func FdToInt added in v0.8.0

func FdToInt(fd uintptr) int

FdToInt safely converts a file descriptor from uintptr to int. File descriptors are always small non-negative values, so this only guards against a theoretical overflow on 32-bit platforms; on overflow it returns -1, which callers treat as an invalid descriptor.

func GetWidthFromWriter

func GetWidthFromWriter(w io.Writer) int

GetWidthFromWriter returns the terminal width for the given writer. Returns DefaultWidth if detection fails or writer is not a terminal.

func IsTerminalReader added in v1.8.1

func IsTerminalReader(r io.Reader) bool

IsTerminalReader returns true if the given reader is a terminal. It mirrors IsTerminalWriter for stdin, so an interactive prompt can require BOTH a terminal to draw on AND a terminal to read the answer from — a piped stdin must never be consumed as if it were a typed reply.

func IsTerminalWriter

func IsTerminalWriter(w io.Writer) bool

IsTerminalWriter returns true if the given writer is a terminal.

Types

type Fder

type Fder interface {
	Fd() uintptr
}

Fder is an interface for types that have a file descriptor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL